作者:1197994757 | 更新时间:2019-07-12 | 浏览量:5825
这是一个不错的想法... ( 你怎么知道的?)
这里我只写贝壳物联子设备的使用和“kaiguan.lua"的具体代码
详细教程比如使用的软件啊下载操作啊还有"init.lua" 我就不贴出来了,都一样的。不会的看参考教程
参考链接
https://www.bigiot.net/help/20.html
https://blog.csdn.net/qq_33508087/article/details/82925995
https://www.bigiot.net/talk/927.html
萌新看这三篇够了
老司机直接开始
开始
1. 添加设备
2. 点击编辑并将设备类型设置为万能遥控器保存
3. 添加接口 保存
4.添加子设备 要添加四个(当然你要控制几路就添加几个),注意父设备的一致 保存
5. OK 接下来打开 "kaiguan.lua" 把里面的代码全删了, 把下面的代码复制上去。
DEVICEID = "12046"
APIKEY = "6870b391e"
INPUTID = "10945"
host = host or "www.bigiot.net"
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
--停止心跳包发送定时器,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 对应 ESP8266的 12 13 14 5 引脚 ,懂的自行修改)
将 “ if r.C == "play" and r.S =="D258" or r.C == "play1" then ”里的258修改为你的子设备ID 我的对应插座一
一样其余三个对应你的子设备ID修改
if r.C == "stop" and r.S =="D258" or r.C == "stop1" then 这个关的同理 也改好
7.改好 并下载到 ESP8266

8.复位或重启 去贝壳物联设备列表刷新看看设备有没有上线 (要好一会才能刷新出来)
好吧 我这个号被禁止登录 没图了

----------------------------------------------------------------------
上线了试一下 设备对话--发送命令 play1 如果有返回数据就是正常了
9.天猫精灵绑定贝壳物联 并刷新 看到四个插座后 就可以让猫精独立控制ESP 四路继电器了(可以用万用表测一下ESP 12 13 14 5 脚的电平)
因为是我的小号 所以不打码了 好让你们看清我的思路 这是重点 如果没有成功就看代码了解我的思路自己改去
我需要经验+1 我的子设备不够用没法继续折腾了
看完了回复一下吧
我需要经验+1 