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

User avatar
By Daveth3
#42832 Hoi,

I'm a newbie in NodeMCU (LUA)and I'm trying all day to loop every 5 sec to get some data from a remote website.
First time start it goes well but it get disconected before the timer restart.
So I have two questions:
1) how to loop this, so that I'll recieve every 5 sec this data
2) how to start it direct without waiting for the timer is compleet.

Code: Select allconn=net.createConnection(net.TCP, 0)
conn:connect(80,'trayradio.com')

conn:on("receive", function(conn, payload)
   back = string.match(payload, '<p>(.*)</p>')
   print(back)
end)

function everySec()
   gpio.write(0,gpio.LOW)
   conn:send("GET /PHP/stats.php? HTTP/1.1\r\nHost: trayradio.com\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")
end

conn:on("disconnection", function(conn, payload)
   print('\nDisconnected')
end)

tmr.alarm(0, 5000, 1, everySec)


Please help me :D