local mqtt_host = "www.visionexpand.com.cn"
local mqtt_port = 1883
local mqtt_isssl = falselocal client_id = "emqx"
local pub_topic = "$thing/up/property/IQMPOB8BI9/temp/humi"
local sub_topic = "mqtt"
local uart2_data = "text"-- libgnss库初始化libgnss.clear() -- 清空数据,兼初始化
if wdt then wdt.init(9000) sys.timerLoopStart(wdt.feed, 3000) endsys.taskInit(function() if rtos.bsp() == "AIR780E"
then device_id = mobile.imei() sys.waitUntil("IP_READY", 30000)
pub_topic = "$thing/up/property/IQMPOB8BI9/temp/humi" sub_topic = "mqtt"
end log.info("mqtt", "pub", pub_topic) log.info("mqtt", "sub", sub_topic)
local mqttc = mqtt.create(nil, mqtt_host, mqtt_port, mqtt_isssl, nil)
mqttc:auth(client_id, nil, nil) mqttc:autoreconn(true, 3000) mqttc:on(function(mqtt_client, event, data, payload)
if event == "conack" then sys.publish("mqtt_conack") mqtt_client:subscribe(sub_topic)
elseif event == "recv"
then log.info("mqtt", "received", "topic", data, "payload", payload)
elseif event == "sent" then log.info("mqtt", "sent", "pkgid", data)
end
end)
mqttc:connect()
sys.waitUntil("mqtt_conack")
标签:mqttc,sub,data,三轴,topic,mqtt,传感器,EMQX,local From: https://blog.csdn.net/TobudOS_people/article/details/140123520