上面是我的微信和QQ群,欢迎新朋友的加入。
资源和烧录我就不管了,和https://blog.csdn.net/Jun626/article/details/109150006一模一样
把那个kaiguan的lua改一下代码
DEVICEID = "19539"
APIKEY = "17aaa8a16"
INPUTID = "10945"
host = host or "www.bigiot.net"
port = port or 8181
RELAY1 = 0
RELAY2 = 1
RELAY3 = 2
RELAY4 = 3
RELAY5 = 4
RELAY6 = 5
gpio.mode(RELAY1,gpio.OUTPUT)
gpio.mode(RELAY2,gpio.OUTPUT)
gpio.mode(RELAY3,gpio.OUTPUT)
gpio.mode(RELAY4,gpio.OUTPUT)
gpio.mode(RELAY5,gpio.OUTPUT)
gpio.mode(RELAY6,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 =="D1904" then
gpio.write(RELAY1, gpio.HIGH)
ok, played = pcall(cjson.encode, {M="say",ID=r.ID,C="RELAY1 turn on!"})
cu:send( played.."\n" )
end
if r.C == "play" and r.S =="D1905" then
gpio.write(RELAY2, gpio.HIGH)
ok, played = pcall(cjson.encode, {M="say",ID=r.ID,C="RELAY2 turn on!"})
cu:send( played.."\n" )
end
if r.C == "play" and r.S =="D1906" then
gpio.write(RELAY3, gpio.HIGH)
ok, played = pcall(cjson.encode, {M="say",ID=r.ID,C="RELAY3 turn on!"})
cu:send( played.."\n" )
end
if r.C == "play" and r.S =="D1907" then
gpio.write(RELAY4, gpio.HIGH)
ok, played = pcall(cjson.encode, {M="say",ID=r.ID,C="RELAY4 turn on!"})
cu:send( played.."\n" )
end
if r.C == "play" and r.S =="D1908" then
gpio.write(RELAY5, gpio.HIGH)
ok, played = pcall(cjson.encode, {M="say",ID=r.ID,C="RELAY5 turn on!"})
cu:send( played.."\n" )
end
if r.C == "play" and r.S =="D1909" then
gpio.write(RELAY6, gpio.HIGH)
ok, played = pcall(cjson.encode, {M="say",ID=r.ID,C="RELAY6 turn on!"})
cu:send( played.."\n" )
end
if r.C == "stop" and r.S =="D1904" then
gpio.write(RELAY1, gpio.LOW)
ok, stoped = pcall(cjson.encode, {M="say",ID=r.ID,C="RELAY1 turn off!"})
cu:send( stoped.."\n" )
end
if r.C == "stop" and r.S =="D1905" then
gpio.write(RELAY2, gpio.LOW)
ok, stoped = pcall(cjson.encode, {M="say",ID=r.ID,C="RELAY2 turn off!"})
cu:send( stoped.."\n" )
end
if r.C == "stop" and r.S =="D1906" then
gpio.write(RELAY3, gpio.LOW)
ok, stoped = pcall(cjson.encode, {M="say",ID=r.ID,C="RELAY3 turn off!"})
cu:send( stoped.."\n" )
end
if r.C == "stop" and r.S =="D1907" then
gpio.write(RELAY4, gpio.LOW)
ok, stoped = pcall(cjson.encode, {M="say",ID=r.ID,C="RELAY4 turn off!"})
cu:send( stoped.."\n" )
end
if r.C == "stop" and r.S =="D1908" then
gpio.write(RELAY5, gpio.LOW)
ok, stoped = pcall(cjson.encode, {M="say",ID=r.ID,C="RELAY5 turn off!"})
cu:send( stoped.."\n" )
end
if r.C == "stop" and r.S =="D1909" then
gpio.write(RELAY6, gpio.LOW)
ok, stoped = pcall(cjson.encode, {M="say",ID=r.ID,C="RELAY6 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("faiRELAY to encode!")
end
cu:send(s.."\n")
tmr.alarm(1, 60000, 1, function()
cu:send(s.."\n")
end)
end
run()
烧录
步骤来源于https://www.bigiot.net/talk/935.html
开始
1. 添加设备
2. 点击编辑并将设备类型设置为万能遥控器保存
3. 添加接口 保存
4.添加子设备 要添加四个(当然你要控制几路就添加几个),注意父设备的一致 保存
打开天猫精灵,更新一下设备
然后就可以控制了