Air724 DTU数据上报json到v1/gateway/telemetry

Air724 DTU数据上报json到v1/gateway/telemetry

任务模板:

Lua 复制代码
function
    sys.wait(10000)
	local taskname="userTask"
	log.info(taskname,"start")
	local nid =1
	local netmsg ="UART_DATA_TO_NET"..nid
	while true do
        local t={}
        t.params = {} -- 定义 params 为数组
        params_temperature = "25" -- 温度
        params_humidity = "50" -- 湿度
        params_getClock = misc.getClock() -- 获取时间
        params_getImei = misc.getImei() --获取IMEI
        params_getIccid = sim.getIccid() --获取卡号
        params_getRssi = net.getRssi() -- 获取信号强度
        table.insert(t.params, {temperature = params_temperature, humidity = params_humidity, getClock = params_getClock, getImei = params_getImei, getIccid = params_getIccid, getRssi = params_getRssi}) -- 插入一个对象
        local str=nil
        str = json.encode(t)
        log.info("temp str=",str)

        pronet.PronetInsertSendChache(nid,str)
        sys.publish(netmsg)
		sys.wait(3000)
	end
end

如果你想让 params 这个 JSON key 使用 IMEI 号作为名称,可以这样做:

Lua 复制代码
function
    sys.wait(10000)
	local taskname="userTask"
	log.info(taskname,"start")
	local nid =1
	local netmsg ="UART_DATA_TO_NET"..nid
	while true do
        local t={}
        local imei = misc.getImei() or "unknown_imei" -- 避免 nil 错误
        t[imei] = {} -- 定义 params 为数组
        params_temperature = "25" -- 温度
        params_humidity = "50" -- 湿度
        params_getClock = misc.getClock() -- 获取时间
        params_getImei = misc.getImei() --获取IMEI
        params_getIccid = sim.getIccid() --获取卡号
        params_getRssi = net.getRssi() -- 获取信号强度
        table.insert(t[imei], {temperature = params_temperature, humidity = params_humidity, getClock = params_getClock, getImei = params_getImei, getIccid = params_getIccid, getRssi = params_getRssi}) -- 插入一个对象
        local str=nil
        str = json.encode(t)
        log.info("temp str=",str)

        pronet.PronetInsertSendChache(nid,str)
        sys.publish(netmsg)
		sys.wait(3000)
	end
end

DTU设备数据上报:

Lua 复制代码
function
    sys.wait(10000)
	local taskname="userTask"
	log.info(taskname,"start")
	local nid =1
	local netmsg ="UART_DATA_TO_NET"..nid
	while true do
        local t={}
        local imei = "1#DTU" or "unknown_imei" -- 避免 nil 错误
        t[imei] = {} -- 定义 params 为数组
        params_getClock = misc.getClock() -- 获取时间
        params_getImei = misc.getImei() --获取IMEI
        params_getIccid = sim.getIccid() --获取卡号
        params_getRssi = net.getRssi() -- 获取信号强度
        table.insert(t[imei], {getClock = params_getClock, getImei = params_getImei, getIccid = params_getIccid, getRssi = params_getRssi}) -- 插入一个对象
        local str=nil
        str = json.encode(t)
        log.info("temp str=",str)

        pronet.PronetInsertSendChache(nid,str)
        sys.publish(netmsg)
		sys.wait(5000)
	end
end
相关推荐
IT_陈寒10 分钟前
Vue3性能优化实战:这5个技巧让我的应用加载速度提升70%
前端·人工智能·后端
mumu1307梦13 分钟前
html 占位符
前端·javascript·html
龙茶清欢20 分钟前
在 Spring Cloud Gateway 中实现跨域(CORS)的两种主要方式
java·spring boot·spring cloud·微服务·gateway
WY20 分钟前
前端项目部署:Nginx 从入门到实战
前端
Apifox24 分钟前
Apifox 9 月更新| AI 生成接口测试用例、在线文档调试能力全面升级、内置更多 HTTP 状态码、支持将目录转换为模块
前端·后端·测试
用户4582031531724 分钟前
CSS性能优化全攻略:提升页面加载与渲染速度
前端·css
90后的晨仔1 小时前
Vue 组件事件完全指南:子父组件通信的艺术
前端·vue.js
90后的晨仔1 小时前
Vue 组件通信全解
前端
golang学习记1 小时前
从0死磕全栈之Next.js 中的 CSS 方案全解析:Global CSS、CSS Modules、Tailwind CSS 怎么选?
前端
Waker1 小时前
🚀 Turbo 使用指南
前端