-- Giorgio Rutigliano -- rel 1.0, 9/17 -- needs firmware built with dht file gpio net node tmr uart wifi modules wifi.setmode(wifi.STATION) station_cfg={} station_cfg.ssid="" station_cfg.pwd="" wifi.sta.config(station_cfg) wifi.sta.connect() wifi.sta.setip({ip="192.168.0.111",netmask="255.255.255.0",gateway="192.168.0.254"}) id = node.chipid() in_dht=4 srv=net.createServer(net.TCP, 20) --print("Server started on " .. wifi.sta.getip()) srv:listen(80,function(con) con:on("receive",function(con,request) page=string.match(request, "GET (%S+) HTTP") st1, t1, h1, t1d, h1d = dht.read(in_dht) if st1~=dht.OK then t1=-999 h1=-999 end if page=="/json" then con:send('{"t": '..(t1)..', "h": '..(h1)..'}') elseif page=="/data" then con:send('') con:send('Clima Serra') if t1>0 then bg="green" fg="white" else bg="red" fg="yellow" end con:send('') con:send('
') con:send('') con:send('') con:send('') con:send('') con:send('') con:send('
Temperatura
'..t1..'
Umidità
'..h1..'
') con:send('
') con:send('') else con:send('direct access not allowed') end end) -- end 'on receive' con:on("sent", function(conn) con:close() collectgarbage() end) -- end 'on sent' end)