So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By RasPelikan
#66871 Hello,

I do my first steps on ESP8266 using nodemcu. Everything works fine: I built a firmware using nodemcu-build. I was able to flash the firmware successfully using esptool.py. Afterwards I used ESPlorer which gives me this console output:

Code: Select allNodeMCU custom build by frightanic.com
   branch: master
   commit: c8ac5cfb912ff206b03dd7c60ffbb2dafb83fe5e
   SSL: false
   modules: file,gpio,net,node,ow,tmr,uart,wifi
 build    built on: 2017-06-06 19:24
 powered by Lua 5.1.4 on SDK 2.1.0(116b762)


So good so far. Then I tried my first lua programs. I connect to my local WiFi and print the IP address once the GOT_IP event fires.

Afterwards I want the module to respond to a http-request using one of the examples available in web. And here is the error: Regardless which example I use I always get and "out of memory" error in the line of the "listen" function:

Code: Select allfile.remove("init.lua");
file.open("init.lua","w+");
w = file.writeline
w([==[wifi.setmode(wifi.STATION)]==]);
w([==[]==]);
w([==[local station_cfg = {}]==]);
w([==[station_cfg.ssid = "ABCDEFGH"]==]);
w([==[station_cfg.pwd = "XXXXXXXXXXXXXXXXXXXXXX"]==]);
w([==[wifi.sta.config(station_cfg)]==]);
w([==[]==]);
w([==[local function receiver(sck,numbers)]==]);
w([==[ print("rec")]==]);
w([==[ collectgarbage("collect")]==]);
w([==[ sck:close()]==]);
w([==[end]==]);
w([==[]==]);
w([==[local sv = net.createServer(net.TCP, 30)]==]);
w([==[if (sv) then]==]);
w([==[ print(node.heap())]==]);
w([==[ sv:listen(80, function(conn) conn:on("receive", receiver) end)]==]);
w([==[end]==]);
file.close();
dofile("init.lua");
40632
init.lua:17: out of memory
stack traceback:
   [C]: in function 'listen'
   init.lua:17: in main chunk
   [C]: in function 'dofile'
   stdin:1: in main chunk


As you can see I printed the heap size and it is 40632 bytes before calling "listen".

I tried so far:
1. Used the compiled version
2. Tried to initialize the TCP server within the GOT_IP hook
3. Used local variables
4. Used different ports

Does anyone know about this issue? The code is so little - what can be wrong? I used a lot of different examples and none of them worked.

Thanks,
Stephan
User avatar
By RasPelikan
#66874 I gave the firmware version 1.5.4.1-final a try and now the error is gone.

I get an IP address and if I set the hostname using

Code: Select allwifi.sta.sethostname("Cnode")


my router shows that hostname.

But: Although there is no error I cannot connect to the device using the IP address. Any form of access (ping, curl, traceroute) gives a timeout and tells me "host is down". Even the router lists the module as "down" after a while.

Could the reason for this the same which causes the "out of memory" using 2.1.0? How can I test whether the module is still alive after starting the server (calling "listen")?

Thx,
Stephan
User avatar
By RasPelikan
#66929 I used an another WiFi router and now it works. But I don't want to use two different routers since I send commands to the ESP modules from a RaspberryPi which has to be available to other clients (my computer, my cell-phone and maybe to the Internet using DynDNS).

The older one knows only b/g and Wpa and the newer knows b/g/n and is set to Wpa/Wpa2. The network type may not be problem because I already used
Code: Select allwifi.setphymode(wifi.PHYMODE_G)
. I don't want to drop Wpa2 for the other clients. Can I limit the ESP module to Wpa?

The password of the newer is long (I don't know the exact number of characters) and the length of the older is 15 characters. I will try to use the same password in the old router to check whether this is the problem. But I got the feeling that it isn't.

And, of course, there are a lot of WiFi settings in the newer router which I do not know and which I don't want to change. At least not setting by setting to figure out what the ESP module doesn't like. Are there any known no-goes for WiFi settings?

Thx,
Stephan
User avatar
By zhaosq
#71197 I met the same problem as you, and then I found out that it was because I put it in the init, and when the device didn't get enough IP, I started listening, so there was an error. The reason why your other router has no problem is that the authentication speed is relatively fast. You try a certain delay, and then listen to it after being assigned to ip.