--Hygrometer V1.0 JankoP Factory -- ************************************************************** ssid = "********" -- your router SSID pass = "********" -- your router password fahrenheit=false -- set Celsius or Fahrenheit grade -- false = Celsius` true = Fahrenheit -- ************************************************************** wifi.setmode(wifi.STATION) wifi.sta.config(ssid, pass,1) _,RID=node.bootreason() srp=5 pin=4 humi=0 temp=0 DhtState=" " HumiAngle=0 function ReadDHT() status, temp, humi, temp_dec, humi_dec = dht.read(pin) if status == dht.OK then DhtState="DHT state : OK" print("Humidity : ",humi) if fahrenheit==true then print("Temperature : ",9/5*temp+32," Fahrenheit") else print("Temperature : ",temp," Celsius") end elseif status == dht.ERROR_CHECKSUM then DhtState="DHT state : Checksum error" print( DhtState ) elseif status == dht.ERROR_TIMEOUT then DhtState="DHT state : Timed out error" print( DhtState ) end if fahrenheit==true then temp=9/5*temp+32 unit="F" else unit="C" end humi= string.format("%.1f",tostring(humi)) temp= string.format("%.1f",tostring(temp)) HumiAngle = 40+humi*2.8 end function LoadBuff() local buff2 = '\ Hygrometer\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 0\ 10\ 20\ 30\ 40\ 50\ 60\ 70\ 80\ 90\ 100\ % RH\ '..temp..'\ '..unit..'\ '..humi..'\ \ \ \ ' lenght= #buff2 buff1 = 'HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n'.. 'Content-Length: '.. lenght ..'\r\n'.. 'Cache-Control: max-age=120\r\n'.. 'Connection: Keep-Alive\r\n\r\n'..buff2 buff2=nil end function StartServer() srv = net.createServer(net.TCP, 40) srv:listen(80, function (conn) conn:on("receive", function (client, request) if string.find(request, "GET / HTTP/1.1") ~= nil then client:send(string.sub(buff1,1, (#buff1 > 1460) and 1460 or #buff1), function() if #buff1>1460 then client:send(string.sub(buff1,1461,(#buff1 > 2920) and 2920 or #buff1), function() if #buff1 > 2920 then client:send(string.sub(buff1,2921,#buff1), function() end) end end) end end) else client:send('HTTP/1.1 404 Not found\r\n'.. 'Content-Type: text/html\r\n'.. 'Content-Length: 25\r\n'.. 'Connection: close\r\n\r\n'.. '

Page not found !

') client:close() end end) end) end tmr.alarm(0,1000,1, function() if wifi.sta.getip()==nil then print("Wait for IP") else ipa,_,_=wifi.sta.getip() print("IP is ",ipa) tmr.stop(0) ReadDHT() LoadBuff() print("Server start") StartServer() tmr.alarm(1,srp*1000,1, function() ReadDHT() LoadBuff() end) end end)