国内综合精彩aⅤ无码不卡_日本少妇做爰全过程_欧美性爱在线播放免费_午夜?V日韩一区二区_免费a级毛片无码免费播放_成在人线av无码喷水_亚洲精品网站色视频_国产婷婷精品成人_老师撩起裙子让我桶的视频_秋霞影院国产

(Nodemcu)基于esp8266的DHT11的實時數(shù)據(jù)監(jiān)控

作者:zong209 | 更新時間:2016-04-08 | 瀏覽量:9669

剛學esp8266不久,經(jīng)過各種碰壁,總算將DHT11數(shù)據(jù)傳到貝殼上了.

第一次發(fā)帖,不足之處還請指正!

準備:

1.       esp8266

2.       DHT11傳感器

3.       (DHT,CJSON)的固件(自己定制)http://nodemcu-build.com/(DHT模塊可以很方便的讀出傳感器的數(shù)據(jù),開始不知道,花了好多時間在讀數(shù)據(jù),還總出錯)

4.       NodeMCU Studio 2015_beta0.3工具NodeMcu Studio 2015_beta0.3.rar

5.       果云ESP8266輔助工具果云ESP8266調(diào)試助手V1.1.zip

(可用于調(diào)試,先不上傳至貝殼,可以先嘗試將命令發(fā)送到本機服務器上,看命令是否符合貝殼通訊協(xié)議)

接線蠻簡單(AOSONG面朝上,從左至右分別是GND,NC,OUT,VCC)

Pin

名稱

注釋

1

VDD

供電  3-5.5VDC

2

DATA

串行數(shù)據(jù)單總線,接I/O口,上拉電阻

3

NC

空腳請懸空

4

GND

接地,電源負極

接線圖.jpg



代碼:

local temp=0

local humi=0

pin=2

--wifi station configured

wifi.setmode(wifi.STATION)

wifi.sta.config("ssid","password ")

wifi.sta.connect()

 cnt = 0

--connect

 tmr.alarm(1, 1000, 1, 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("Config done, IP is "..wifi.sta.getip())

--please input your deceive parameters

DEVICEID = "設備ID"

APIKEY = "設備APIKEY"

INPUTID1 = "數(shù)據(jù)口1ID"

INPUTID2 = "數(shù)據(jù)口2ID"

host=host or "m.placeboworld.cn"

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, 60000, 1, function()

cu:send(s.."\n" )

end)

--update the data and output 

tmr.alarm(2, 5000, 1, function()

status, temp, humi, temp_dec, humi_dec = dht.read(pin)

if status == dht.OK then

print("DHT Temperature:"..temp..";".."Humidity:"..humi.."%")

elseif status == dht.ERROR_CHECKSUM then

print( "DHT Checksum error." )

elseif status == dht.ERROR_TIMEOUT then

print( "DHT timed out." )

end

--uploading command

str="{\"M\":\"update\",\"ID\":\""..DEVICEID.."\",\"V\":{\""..INPUTID1.."\":"..temp..",\""..INPUTID2.."\":"..humi.."}}\n"

cu:send(str)

end)

else print("Wifi setup time more than 20s, Please verify wifi.sta.config() function. Then re-download the file.")

    end

end

 end)



注意:1.數(shù)據(jù)獲取和上傳命令放在同一個定時器下(

status, temp, humi, temp_dec, humi_dec = dht.read(pin)

str="{\"M\":\"update\",\"ID\":\""..DEVICEID.."\",\"V\":{\""..INPUTID1.."\":"..temp..",\""..INPUTID2.."\":"..humi.."}}\n"

cu:send(str)

2.沒有返回“welcome to m.placeboworld.cn”,但設備是可以上線的,需要等會。

加上

cu:on("receive", function(cu, c) 

print(c)

end)就有返回了











評論:共10條

貝殼物聯(lián) 評論于:2016-04-07 20:32:21
多謝分享,平臺有什么不足之處,還望多提意見。
nikoava 評論于:2016-04-13 20:41:42
為什么會有兩個數(shù)據(jù)口ID?
chenyuechi 回復于:2016-04-15 13:18:28
回復 @nikoava:一個存溫度,一個存濕度
回到未來 評論于:2016-05-08 23:58:19
cjson解析這塊我這里一直報錯,樓主有辦法嗎?
ANIC: unprotected error in call to Lua API (node_init.lua:42: Expected value but found invalid token at character 1)
謝謝了!
回到未來 評論于:2016-05-08 23:59:16
對了,我用的是解析cjson,
sk:on("receive", function(sck, c) print(c)
if signal==1 then
r = cjson.decode(c)
……
回到未來 評論于:2016-05-09 08:44:11
樓主,你定制固件后,燒寫時候blank.bin,boot.bin這些文件是在哪里下載的?配置頁面可以分享一下嗎?多謝指點!
centuryway 評論于:2016-10-06 22:12:14
樓主,我的DHT返回DHT time out,怎么解決?謝謝!
qqrr111 評論于:2017-01-02 12:12:16
unprotected error in call to Lua API (shidu.lua:81: attempt to index global 'dht' (a nil value))
貝殼物聯(lián) 回復于:2017-01-15 21:54:34
回復 @qqrr111:這個是因為你刷的固件里沒有dht模塊。
yan 評論于:2018-05-13 16:34:20
為什么我的每隔幾個數(shù)據(jù)才會出現(xiàn)一個正確的數(shù)據(jù)
返回頂部