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

Tison溫度濕度LED控制的詳細(xì)介紹(基于nodemcu編程)

作者:zls121zls | 更新時(shí)間:2016-12-08 | 瀏覽量:6754

控制界面:http://www.placeboworld.cn/Panel/index/id/134.html

詳細(xì)介紹:http://www.placeboworld.cn/info/822.html

一:準(zhǔn)備工作

環(huán)境搭建:

1、PC端軟件,需要安裝java   ESPlorer

2、固件燒錄工具:esp8266 flash升級(jí)燒寫(xiě)燒錄工具v2.1綠色版

3、燒寫(xiě)教程:參考difiot

4、以上所有資料訪問(wèn)百度云盤(pán)

 

基于nodemuc編程API說(shuō)明中文版本

https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_cn

NodeMCU所有資料和源碼

https://github.com/nodemcu

基礎(chǔ)編程手冊(cè)

http://manual.luaer.cn/

 

二:硬件介紹

三:相關(guān)源碼

軟件管腳解讀:NODEMCU對(duì)應(yīng)TISON開(kāi)發(fā)板ESP8266管腳關(guān)系,如下圖

TISON開(kāi)發(fā)板
NODEMCU引腳  TISON開(kāi)發(fā)板 輸入輸出 開(kāi)發(fā)板標(biāo)識(shí) 連接關(guān)系
IO6 GPIO12 輸入 photoR 連接Tison ESP8266光敏管
IO6 GPIO12 輸出 REALY 連接Tison ESP8266繼電器
IO6 GPIO12 輸入輸出 DHT 連接Tison ESP8266溫濕度傳感器
IO7 GPIO13 輸出 LEDB 連接Tison ESP8266開(kāi)發(fā)板藍(lán)色LED,藍(lán)色燈亮起進(jìn)入ESPTOUCH模式,配置完成關(guān)閉
IO5 GPIO14 輸出 LEDR 連接Tison ESP8267開(kāi)發(fā)板紅色LED,紅色燈亮起表示故障,故障排除關(guān)閉
IO8 GPIO15 輸出 LEDG 連接Tison ESP8268開(kāi)發(fā)板綠色LED,綠色燈亮起進(jìn)入AIRKISS模式,配置完成關(guān)閉

 

--init.lua
print("set up wifi mode")
wifi.setmode(wifi.STATION)
wifi.sta.config("JSZLZXBGS","jszlzx123")
--here SSID and PassWord should be modified according your wireless router
wifi.sta.connect()
tmr.alarm(1, 1000, 1, function()
    if wifi.sta.getip()== nil then
        print("IP unavaiable, Waiting...")
    else
        tmr.stop(1)
        print("IP:"..wifi.sta.getip())
        dofile("runtime.lua")     
    end
end)

 

dofile("config.lua")
dofile("Dht.lua")
dofile("SendData.lua")

bLive=0
bOnLine=0

cu = net.createConnection(net.TCP)
cu:connect(config.port, config.host)

cu:on("receive", function(cu, c) 
    print(c)
    r = cjson.decode(c)
    --如果存活標(biāo)記為1,置為0
    if r.M=="isOL" then
        bLive=0 
    end
    tmr.alarm(1, 10000, 1, function()
        --checkin和心跳
        dofile("checkIn.lua")
        --在線后再讀取數(shù)據(jù),發(fā)送年,接收命令
        if bOnLine==1 then
            print("start send data")
            --讀取濕度      
            Humi,Temp=ReadDHT(config.DHTPin)         
            --發(fā)送數(shù)據(jù)
            sendToBigiot(cu,Humi,Temp)
        end
        --執(zhí)行命令
        dofile("sayCommand.lua")
        
    end)
end)

--modify DEVICEID1 INPUTID APIKEY DEVICEID2
config={
host = host or "www.placeboworld.cn",
port = port or 8181,
DEVICEID = "822",
UID=" ",
TempID=" ",
HumiID=" ",
APIKEY = " ",
DHTPin= 6,
LEDPin= 8
}

--收到連接正常,發(fā)送checkin
if r.M == "WELCOME TO BIGIOT" then
    ok, s = pcall(cjson.encode, {M="checkin",ID=config.DEVICEID,K=config.APIKEY})
    if ok then
      print(s)
    else
      print("failed to encode!")
    end
    cu:send( s.."\n" )
    bLive=0
    --定時(shí)心跳,防止掉線
    tmr.alarm(2, 40000, 1, function()
        --如果標(biāo)記為1,表示未收到上次的心跳返回,重啟
        if bLive==3 then
            node.restart()
        end
        ok, ticket = pcall(cjson.encode, {M="isOL",ID="D"..config.DEVICEID})
        print(ticket)
        cu:send(ticket.."\n" )
        --發(fā)送后將標(biāo)記置為1
        bLive=bLive+1        
    end)
end
if r.M=="checkinok" then
    bOnLine=1
end


function ReadDHT(pin)
    dhstatus, temp, humi, temp_dec, humi_dec = dht.read11(pin)
    print(dhstatus)
    if dhstatus == dht.OK then         
        print(string.format("DHT Temperature:%d.%01d;Humidity:%d.%01d\r\n",
        math.floor(temp),
        temp_dec,
        math.floor(humi),
        humi_dec
        ))
        --轉(zhuǎn)換實(shí)際溫度
        realTemp=math.floor(temp)
        --轉(zhuǎn)換實(shí)際濕度
        realhumi=math.floor(humi)
        
        return realhumi,realTemp
        
    elseif status == dht.ERROR_CHECKSUM then
        print( "DHT Checksum error." )
    elseif status == dht.ERROR_TIMEOUT then
        print( "DHT timed out." )
    end
end

function sendToBigiot(cu,humi,temp)
    print(humi)
    print(temp)
     
    if humi==nil then 
        humi=0
    end
    
    if temp==nil then
        temp=0
    end
    --上報(bào)濕度
    local v = {[config.TempID]=string.format("%d", math.floor(temp)),[config.HumiID]=string.format("%d",math.floor(humi))}              
    ok3, s3 = pcall(cjson.encode, {M="update",ID=config.DEVICEID,V=v})
    print("send data:"..s3)
    cu:send( s3.."\n")
end

 --如果是say代表命令

LEDG = 5
LEDR = 7
LEDB = 8

gpio.mode(LEDG,gpio.OUTPUT)
gpio.mode(LEDR,gpio.OUTPUT)
gpio.mode(LEDB,gpio.OUTPUT)


gpio.write(LEDG, gpio.LOW)
gpio.write(LEDR, gpio.HIGH)
gpio.write(LEDB, gpio.HIGH)
 
if r.M == "say" then     
    local commander=r.C 
    if commander == "play" then     
        gpio.write(LEDG, gpio.LOW) 
        gpio.write(LEDR, gpio.LOW)
        gpio.write(LEDB, gpio.LOW) 
        ok, played = pcall(cjson.encode, {M="say",ID=config.UID,C="LED turn on!"})
        cu:send( played.."\n" )
    elseif commander == "stop" then     
        gpio.write(LEDG, gpio.HIGH)
        gpio.write(LEDR, gpio.HIGH)
        gpio.write(LEDB, gpio.HIGH)
        ok, stoped = pcall(cjson.encode, {M="say",ID=config.UID,C="LED turn off!"})
        cu:send( stoped.."\n" )  
    end  
end

 

四:相關(guān)資料參考

經(jīng)典的NodeMCU lua教程,值得好好看看 

http://www.electrodragon.com/w/ESP8266_NodeMCU_Lua

http://www.nodemcu.com/index_cn.html

http://nodemcu.readthedocs.io/en/master/

http://www.electrodragon.com/smartconfig-nodemcu/

http://www.zhihu.com/question/36288709

http://blog.csdn.net/leytton/article/details/51723221

http://www.tinylab.org/nodemcu-kickstart/

http://my.oschina.net/u/2306127/blog/402931

http://www.esp8266.com/viewforum.php?f=17

http://nodemcu-dev.doit.am/index.html

https://github.com/SmartArduino/Doit_Cloud

http://www.wifimcu.com

http://nodemcu.doit.am/

http://www.esp8266.com

http://git.oschina.net/HEKRCLOUD/hekr-esp8266-sdk-ra

NodeMCU固件編譯環(huán)境搭建

http://blog.csdn.net/free0loop/article/details/48518729


評(píng)論:共4條

貝殼物聯(lián) 評(píng)論于:2016-10-22 14:55:14
灰常詳細(xì),謝謝分享-_-!!!
coldfish 評(píng)論于:2016-11-18 10:45:22
好貼,大有用處
沃斯托克 評(píng)論于:2017-07-08 11:35:36
你好,根據(jù)你的代碼含cjson的固件可以實(shí)現(xiàn),現(xiàn)在新生成的含sjon的固件,把代碼中cjson改為sjson,有錯(cuò)誤,找了很多天,不知道什么原因,能否幫我解答下,謝謝
沃斯托克 評(píng)論于:2017-07-08 11:37:01
固件生成網(wǎng)址https://nodemcu-build.com/
返回頂部