2017-02-25 22:56:45 +01:00
|
|
|
t = require('ds18b20')
|
2015-01-10 10:58:08 +01:00
|
|
|
|
|
|
|
port = 80
|
2017-02-25 22:56:45 +01:00
|
|
|
pin = 3 -- gpio0 = 3, gpio2 = 4
|
|
|
|
gconn = {} -- global variable for connection
|
2015-01-10 10:58:08 +01:00
|
|
|
|
2017-02-25 22:56:45 +01:00
|
|
|
function readout(temp)
|
|
|
|
local resp = "HTTP/1.1 200 OK\nContent-Type: text/html\nRefresh: 5\n\n" ..
|
|
|
|
"<!DOCTYPE HTML>" ..
|
|
|
|
"<html><body>" ..
|
2017-03-10 22:10:49 +01:00
|
|
|
"<b>ESP8266</b></br>"
|
|
|
|
|
2017-02-25 22:56:45 +01:00
|
|
|
for addr, temp in pairs(temp) do
|
2017-08-16 21:04:52 +02:00
|
|
|
resp = resp .. string.format("Sensor %s: %s ℃</br>", ('%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X '):format(addr:byte(1,8)), temp)
|
2017-02-25 22:56:45 +01:00
|
|
|
end
|
2017-03-10 22:10:49 +01:00
|
|
|
|
2017-02-25 22:56:45 +01:00
|
|
|
resp = resp ..
|
|
|
|
"Node ChipID: " .. node.chipid() .. "<br>" ..
|
|
|
|
"Node MAC: " .. wifi.sta.getmac() .. "<br>" ..
|
|
|
|
"Node Heap: " .. node.heap() .. "<br>" ..
|
|
|
|
"Timer Ticks: " .. tmr.now() .. "<br>" ..
|
|
|
|
"</html></body>"
|
2015-01-10 10:58:08 +01:00
|
|
|
|
2017-02-25 22:56:45 +01:00
|
|
|
gconn:send(resp)
|
|
|
|
gconn:on("sent",function(conn) conn:close() end)
|
|
|
|
end
|
2015-01-10 10:58:08 +01:00
|
|
|
|
|
|
|
srv=net.createServer(net.TCP)
|
|
|
|
srv:listen(port,
|
|
|
|
function(conn)
|
2017-02-25 22:56:45 +01:00
|
|
|
gconn = conn
|
2017-08-16 21:04:52 +02:00
|
|
|
-- t:read_temp(readout) -- default pin value is 3
|
|
|
|
t:read_temp(readout, pin)
|
2015-01-10 10:58:08 +01:00
|
|
|
end
|
|
|
|
)
|