Post your best Lua script examples here

User avatar
By Erni
#3805 This is my example of using a lua client to update a databse on my webserver.
It calls a .php page that update a MySql database every 30 seconds.

You can see the result here (showing only the last 25 entrys):

http://www.ernstc.dk/sensor.php

One thing that I can't figure out is why we have to use the IP number.
Wouldn't it be posibble to let the esp do the DNS lookup

Code: Select alltmr.alarm(30000, 1, function()
conn=net.createConnection(net.TCP, 0)
    conn:on("receive", function(conn, payload) print(payload) end )
    conn:connect(80,"46.30.212.238")
    conn:send("GET /esp.php?tekst="..adc.read(0) .."&heap="..node.heap().." HTTP/1.1\r\nHost: www.ernstc.dk\r\n"
        .."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
end)
Last edited by Erni on Tue Dec 02, 2014 6:18 pm, edited 1 time in total.
User avatar
By Erni
#3808 Thanks gerardwr

Yes I found scargill's solution here

viewtopic.php?f=18&t=668

And with the new lua firmware from today, the heap issue seems to be solved.
I have tried your webserver with the new firmware, and I can't kill it even if I update as fast as I can, the heap recovers really fast
User avatar
By gerardwr
#3830
Erni wrote:And with the new lua firmware from today, the heap issue seems to be solved.
I have tried your webserver with the new firmware, and I can't kill it even if I update as fast as I can, the heap recovers really fast


Had no idea that the new firmware was already available, thanks for the tip. Nice that my webserver is behaving robustly now.