Help with multiple GET requests and received order
Posted: Thu Apr 02, 2015 12:44 am
hey, trying to figure out why this is returned out of order?
init.lua
s.lua
this is returned via lualoader console
then other times, this
also if i place an if/then statement that refers to fv and/or ft at the end of s.lua it will process the if/then before the http requests even though it is placed at the end.
thanks in advance and sorry if i'm incorrect with my terminology.
-Andy
init.lua
Code: Select all
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","PASSWORD")
print(wifi.sta.getip())
tmr.alarm(0, 30000, 1, function() dofile("s.lua") end )
s.lua
Code: Select all
-- ft
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) success=true
ft = tonumber(string.sub(payload, string.find(payload, "<field1>") + 8, string.find(payload, "</field1>") - 1))
print("f= 1")
print("ft= "..ft)
end)
conn:on("disconnection", function(conn, payload) print("disconnect") conn:close() end)
conn:on("connection", function(conn, payload) print("sending...")
conn:send("GET /channels/CHANNEL/fields/1/last.xml HTTP/1.0\r\n")
conn:send("Host: api.thingspeak.com\r\n")
conn:send("Accept: */*\r\n")
conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")
conn:send("\r\n")
end)
conn:connect(80,'184.106.153.149')
-- fv
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) success=true
fv = tonumber(string.sub(payload, string.find(payload, "<field5>") + 8, string.find(payload, "</field5>") - 1))
print("f= 5")
print("fv= "..fv)
end)
conn:on("disconnection", function(conn, payload) print("disconnect") conn:close() end)
conn:on("connection", function(conn, payload) print("sending...")
conn:send("GET /channels/CHANNEL/fields/5/last.xml HTTP/1.0\r\n")
conn:send("Host: api.thingspeak.com\r\n")
conn:send("Accept: */*\r\n")
conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")
conn:send("\r\n")
end)
conn:connect(80,'184.106.153.149')
this is returned via lualoader console
Code: Select all
nil
> sending...
sending...
f= 1
ft= 70.925
f= 5
fv= 0
disconnect
disconnect
then other times, this
Code: Select all
nil
> sending...
sending...
f= 5
fv= 0
f= 1
ft= 70.925
disconnect
disconnect
also if i place an if/then statement that refers to fv and/or ft at the end of s.lua it will process the if/then before the http requests even though it is placed at the end.
thanks in advance and sorry if i'm incorrect with my terminology.
-Andy