I've put together this code to read one of the cheerlights feeds
http://api.thingspeak.com/channels/1417 ... /last.json
but I'd like to make it poll every 60 secs and I'm just going around in circles trying to understand how to do this
Can anyone help please?
Simon
-- get current cheerlights colour
print("Setting the device up as a STATION")
wifi.setmode(wifi.STATION)
print("Connecting to the AP")
wifi.sta.config("CYCY", "")
wifi.sta.connect()
print("Waiting a little bit to get an IP address...")
function main()
sk=net.createConnection(net.TCP, 0)
sk:on("receive", function(sck, c)
field2 = string.find(c, 'field2')
if field2 ~= nil then
pkt = string.sub(c,field2 + 10,field2 + 15)
print ("pkt:" .. pkt)
end
end )
sk:connect(80,"144.212.80.11")
sk:send("GET /channels/1417/field/2/last.json HTTP/1.1\r\nHost: api.thingspeak.com\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")
end
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip()=="0.0.0.0" or wifi.sta.getip() == nil then
print("Connect AP, Waiting...")
else
print("Wifi AP connected. Wicon IP:")
print(wifi.sta.getip())
main()
tmr.stop(1)
end
end)