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