NODEMCU-NWS

NODEMCU-NWS的详细介绍

创作者: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.bigiot.net" 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)