--Barometer Glass & Brass V1.2 with three hourly trend pressure -- ************************************************************** ssid = "yourSSID" -- your router SSID pass = "yourPassword" -- your router password alti = 185 -- set correction for your altitude location in meters -- ************************************************************** wifi.setmode(wifi.STATION) wifi.sta.config(ssid, pass,1) _,RID=node.bootreason() myheap=0 srp=5 -- period reading of sensors [s] sda=4 -- GPIO2 connect to SDA BMP180 scl=3 -- GPIO0 connect to SCL BMP180 press=0 -- actual pressure from BMP180 pressold=0 -- pressure (n-3)hour temp=0 -- temperature BMP180 PressAngle=0 -- angle of pointer calculated from pressure PressAngle = 30+(press-960)*3 TrendAngle=189.9 -- angle of "press trend" pointer ctdown=3 -- hour counter for "press trend" -- web page - barometer face with included parameters function LoadBuff() local buff2 = '\ Barometer\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 970\ 980\ 990\ 1000\ 1010\ 1020\ 1030\ 1040\ 1050\ hPa\ '..temp..'\ C\ '..press..'\ hPa\ \ \ \ \ \ \ Reset ID : '..RID..' Heap : '..myheap..'' 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 collectgarbage() end -- read sensor, load buffer function ReadBMP180() bmp085.init(sda,scl) press=string.format("%.1f",tostring(bmp085.pressure()/((1-alti/44330)^5.255)/100)) temp=string.format("%.1f",tostring(bmp085.temperature()/10)) PressAngle=string.format("%.1f",tostring(30+(press-960)*3)) myheap=node.heap() LoadBuff() --print("Lenght of http page: ",#buff1) collectgarbage() end -- web server function StartServer() srv = net.createServer(net.TCP, 120) 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() collectgarbage() end) end end) end end) collectgarbage() 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 -- main loop 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) ReadBMP180() print("Server start") StartServer() -- periodic reading of sensors and load buffer tmr.alarm(1,srp*1000,1, function() ReadBMP180() print("My heap :",myheap) end) pressold=press TrendAngle=string.format("%.1f",tostring(30+(pressold-960)*3)) -- three hourly periodic trending tmr.alarm(0,3600000,1, function() ctdown=ctdown-1 if ctdown < 1 then TrendAngle=string.format("%.1f",tostring(30+(pressold-960)*3)) pressold=press ctdown=3 end end) end end)