示例-订阅历程数据

local log = require("log")
local json = require("json")
local http = require("http")

-------------------------------------------------------------------------------------
--[[
    示例,订阅历程数据
]]
-------------------------------------------------------------------------------------
local prog_name  = "订阅历程数据"        --程序名称,日志
local object_id  = "OBJ3014355407xx"     --设备id
local retainer_id= "RETAINER1xxxxxx"     --历程id

function run()
    --订阅马赛克事件
    pub2mmq:send(json.encode({["event"] = "retainer_open",["retainer_id"] = retainer_id, ["object_id"] = object_id}))

    local exit = false
    while (exit == false) do
        channel.select({ "|<-", mmq_resp, retainer_handler }, { "|<-", mmq_stop, function(ok, data)
            exit = true
        end })
    end
end

function retainer_handler(ok, data)
    req = json.decode(data)
    show("retainer data"..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:14   作者:技术支持