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
相关推荐
霍理迪12 小时前
CSS复合、关系、属性、伪类选择器
前端·javascript·css
棒棒的唐12 小时前
Avue2图片上传使用object对象模式时,axios的请求模式用post还是get?
开发语言·前端·javascript·avue
OnlyEasyCode12 小时前
Linux部署Nginx前后端web教程
linux·前端·nginx
梵得儿SHI12 小时前
Vue Router 路由管理从入门到精通:基础、导航与参数传递实战(含避坑指南)
前端·javascript·vue.js·路由基础配置·版本适配·路由实例创建·路由规则定义
IT_陈寒13 小时前
JavaScript 性能优化实战:7 个让你的应用提速 50%+ 的 V8 引擎技巧
前端·人工智能·后端
Watermelo61713 小时前
【前端实战】Axios 错误处理的设计与进阶封装,实现网络层面的数据与状态解耦
前端·javascript·网络·vue.js·网络协议·性能优化·用户体验
不一样的少年_13 小时前
【性能监控】别只做工具人了!手把手带你写一个前端性能检测SDK
前端·javascript·监控
开发者小天13 小时前
react中使用复制的功能
前端·javascript·react.js
AI炼金师13 小时前
Chrome 中的 Claude 入门指南
前端·chrome
德迅云安全—珍珍13 小时前
2025 年 Chrome 浏览器 0Day 漏洞全面分析:八大高危漏洞遭利用
前端·chrome