As the title says... Chat on...

User avatar
By gwizz
#7606 Oh, bummer, that makes a captive portal a bit more impossible!

My idea was to set up a really simple dns server that responds to any dns lookup with the ip of the esp. That way we don't have to get end-users to goto 192.168.4.1 but instead can ask them to browse to any site - the lookup returns the ip 192.168.4.1 and then they can configure the esp to join your local wifi point.

I suppose that once the bug is fixed then we can create a dns server, after it answers stop it, then start our web server.

Otherwise we'd have to serve the dns request, reboot, then serve the htpp GET request.

I've commented on the most relevant open issue on the nodeMCU github issues https://github.com/nodemcu/nodemcu-firmware/issues/59 - so hopefully zeroday (or some other code wizard) will be able to fix the bug soon.
User avatar
By chrisbonnert
#9654
lorneb wrote:I'll answer my own question in the interests of sharing the learning experience.

you need to close the server with
svr.close(svr)

then free the server with
svr = nil

noob mistake really


I tried your above suggestion, but I got:
PANIC: unprotected error in call to Lua API (attempt to index a nil value)
a few times then it rebooted

Here's my code:

srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive",function(conn,payload)
if (xxx < 0) then
print("Closing svr")
svr.close(svr)
print("Setting svr=nil")
srv=nil
print("Returning")
return
end
if (xxx == 0) then
print("Server restarted")
end
xxx = xxx+1
print(xxx)
print(payload)
conn:send("<h1> Hello, NodeMcu " .. tostring(xxx) .. "</h1>")
end)
end)

This is run using dofile from LuaLoader after first manually setting:
wifi.setmode(wifi.SOFTAP)
wifi.ap.config({ssid="test1", pwd="1234"})
wifi.sta.connect()

I use a global variable xxx that I set to 0 before running the above code.
That way I am attempting to turn off the server by entering xxx=-1 in LuaLoader, whilst debugging.
I am attempting to avoid "only one tcp server allowed" when re-running the above code.
I am a newbie at Lua so please be kind ;-)
Chris