目录
一、项目意义和项目简介
二、硬件设计
1.原理图设计
2.PCB设计
3、主要器件
3.1三轴加速度传感器
3.2可燃气体传感器
3.3GPS模块
4、MQTT通信协议设计
三、微信小程序设计
3.1、连接EMQX服务器步骤
3.2、MQTT发布订阅测试
3.3程序界面设计
1)APP主页面:
2)地图界面设计
3)设备信息界面设计
4)设备日志页面设计
4、MQTT通信协议设计
说明: 在这个项目中,AIR780E模块使用MQTT协议,用于将传感器数据上传到云服务器。设备作为MQTT终端发布消息到服务器上的一个主题,其他客户端(如小程序或移动说明)可以订阅这个主题以接收数据。
关键部分代码:
PROJECT = "mqttdemo"
VERSION = "1.0.0"
PROJECT = "gnsstest"
VERSION = "1.0.1"
-- LuaTools需要PROJECT和VERSION这两个信息
PROJECT = "adcdemo"
_G.sys = require("sys")
_G.sysplus = require("sysplus")
local mpu6xxx = require "mpu6xxx"
i2cid = 0
i2c_speed = i2c.FAST
local mqtt_host = "www.visionexpand.com.cn"
local mqtt_port = 1883
local mqtt_isssl = false
local client_id = "emqx"
local pub_topic = "$thing/up/property/IQMPOB8BI9/temp/humi"
local sub_topic = "mqtt"
local uart2_data = "text"
local adc_pin_1=1
local data_pub={ }
-- libgnss库初始化
libgnss.clear() -- 清空数据,兼初始化
if wdt then
wdt.init(9000) sys.timerLoopStart(wdt.feed, 3000) end
local uartid = 2
local result = uart.setup(
uartid,
115200,
8,
1
)
sys.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")
将数据打包至EMQX服务器:
local mqtt_host = “www.visionexpand.com.cn”
local mqtt_port = 1883
local mqtt_isssl = false
local 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) end
sys.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”)
接下来请见连载3
对本项目感兴趣的同学、朋友,或者需要定制、学术论文使用的都可以扫码联系: