LUA Madness

If you’ve been following the blog you’ll know we are THAT far off getting a working web server out of the ESP8266 and the LUA firmware – which has to beat the pants off messing with a compiler.

The code below setup a webserver – which will look for “?myarg=” – get the value and send it back…and increment a counter. If that request is not there – it does nothing..

03:13PM – Problem is – hit refresh on the browser several times and…. it crashes….  it has to be the interpreter or it would not work several times!  Still some way to go.

mycounter=0
srv=net.createServer(net.TCP)
   srv:listen(80,function(conn)
      conn:on(“receive”,function(conn,payload)
      if string.find(payload,”?myarg=”) then
         mycounter=mycounter+1
         m=”<br/>Value= ” .. string.sub(payload,string.find(payload,”?myarg=”)+7,string.find(payload,”HTTP”)-2)
     else
         m=””
     end
     conn:send(“<h1> Hello, this is Pete’s web page.</h1>How are you today.<br/> Count=” .. mycounter .. m .. “Heap=”.. node.heap())
end)
conn:on(“sent”,function(conn) conn:close() end)
end)

If you try the above example – assuming you are connected to your router… point a browser to it (note normal port 80) you will see the heap (RAM starts at maybe 5800bytes and takes a drop each time you refresh… and just keeps going down and down and.. at around 3k it bombs… if you get half way down and stop for 5 mins, the heap will recover – but clearly this is useless for polling – I have reported this with the code and I am just hoping this can be fixed..

5896
5496
5080
4688
4304 (wait 30 secs)
4688
4304 (wait 3 minues)
5856 (- note not as high as it was originally
5080
4688 (wait 5 minutes)
5856
5080
…etc
and at 3100 – the next refresh – the board resets…

This is getting SO NEAR yet maddeningly so far.  I cannot imagine why on earth the stack would take so long to clear.

Oh – and the A./D convertor on the ESP-01 is pin 6 ! I had the soldering iron out a while ago and… nope.. wrong wire, soldering iron too thick… magnifier naff.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s