Dear ALL
I am sending temperature data to thingspeak but it did't show in my channel. Below is my code. Please give me the suggestion.
t=require("ds18b20_1")
pin = 1
t.setup(pin)
addrs = t.addrs()
if (addrs ~= nil) then
print("Total DS18B20 sensors: "..table.getn(addrs))
end
-------------------------------------------------------------------------------
wifi.setmode(wifi.STATIONAP)
wifi.sta.config("INNEXIV", "innexiv$1")
tmr.alarm(0,5000,1, function() -- 5sec for get the ip address for router
add = wifi.sta.getip()
if(add == nil) then
print("Connecting to AP...
")
else
ip, nm, gw=wifi.sta.getip()
print("IP Info:
IP Address: ",ip)
print("Netmask: ",nm)
print("Gateway Addr: ",gw,'
')
tmr.stop(0)
end
end)
-------------------------------------------------
function sendData()
value=ds18b20_1.read()
-- print("temp",value)
print("Sending data to thingspeak.com")
conn=net.createConnection(net.TCP,false)
conn:on("receive", function(conn, payload) print(payload) end)
-- api.thingspeak.com 184.106.153.149
conn:connect(80,'184.106.153.149')
conn:send("GET /update?key=XDKWXU7SQ39WXXPY&field1="..value.." HTTP/1.1
")
conn:send("Host: api.thingspeak.com
")
conn:send("Accept: */*
")
conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)
")
conn:send("
")
conn:on("sent",function(conn)
print("Closing connection")
conn:close()
end)
conn:on("disconnection", function(conn)
print("Got disconnection...")
end)
end
-- send data every X ms to thing speak
tmr.alarm(2, 60000, 1, function() sendData() end )
--------------------------------------------------------