当前位置: 首页 > article >正文

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

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

任务模板:

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 号作为名称,可以这样做:

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设备数据上报:

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


http://www.kler.cn/a/544609.html

相关文章:

  • 2D小游戏-创新设计——《弹射挑战》
  • 伯克利 CS61A 课堂笔记 08 —— Strings and Dictionaries
  • 解析 JavaScript 面试题:`index | 0` 确保数组索引为整数
  • 数据库安全、分布式数据库、反规范化等新技术(高软19)
  • 连锁收银系统的核心架构与技术选型
  • 51c自动驾驶~合集50
  • Tweak Power:高效电脑系统优化利器
  • ubuntu 实时系统安装Nvidia驱动
  • 小米红米手机澎湃2.0解锁BL 绕澎湃社区验证 救砖以及9008授权
  • 优雅的git log输出内容更加醒目
  • 【愚公系列】《Python网络爬虫从入门到精通》007-请求模块requests高级应用(Reguests-HTML)
  • Kubernetes部署OwnCloud网盘服务
  • 基于javaweb的SpringBoot+MyBatis健身房信息管理系统(源码+文档+部署讲解)
  • 深入理解DeepSeek与企业实践(二):32B多卡推理的原理、硬件散热与性能实测
  • 06:串口通信
  • python使用虚拟环境
  • Python 依赖管理的革新——Poetry 深度解析
  • C# Dictionary的实现原理
  • 走进 Tcl 语言:历史、特性与应用
  • 数据结构:图论入门