APIKEY = ā€¯YourPrivateThingSpeakAPIKeyā€¯ APIIP = "54.88.155.198" print("*** You've got 1 sec to stop timer 0 ***") tmr.alarm(0, 1000, 0, function() print("Good morning") enduser_setup.start( function() print("Connected to wifi as:" .. wifi.sta.getip()) tmr.alarm(1,1000,tmr.ALARM_SINGLE,function()readDHT()end) tmr.alarm(2, 4000, tmr.ALARM_SINGLE,function() print("Good night") node.dsleep(15*60*1000000) end ) end, function(err, str) print("enduser_setup: Err #" .. err .. ": " .. str) end ); end) function readDHT() pin = 2 status, temp, humi, temp_dec, humi_dec = dht.read(pin) if status == dht.OK then -- Integer firmware using this example str_temp = string.format("%d.%d", math.floor(temp), math.floor(temp_dec/100) ) str_humi = string.format("%d.%d", math.floor(humi), math.floor(humi_dec/100) ) sendData(str_temp, str_humi) elseif status == dht.ERROR_CHECKSUM then sendData(-1, -1) --"DHT Checksum error." elseif status == dht.ERROR_TIMEOUT then sendData(-2, -2) --"DHT timed out." end end function sendData(temp, humi) -- conection to thingspeak.com conn=net.createConnection(net.TCP, 0) conn:on("receive", function(sck, payload) print(payload) end) conn:connect(80,APIIP) conn:on("connection", function(sck,c) print("Got connection") print("Send temp="..temp..", humi="..humi) conn:send("GET /update?key="..APIKEY.."&field1="..temp.."&field2="..humi.." HTTP/1.1\r\nHost: "..APIIP.."\r\nConnection: close\r\nAccept: */*\r\n\r\n") end) conn:on("sent",function(sck) print("Closing connection") conn:close() end) conn:on("disconnection", function(sck) print("Got disconnection...") end) end