-- Demo http server for sensor DHT11 - tested with NodeMCU 0.9.5 build 20150107 -- 1. Flash NodeMCU 0.9.5 build 20150107 or later to ESP module. -- 2. Load program monDHT11.lua and dht11.lua to ESP8266 with LuaLoader -- 3. You can rename the program monDHT11.lua to init.lua -- 3. HW reset module -- 4. Login module to your AP - wifi.setmode(wifi.STATION),wifi.sta.config("yourSSID","yourPASSWORD") -- 5. Run program monDHT11.lua - dofile(monDHT11.lua) -- 6. Test IP address - wifi.sta.getip() -- 7. Test it with your browser and true IP address of module. -- 8. The sensor is repeatedly read every minute. -- 9. The pictures on page are external. --10. The length of html code is limited to 1460 characters including header. --11. The author of the program module dht11.lua for reading DHT sensor is Javier Yanez --wifi.setmode(wifi.STATION) --wifi.sta.config("yourSSID","yourPASSWORD") tmr.delay(1000000) humi="XX" temp="XX" fare="XX" bimb=1 PIN = 4 -- data pin, GPIO2 --load DHT11 module and read sensor function ReadDHT11() dht11 = require("dht11") dht11.read(PIN) t = dht11.getTemperature() h = dht11.getHumidity() humi=(h) temp=(t) fare=((t*9/5)+32) print("Humidity: "..humi.."%") print("Temperature: "..temp.." deg C") print("Temperature: "..fare.." deg F") -- release module dht11 = nil package.loaded["dht11"]=nil end ReadDHT11() tmr.alarm(1,60000, 1, function() ReadDHT11() bimb=bimb+1 if bimb==5 then bimb=0 wifi.sta.connect() print("Reconnect")end end) srv=net.createServer(net.TCP) srv:listen(80,function(conn) conn:on("receive",function(conn,payload) --print(payload) -- for debugging only --generates HTML web site conn:send('HTTP/1.1 200 OK\r\nConnection: keep-alive\r\nCache-Control: private, no-store\r\n\r\n\ \ ESP8266\

Hygrometer with
DHT11 sensor

\

\
\ % of relative humidity

\
\ Temperature grade C
\ Temperature grade F

\ ') conn:on("sent",function(conn) conn:close() end) end) end)