示例-订阅mosiac数据
local log = require("log")
local json = require("json")
local http = require("http")
-------------------------------------------------------------------------------------
--[[
示例,订阅mosiac数据
]]
-------------------------------------------------------------------------------------
local prog_name = "订阅mosiac数据" --程序名称,日志
local object_id = "OBJ3014355407xx" --设备ID(需要设定)
function run()
--订阅马赛克事件
pub2mmq:send(json.encode({["event"] = "recv_fv",["object_id"] = object_id}))
local exit = false
while (exit == false) do
channel.select({ "|<-", mmq_resp, mosaic_handler }, { "|<-", mmq_stop, function(ok, data)
exit = true
end })
end
end
function mosaic_handler(ok, data)
req = json.decode(data)
show("接收到数据"..object_id, req)
end
function show(msg, info)
local str_info = ""
if type(info) == "table" then
str_info = json.encode(info)
elseif type(info) == "nil" then
str_info = ""
else
str_info = tostring(info)
end
msg = "prog_name:"..prog_name..";object_id:"..object_id .. ";[" .. os.date("%Y-%m-%d %H:%M:%S") .. "];" .. msg
log.info(msg ..";" .. str_info)
--log.info(json_info)
end
----===============------
run()
文档更新时间: 2024-05-28 11:13 作者:技术支持