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 \n Content-Type: text/html \n Refresh: 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
-- resp = resp .. string.format("Sensor %s: %s ℃</br>", addr, temp)
2017-03-10 22:10:49 +01:00
resp = resp .. string.format ( " Sensor %s: %s ℃</br> " , encoder.toHex ( addr ) , temp ) -- readable address with base64 encoding is preferred when encoder module is available
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
-- t:readTemp(readout) -- default pin value is 3
t : readTemp ( readout , pin )
2015-01-10 10:58:08 +01:00
end
)