Left here for archival purposes.

User avatar
By scargill
#5304 After spending yesterday wondering what's wrong with my ESP8266 terminal (scargill.wordpress.com) I've tried another terminal in here and the same result. This DID work ok, but with the latest firmware it seems to no longer work.

I have a web page I can call which returns the time (please don't use mine in your code - the PHP source is in my blog). Since the updates last week to the firmware, the DNS lookup works a treat and the code works perfectly.

Code: Select allsecond=0 minute=0 hour=0 day=0 month=0 year=0
host="www.scargill.net"


  conn=net.createConnection(net.TCP, 0)
    conn:on("receive", function(conn, payload)
                    hour,minute,second,day,month,year=string.match(payload,".*timestr=(%d+):(%d+):(%d+) (%d+)-(%d+)-(%d+)")
                    conn=nil
                    print("time request processed")
    end )
    conn:connect(80,host)
    conn:send("GET /time1921681974.php HTTP/1.1\r\nHost: " .. host .. "\r\n"
              .."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
    print("Sent time request")


Notice there are two prints() - one when the send has been done, another when the callback function has completed - usually instantly - the string matching is just to pull out time etc.

This works all the time, every time, returning 2 print() statements.

HOWEVER, wrap it in a LUA file - the second print "time request processed" works - but the callback NEVER operates.

I've checked every line that goes into the LUA file and it simply isn't working.

I even tried wrapping the code in a function call and it makes no difference. put it into a LUA file and DOFILE it and the callback will not operate - this USED to work.

HELP!!!!
User avatar
By ThomasW
#5305 Just a guess: Maybe the 'send' comes too fast (before the connection is made, especially as DNS is involved)?
You could try to add an on('connection') - callback and place the 'send' there

Thomas