創作者:niwusong | 更新日期:2017-02-09 | 在線時長:14天
NODEMCU-BMP085/MQ135/GY-30 在線監測氣壓和溫度/空氣質量/光照
我的BMP085都是整數是原因?調試的print有兩個小數,傳到貝殼都是整數了?你的源程序可以發一下我嗎?niwusong@163.com QQ :82528190 TKS
解決辦法:在https://nodemcu-build.com官方網站上下載的bin固件選擇float版本的,不要選擇int整數的,就可以了。
--init.lua if true then --change to if true ssid1="freewifi" password1="1234567890" ssid2="eve" password2="eve379549581" ssid3="freewifi" password3="1234567890" g_mac=nil print("set up wifi mode") wifi.setmode(wifi.STATION) wifi.sta.config(ssid2,password2) wifi.sta.connect() cnt = 0 tmr.alarm(1, 1000, tmr.ALARM_AUTO, function() if (wifi.sta.getip() == nil) and (cnt < 20) then print("IP unavaiable, Waiting...") cnt = cnt + 1 else tmr.stop(1) if (cnt < 20) then print("IP:"..wifi.sta.getip()) MAC=wifi.sta.getmac() mac=string.gsub(MAC,":","") g_mac = mac print("MAC:"..mac) --dofile("testbmp085.lua") --dofile("mqtt.lua") --這里設置自動執行的程序,去掉減號就可以運行了。 --dofile("uart.lua") --這里設置自動執行的程序,去掉減號就可以運行了。 --dofile("list.lua") dofile("bmp085.lua") --dofile("httpbmp085.lua") --dofile("bigiot.lua") else print("SSID1 not Connected.") print("SSID2 connect again") end end end) else print("\n") print("Please edit 'init.lua' first:") print("Step 1: Modify wifi.sta.config() function in line 5 according settings of your wireless router.") print("Step 2: Change the 'if false' statement in line 1 to 'if true'.") node.restart() end --bmp085.lua --please input your deceive parameters bmp085.init(1, 2) DEVICEID = "1347" APIKEY = "09dd54b61" INPUTID1 = "1338" INPUTID2 = "1339" host=host or "www.eqytg.org" port=port or 8181 cu = net.createConnection(net.TCP) cu:connect(port, host) ok, s = pcall(cjson.encode, {M="checkin",ID=DEVICEID,K=APIKEY}) if ok then print(s) else print("failed to encode!") end cu:send(s.."\n" ) --keeping the on-line state tmr.alarm(1, 40000, 1, function() cu:send(s.."\n" ) end) --update the data and output tmr.alarm(2, 5000, 1, function() temp = bmp085.temperature() / 10 press = tonumber(bmp085.pressure()/ 100) str="{\"M\":\"update\",\"ID\":\""..DEVICEID.."\",\"V\":{\""..INPUTID1.."\":"..temp..",\""..INPUTID2.."\":"..press.."}}\n" cu:send(str) print("Pressure: ", press, "mbar") print("Temperature: ", temp, "℃") --print(string.format("Temperature: %s.%s degrees C", temp, temp % 10)) print("Pressure: ", press, "mbar") print(type(temp)) end)