Post your best Lua script examples here

User avatar
By Nkonnect
#51250 Hello,

I am having 3 ESP-07 modules of which 1 is configured as Access point having AT version:0.50.0.0(Sep 18 2015 20:55:38) SDK version:1.4.0 firmware and other 2 are configured as Station mode with NodeMCU 0.9.6 build 20150704 firmware. Script for station mode is developed in Lua 5.1.4, now the problem is when AP configured module1 is not powered ON and the station configured 2 modules are powered ON they try to connect to AP module but the connection is not established. This process is continued for say 1 min and then suddenly it gives this error PANIC: unprotected error in call to Lua API (not enough memory)

Script for Station Mode is here:

wifi.setmode(wifi.STATION)
wifi.sta.config("ESP8266","12345678")
cfg =
{
ip = "192.168.4.13",
netmask = "255.255.255.0",
gateway = "192.168.4.1"
}
wifi.sta.setip(cfg)

tmr.alarm(0, 1000, 1, function()
if wifi.sta.getip() == nil then
else
ip, nm, gw=wifi.sta.getip()
print("got IP:", ip)
sk=net.createConnection(net.TCP, 0)
sk:connect(1234,"192.168.4.11")
sk:on("connection", function(sck,c)
sk:send("IP:")
sk:send(ip)
tmr.stop(0)
end)
sk:on("receive", function(sck, c)
print(c)
end)
sk:on("disconnection", function(sck, c)
sk:close()
print("DISCONNECT")
tmr.start(0)
end)
end
end)

function serial (data)
sk:send(data)
end

uart.setup(0, 9600, 8, 0, 1, 0)
uart.on("data", 0, serial, 0)

Guide me to solve this issue

Thank You
Nkonnect