作者:1197994757 | 更新時(shí)間:2019-07-12 | 瀏覽量:5765
這是一個(gè)不錯(cuò)的想法... ( 你怎么知道的?)
這里我只寫貝殼物聯(lián)子設(shè)備的使用和“kaiguan.lua"的具體代碼
詳細(xì)教程比如使用的軟件啊下載操作啊還有"init.lua" 我就不貼出來了,都一樣的。不會(huì)的看參考教程
參考鏈接
http://www.placeboworld.cn/help/20.html
https://blog.csdn.net/qq_33508087/article/details/82925995
http://www.placeboworld.cn/talk/927.html
萌新看這三篇夠了
老司機(jī)直接開始
開始
1. 添加設(shè)備
2. 點(diǎn)擊編輯并將設(shè)備類型設(shè)置為萬能遙控器保存
3. 添加接口 保存
4.添加子設(shè)備 要添加四個(gè)(當(dāng)然你要控制幾路就添加幾個(gè)),注意父設(shè)備的一致 保存
5. OK 接下來打開 "kaiguan.lua" 把里面的代碼全刪了, 把下面的代碼復(fù)制上去。
DEVICEID = "12046"
APIKEY = "6870b391e"
INPUTID = "10945"
host = host or "www.placeboworld.cn"
port = port or 8181
LED = 5
LED1 = 6
LED2 = 7
LED3 = 1
gpio.mode(LED,gpio.OUTPUT)
gpio.mode(LED1,gpio.OUTPUT)
gpio.mode(LED2,gpio.OUTPUT)
gpio.mode(LED3,gpio.OUTPUT)
local function run()
local cu = net.createConnection(net.TCP)
cu:on("receive", function(cu, c)
print(c)
r = cjson.decode(c)
if r.M == "say" then
if r.C == "play" and r.S =="D258" or r.C == "play1" then
gpio.write(LED, gpio.HIGH)
ok, played = pcall(cjson.encode, {M="say",ID=r.ID,C="LED turn on!"})
cu:send( played.."\n" )
end
if r.C == "play" and r.S =="D259" or r.C == "play2" then
gpio.write(LED1, gpio.HIGH)
ok, played = pcall(cjson.encode, {M="say",ID=r.ID,C="LED1 turn on!"})
cu:send( played.."\n" )
end
if r.C == "play" and r.S =="D260" or r.C == "play3" then
gpio.write(LED2, gpio.HIGH)
ok, played = pcall(cjson.encode, {M="say",ID=r.ID,C="LED2 turn on!"})
cu:send( played.."\n" )
end
if r.C == "play" and r.S =="D261" or r.C == "play4" then
gpio.write(LED3, gpio.HIGH)
ok, played = pcall(cjson.encode, {M="say",ID=r.ID,C="LED3 turn on!"})
cu:send( played.."\n" )
end
if r.C == "stop" and r.S =="D258" or r.C == "stop1" then
gpio.write(LED, gpio.LOW)
ok, stoped = pcall(cjson.encode, {M="say",ID=r.ID,C="LED turn off!"})
cu:send( stoped.."\n" )
end
if r.C == "stop" and r.S =="D259" or r.C == "stop2" then
gpio.write(LED1, gpio.LOW)
ok, stoped = pcall(cjson.encode, {M="say",ID=r.ID,C="LED1 turn off!"})
cu:send( stoped.."\n" )
end
if r.C == "stop" and r.S =="D260" or r.C == "stop3" then
gpio.write(LED2, gpio.LOW)
ok, stoped = pcall(cjson.encode, {M="say",ID=r.ID,C="LED2 turn off!"})
cu:send( stoped.."\n" )
end
if r.C == "stop" and r.S =="D261" or r.C == "stop4" then
gpio.write(LED3, gpio.LOW)
ok, stoped = pcall(cjson.encode, {M="say",ID=r.ID,C="LED3 turn off!"})
cu:send( stoped.."\n" )
end
end
end)
cu:on('disconnection',function(scu)
cu = nil
--停止心跳包發(fā)送定時(shí)器,5秒后重試
tmr.stop(1)
tmr.alarm(6, 5000, 0, run)
end)
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")
tmr.alarm(1, 60000, 1, function()
cu:send(s.."\n")
end)
end
run()
6.修改代碼
代碼前三行寫你的 (LED 5 6 7 1 對(duì)應(yīng) ESP8266的 12 13 14 5 引腳 ,懂的自行修改)
將 “ if r.C == "play" and r.S =="D258" or r.C == "play1" then ”里的258修改為你的子設(shè)備ID 我的對(duì)應(yīng)插座一
一樣其余三個(gè)對(duì)應(yīng)你的子設(shè)備ID修改
if r.C == "stop" and r.S =="D258" or r.C == "stop1" then 這個(gè)關(guān)的同理 也改好
7.改好 并下載到 ESP8266

8.復(fù)位或重啟 去貝殼物聯(lián)設(shè)備列表刷新看看設(shè)備有沒有上線 (要好一會(huì)才能刷新出來)
好吧 我這個(gè)號(hào)被禁止登錄 沒圖了

----------------------------------------------------------------------
上線了試一下 設(shè)備對(duì)話--發(fā)送命令 play1 如果有返回?cái)?shù)據(jù)就是正常了
9.天貓精靈綁定貝殼物聯(lián) 并刷新 看到四個(gè)插座后 就可以讓貓精獨(dú)立控制ESP 四路繼電器了(可以用萬用表測(cè)一下ESP 12 13 14 5 腳的電平)
因?yàn)槭俏业男√?hào) 所以不打碼了 好讓你們看清我的思路 這是重點(diǎn) 如果沒有成功就看代碼了解我的思路自己改去
我需要經(jīng)驗(yàn)+1 我的子設(shè)備不夠用沒法繼續(xù)折騰了
看完了回復(fù)一下吧
我需要經(jīng)驗(yàn)+1 