-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript1.lua
More file actions
40 lines (32 loc) · 1.22 KB
/
Copy pathscript1.lua
File metadata and controls
40 lines (32 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
wifi.sta.config("shivi" ,"shivi1893")
wifi.sta.connect()
function GetDataFromThingspeak(_server, _port, _channel, _field)
--print("Querying data from thingspeak")
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload)
tmr.wdclr()
--print(payload)
tmr.wdclr()
conn:close()
ThingspeakReply = payload
print("Query ".._server..":".._port.." channel".._channel.." field".._field.." REPLY: "..ThingspeakReply.."\n")
end)
conn:connect(_port,_server)
--Send request for receiving data in payload
conn:send("GET /channels/263048/fields/1/last?key=ND74EYBDOR6TQBTD HTTP/1.1\r\n")
conn:send('Host: 52.7.7.190\r\nAccept: */*\r\nUser-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n\r\n')
conn:on("disconnection", function(conn)
--print("Got disconnection...")
conn=nil
end)
end
-- END GET DATA FROM THINGSPEAK
function data_init()
if ThingspeakReply == nil then
GetDataFromThingspeak("52.7.7.190", 80, 263048, 1)
else
print("Last entry in Thingspeak database: "..ThingspeakReply.."\n")
-- now a valid reply is available, do whatever you want with the read value
end
end
tmr.alarm(0,5000, 1, function() data_init() end )