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

Tison溫度濕度LED控制

Tison溫度濕度LED控制的詳細(xì)介紹

創(chuàng)作者:zls121zls | 更新日期:2020-09-22 | 在線時長:111天
Tison溫度濕度LED控制,有源碼哦-_-!!!

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

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

一:準(zhǔn)備工作

環(huán)境搭建:

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

2、固件燒錄工具:esp8266 flash升級燒寫燒錄工具v2.1綠色版

3、燒寫教程:參考difiot

4、以上所有資料訪問百度云盤

 

基于nodemuc編程API說明中文版本

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

NodeMCU所有資料和源碼

https://github.com/nodemcu

基礎(chǔ)編程手冊

http://manual.luaer.cn/

 

二:硬件介紹

三:相關(guān)源碼

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

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

-----runtime.lua---------------------------------------------------

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

bLive=0
bOnLine=0

gpio.mode(config.LEDG,gpio.OUTPUT)
gpio.mode(config.LEDR,gpio.OUTPUT)
gpio.mode(config.LEDB,gpio.OUTPUT)
gpio.write(config.LEDG,gpio.LOW) 
gpio.write(config.LEDR,gpio.LOW) 
gpio.write(config.LEDG,gpio.LOW) 

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
    end)
    --執(zhí)行命令
    dofile("sayCommand.lua")
end)

--modify DEVICEID1 INPUTID APIKEY DEVICEID2
config={
host = host or "m.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
    --定時心跳,防止掉線
    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
    --上報濕度
    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

 --sayCommand.lua----------------------------------------------------

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

if r.M == "say" then     
    local commander=r.C    
    if commander == "play" then  
        print("play:LEDG turn on!")    
        gpio.write(config.LEDG,gpio.LOW) 
        ok, played = pcall(cjson.encode, {M="say",ID=r.ID,C="LEDG turn on!"})
        cu:send( played.."\n" )
    elseif commander == "stop" then 
        print("play:LEDG turn off!")         
        gpio.write(config.LEDG,gpio.HIGH)
        ok, stoped = pcall(cjson.encode, {M="say",ID=r.ID,C="LEDG turn off!"})
        cu:send( stoped.."\n" )     
   elseif commander == "up" then 
        print("up:LEDR turn on!") 
        gpio.write(config.LEDR,gpio.LOW)
        ok, uped = pcall(cjson.encode, {M="say",ID=r.ID,C="LEDR turn off!"})
        cu:send( uped.."\n" )  
   elseif commander == "plus" then  
        print("plus:LEDR turn off!")       
        gpio.write(config.LEDR,gpio.HIGH)
        ok, plused = pcall(cjson.encode, {M="say",ID=r.ID,C="LEDR turn off!"})
        cu:send( plused.."\n" )  
   elseif commander == "pause" then  
        print("pause:LEDB turn on!") 
        gpio.write(config.LEDB,gpio.LOW)
        ok, paused = pcall(cjson.encode, {M="say",ID=config.DEVICEID,C="LEDB turn off!"})
        cu:send( paused.."\n" )  
   elseif commander == "right" then 
        print("right:LEDB turn off!")        
        gpio.write(config.LEDB,gpio.HIGH)
        ok, righted = pcall(cjson.encode, {M="say",ID=config.DEVICEID,C="LEDB turn off!"})
        cu:send( righted.."\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