---wifi setup
wifi.setmode(wifi.STATION)
wifi.sta.config("SEUSSID","SUASENHAWIFI") -- conf de rede wifi
tmr.delay(1000000)
bimb=1
PIN = 4 -- data pin, GPIO2
--load DHT22 module and read sensor
function ReadDHT22()
dht22 = require("dht22")
dht22.read(PIN)
t = dht22.getTemperature()/10
h = dht22.getHumidity()/10
-- release module
dht22 = nil
package.loaded["dht22"]=nil
end
--- Get temp and send data to thingspeak.com
function sendData()
ReadDHT22()
-- conection
print("Sending data....")
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end)
-- api.servidor scada
conn:connect(8080,"192.168.0.57")
conn:send("GET /KT/httpds?".."__device="..000.. "&T="..(t).. "&H="..(h) .." HTTP/1.1\r\n")
conn:send("Host: agr.kttelemed.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")
conn:on("sent",function(conn)
conn:close()
end)
conn:on("disconnection", function(conn)
end)
end
-- send data every X ms to thing speak
tmr.alarm(0, 30000, 1, function() sendData() end )