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:
NodeMCU 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:
file.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