1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| module(...,package.seeall) require"aLiYun" require"misc" require"pm" require"pins"
local PRODUCT_KEY = "a1sLSgWRLGZ"
local function getDeviceName() return "869300031602869" end
local function setDeviceSecret(s) misc.setSn(s) end
local function getDeviceSecret() return "2wdomNTGLFZCPykcxCUWrEH3c1O8qGs9" end
local sConnected
local function rcvCbFnc(topic,qos,payload)
log.info("testALiYun.rcvCbFnc:",topic,qos,payload)
local tjsondata,result,errinfo = json.decode(payload) key = tjsondata["params"]['LightSwitch'] log.info("key:",key) data(key) end
function data(key) local led1 = pins.setup(pio.P0_6,0) if key == 0 then led1(0) log.info("ledon") else if key == 1 then led1(1) log.info("ledoff") end end
end
local function connectCbFnc(result) log.info("testALiYun.connectCbFnc",result) sConnected = result if result then aLiYun.subscribe({["/sys/"..PRODUCT_KEY.."/"..getDeviceName().."/thing/service/property/set"]=0, ["/"..PRODUCT_KEY.."/"..getDeviceName().."/get"]=1}) aLiYun.on("receive",rcvCbFnc) publishTest() end end
local function authCbFnc(result) log.info("testALiYun.authCbFnc",result) end
function gpio4IntFnc(msg) local beel = pins.setup(pio.P0_2,0) log.info("testGpioSingle.gpio4IntFnc",msg,getGpio4Fnc()) if msg==cpu.INT_GPIO_POSEDGE then beel(1) log.info("ladi,miedeng") else beel(0) publishTest(LockCloseData) log.info("liang") end end
getGpio4Fnc = pins.setup(pio.P0_4,gpio4IntFnc)
aLiYun.setup(PRODUCT_KEY,nil,getDeviceName,getDeviceSecret)
aLiYun.on("auth",authCbFnc) aLiYun.on("connect",connectCbFnc)
|