iot - Lua alarm does not execute code -


i'm programming in nodemcu using lualoader. i'm trying read adc of node , send php file in public domain.

with next code adc , node's ip , send through get.

x = adc.read(0); ip = wifi.sta.getip();  conn=net.createconnection(net.tcp, 0)  conn:on("receive", function(conn, payload) print(payload) end)  conn:connect(80,'example.com')  conn:send("get /data.php?mdata="..x.."&ip="..ip.." http/1.1\r\n")  conn:send("host: example.com\r\n")  conn:send("connection: keep-alive\r\naccept: */*\r\n")  conn:send("user-agent: mozilla/4.0 (compatible; esp8266 lua; windows nt 5.1)\r\n") conn:send("\r\n") print ("done") 

the code works correctly. if paste in lualoader return:

 http/1.1 200 ok  date: wed, 30 sep 2015 02:47:51 gmt  server: apache  x-powered-by: php/5.5.26  content-length: 0  keep-alive: timeout=2, max=100  connection: keep-alive  content-type: text/html   done 

however, want repeat code inside alarm , send data each minute, doesnt work.

tmr.alarm(0, 60000, 1, function()     x = adc.read(0);     ip = wifi.sta.getip();      conn=net.createconnection(net.tcp, 0)      conn:on("receive", function(conn, payload) print(payload) end)      conn:connect(80,'example.com')      conn:send("get /data.php?mdata="..x.."&ip="..ip.." http/1.1\r\n")      conn:send("host: example.com\r\n")      conn:send("connection: keep-alive\r\naccept: */*\r\n")      conn:send("user-agent: mozilla/4.0 (compatible; esp8266 lua; windows nt 5.1)\r\n")     conn:send("\r\n")     print ("done")  end ) 

the output only...

 done 

...without payload. not sending data.

i tried putting code in function, in file , calling alarm dotfile not work. tried giving more time send data extending alarm 2 minutes nothing.

from documentation of tmr.alarm, 3rd argument can 0 or 1:

repeat: `0` - 1 time alarm, `1` - repeat 

since passing 0, executing function once. pass 1 instead:

tmr.alarm(0, 60000, 1, function()     x = adc.read(0);     ip = wifi.sta.getip();      conn=net.createconnection(net.tcp, 0)      conn:on("receive", function(conn, payload) print(payload) end)      conn:connect(80,'robcc.esy.es')      conn:send("get /data.php?mdata="..x.."&ip="..ip.." http/1.1\r\n")      conn:send("host: robcc.esy.es\r\n")      conn:send("connection: keep-alive\r\naccept: */*\r\n")      conn:send("user-agent: mozilla/4.0 (compatible; esp8266 lua; windows nt 5.1)\r\n")     conn:send("\r\n")     print ("done") end ) 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -