作者:GAO0594 | 更新时间:2019-11-05 | 浏览量:1489
8266对接天猫精灵固件,谁有?
LED =3 gpio.mode(LED,gpio.OUTPUT) cu = net.createConnection(net.TCP) cu:connect(port, host) ok, s = pcall(sjson.encode, {M="checkin",ID=DEVICEID,K=APIKEY}) if ok then print(s) else print("failed to encode!") end cu:on("receive", function(cu, c) print(c) r = sjson.decode(c) if r.M == "say" then if r.C == "play" then gpio.write(LED, gpio.HIGH) ok, played = pcall(sjson.encode, {M="say",ID=r.ID,C="LED turn on!"}) cu:send( played.."\n" ) end if r.C == "stop" then gpio.write(LED, gpio.LOW) ok, stoped = pcall(sjson.encode, {M="say",ID=r.ID,C="LED turn off!"}) cu:send( stoped.."\n" ) end end end) tmr.create():alarm(20000, tmr.ALARM_AUTO, function() cu:send( s.."\n" ) print(s) end)