инфа по Air302
на китайском.
Air302 имеет встроенную VMLua.
можно писать на луа и грузить скрипты как в ESP8266 на lua
--------------------------------
Вот пример MQTT:
-- LuaTools
PROJECT = "mqttairm2m"
VERSION = "1.0.0"
_G.sys = require("sys")
local mqtt = require "mqtt"
sys.taskInit(function()
local host, port, selfid = "lbsmqtt.airm2m.com", 1884, nbiot.imei()
while true do
while not socket.isReady() do
log.info("net", "wait for network ready")
sys.waitUntil("NET_READY", 1000)
end
log.info("main", "Airm2m mqtt loop")
local mqttc = mqtt.client(selfid, nil, nil, false)
while not mqttc:connect(host, port) do sys.wait(2000) end
local topic_req = string.format("/device/%s/req", selfid)
local topic_report = string.format("/device/%s/report", selfid)
local topic_resp = string.format("/device/%s/resp", selfid)
log.info("mqttc", "mqtt seem ok", "try subscribe", topic_req)
if mqttc:subscribe(topic_req) then
log.info("mqttc", "mqtt subscribe ok", "try publish")
if mqttc _ublish(topic_report, "test publish " .. os.date() .. crypto.md5("12345"), 1) then
while true do
log.info("mqttc", "wait for new msg")
local r, data, param = mqttc:receive(120000, "pub_msg")
log.info("mqttc", "mqttc:receive", r, data, param)
if r then
log.info("mqttc", "get message from server", data.payload or "nil", data.topic)
elseif data == "pub_msg" then
log.info("mqttc", "send message to server", data, param)
mqttc_ublish(topic_resp, "response " .. param)
elseif data == "timeout" then
log.info("mqttc", "wait timeout, send custom report")
mqttc_ublish(topic_report, "test publish " .. os.date() .. nbiot.imei())
else
log.info("mqttc", "ok, something happen", "close connetion")
break
end
end
end
end
mqttc:disconnect()
sys.wait(5000)
end
end)
sys.run()
----------------------------