Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sensorId(addr)
- --return string.format("%02x%02x%02x%02x%02x%02x%02x%02x", addr:byte(1,8))
- return string.format("%02x%02x%02x%02x%02x%02x", string.reverse(addr):byte(2,7))
- end
- function prepareSensorToHtml(i, serial, temp)
- return string.format("<h2>#%s - %s</h2><h3>%.4f°C</h3>\r\n", i, serial, temp)
- end
- function httpReceive(c, payload)
- r = "HTTP/1.1 200/OK\r\nServer: NodeLua\r\nContent-Type: text/html\r\n\r\n"
- addrs = t.addrs()
- for i=1,table.getn(addrs)
- do
- r = r .. prepareSensorToHtml(i, sensorId(addrs[i]), t.read(addrs[i]))
- end
- c:send(r)
- c:close()
- end
- function httpListen(c, data)
- c:on("receive", httpReceive)
- end
- function uploadTemp()
- addrs=t.addrs()
- for i=1,table.getn(addrs)
- do
- serial = sensorId(addrs[i])
- temp = string.format("%.2f", t.read(addrs[i]))
- url = string.format("http://monitor.shajen.pl/api/temp/add?serial=%s&temperature=%.2f&key=%s", serial, temp, KEY)
- http.get(url, nil, nil)
- end
- end
- KEY="XXXXXX" -- wymagany klucz, dla chetnych trzeba sie zglosic
- t=require("ds18b20")
- t.setup(4)
- wifi.setmode(wifi.STATION)
- wifi.sta.config("NAZWA SIECI","HASLO")
- httpServer=net.createServer(net.TCP, 30)
- httpServer:listen(8080, httpListen)
- tmr.alarm(0, 60000, tmr.ALARM_AUTO, uploadTemp) -- co 60s wgrywa dane na serwer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement