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
相关推荐
大飞记Python16 分钟前
部门管理|“编辑部门”功能实现(Django5零基础Web平台)
前端·数据库·python·django
tsumikistep1 小时前
【前端】前端运行环境的结构
前端
你的人类朋友1 小时前
【Node】认识multer库
前端·javascript·后端
Aitter1 小时前
PDF和Word文件转换为Markdown的技术实现
前端·ai编程
mapbar_front2 小时前
面试问题—上家公司的离职原因
前端·面试
昔人'3 小时前
css使用 :where() 来简化大型 CSS 选择器列表
前端·css
昔人'3 小时前
css `dorp-shadow`
前端·css
流***陌3 小时前
扭蛋机 Roll 福利房小程序前端功能设计:融合趣味互动与福利适配
前端·小程序
烛阴3 小时前
用 Python 揭秘 IP 地址背后的地理位置和信息
前端·python
前端开发爱好者4 小时前
尤雨溪官宣:"新玩具" 比 Prettier 快 45 倍!
前端·javascript·vue.js