Current Lua downloadable firmware will be posted here

User avatar
By cendev
#2791 I'm having problems with reaching the socket i've created on tcp client connection from other functions :/ is there a way to declare it as a global variable?
i want to use the sk:send from other functions too :/

Edit : rather than dofile("functions.lua") i used the require"functions" and it did the job.. now my functions are created while socket created and works like charm :)
User avatar
By gerardwr
#2794
cendev wrote:Edit : rather than dofile("functions.lua") i used the require"functions" and it did the job.. now my functions are created while socket created and works like charm :)


Brilliant, we're going to be Lua experts yet, maybe we should read a manual ;-)
User avatar
By zeroday
#2797
zeroday wrote:
xinort wrote:I'm not sure if this is the best place to ask this but I'm using the lua web server and running into a problem. I can connect but only 2 times before I get a MAX_SOCKET error. I can't figure out how to release the socket after sending the data. I've tried conn:close() but no joy. This is the lua script I'm trying to use:

Code: Select allsrv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive",function(conn,payload)
print(payload)
door="open"
if gpio.read(8)==1 then door="open" else door="closed" end
conn:send("<h1> Door Sensor. The door is " .. door ..".</h1>")
conn:close()
end)
end)


MAX_SOCKET is 5.
A connection will closed in 180 seconds if it's inactive.
I will do more test on net module to find out why conn:close() doesn't work.
My experience is a Chrome will initiate 3 or 4 connections to host, if click on "refresh" too fast, the MAX_SOCKET is reached easily.


this bug is fixed.
now you can try your code, or below
Code: Select allsrv=net.createServer(net.TCP) srv:listen(80,function(conn)
   conn:on("receive",function(conn,payload)
      print(node.heap())
      door="open"
      if gpio.read(0)==1 then door="open" else door="closed" end
      conn:send("<h1> Door Sensor. The door is " .. door ..".</h1>")
      end)
   conn:on("sent",function(conn) conn:close() end)
end)
User avatar
By gerardwr
#2801
zeroday wrote:
zeroday wrote:
xinort wrote:I'm not sure if this is the best place to ask this but I'm using the lua web server and running into a problem.


this bug is fixed.


I just downloaded the latest version of the firmware and uploaded it to my ESP.

With the previous version of the firmware my ESP was rebooting when the server connection was closed. With the latest firmware I have no more unwanted reboots. So MY problem is FIXED.

Thanks zero day

Edit:

This the code for my server, based on the example from zero day:
Code: Select allsrv=net.createServer(net.TCP) srv:listen(80,function(conn)
    conn:on("receive",function(conn,payload) print(payload)
    conn:send("HTTP/1.1 200 OK\n\n")
    conn:send("<html><body>")
    conn:send("<h1>Served from GWR's ESP8266</h1><BR>")
    conn:send("NODE.CHIPID : " .. node.chipid() .. "<BR>")
    conn:send("NODE.HEAP : " .. node.heap() .. "<BR>")
    conn:send("TMR.NOW : " .. tmr.now() .. "<BR>")
    conn:send("</html></body>")
    conn:on("sent",function(conn) conn:close() end)
  end)
end)


This is the result in the browser:
Schermafbeelding 2014-11-17 om 22.22.01.png