Free network configuration + smallest and most concise
Free network configuration + smallest and most concise
Free network configuration + smallest and most concise
Get started in one minute
It is developed using GPRS module + LUA language, which is super simple.
Mom no longer has to worry that I don’t understand C pronunciation.
There are only a few original parts, and the welding is done in five minutes.
Control the switch action through cloud intelligence and Tmall Genie
At first I thought 2G would have serious delays, but the test was perfect. See attachments
Common MQTT is used to connect to Alibaba Cloud, and the device is kept online through heartbeats.
If the device heartbeat report times out, the APP and Tmall Genie will prompt that the device is not online.
All cloud data processing is done on Alibaba Cloud, and local users are responsible for reporting on/off status.
module(...,package.seeall)
require"aLiYun"
require"misc"
require"pm"
local PRODUCT_KEY = "your key"
local function getDeviceName()
return misc.getImei()
end
local function setDeviceSecret(s)
misc.setSn(s)
end
local function getDeviceSecret()
return misc.getSn()
end
local sConnected
local publishCnt = 1
local function publishTestCb(result,para)
log.info("testALiYun.publishTestCb",result,para)
sys.timerStart(publishTest,20000)
publishCnt = publishCnt+1
end
function publishTest()
if sConnected then
aLiYun.publish("/"..PRODUCT_KEY.."/"..getDeviceName().."/update","qos1data",1,publishTestCb,"publishTest_"..publishCnt)
end
end
local function rcvCbFnc(topic,qos,payload)
log.info("testALiYun.rcvCbFnc",topic,qos,payload)
end
local function connectCbFnc(result)
log.info("testALiYun.connectCbFnc",result)
sConnected = result
if result then
aLiYun.subscribe({["/"..PRODUCT_KEY.."/"..getDeviceName().."/get"]=0, ["/"..PRODUCT_KEY.."/"..getDeviceName().."/get"]=1})
aLiYun.on("receive",rcvCbFnc)
publishTest()
end
end
local function authCbFnc(result)
log.info("testALiYun.authCbFnc",result)
end
aLiYun.setup(PRODUCT_KEY,nil,getDeviceName,getDeviceSecret)
aLiYun.on("auth",authCbFnc)
aLiYun.on("connect",connectCbFnc)
require"aLiYunOta"
local function otaCb(result,filePath)
log.info("testALiYun.otaCb",result,filePath)
if result then
local uartID = 1
sys.taskInit(
function()
local fileHandle = io.open(filePath,"rb")
if not fileHandle then
log.error("testALiYun.otaCb open file error")
if filePath then os.remove(filePath) end
return
end
pm.wake("UART_SENT2MCU")
uart.on(uartID,"sent",function() sys.publish("UART_SENT2MCU_OK") end)
uart.setup(uartID,115200,8,uart.PAR_NONE,uart.STOP_1,nil,1)
while true do
local data = fileHandle:read(1460)
if not data then break end
uart.write(uartID,data)
sys.waitUntil("UART_SENT2MCU_OK")
end
aLiYunOta.setVer("MCU_VERSION_1.0.1")
uart.close(uartID)
pm.sleep("UART_SENT2MCU")
fileHandle:close()
if filePath then os.remove(filePath) end
end
)
else
if filePath then os.remove(filePath) end
end
end
function
local str = ...
local off = '{"method":"thing.service.property.set","id":"","params":{"powerstate":0},"version":"1.0.0"}'
local on = '{"method":"thing.service.property.set","id":"","params":{"powerstate":1},"version":"1.0.0"}'
res,res1,res2 = json.decode(str)
if res["params"]["powerstate"] == 0 then
local led = pins.setup(pio.P0_8,0)
led(0)
return off, 1
elseif res["params"]["powerstate"] == 1 then
local led = pins.setup(pio.P0_8,1)
led(1)
return on, 1
else
return str,1
end
end
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet