user_script/channel-demo.lua
CSSC-WORK\murmur b4f1927cf2 add more
2024-06-24 15:05:17 +08:00

54 lines
1.2 KiB
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

--[[
通用消息通道示例代码
该功能拓展了lua脚本的控制范围
可以更加灵活地进行自动化测试
]]
-- uart对应软件自身的串口功能
apiSetCb("uart",function (data)
log.info("uart received",data)
end)
local sendResult = apiSend("uart","ok!")
-- mqtt对应 MQTT 选项卡
apiSetCb("mqtt",function (data)
log.info(
"mqtt received",
data.topic,
data.payload,
data.qos)
end)
local sendResult = apiSend("mqtt",nil,
{
topic = "test",
payload = "test",
qos = 0
})
-- tcp-server对应 本机TCP服务端 选项卡
apiSetCb("tcp-server",function (data)
log.info(
"tcp-server received",
data.from,
data.data)
end)
local sendResult = apiSend("tcp-server","broadcast message!")
-- socket-client对应 socket客户端 选项卡
apiSetCb("socket-client",function (data)
log.info("socket-client received", data)
end)
local sendResult = apiSend("socket-client","send message by lua!")
-- netlab对应 socket公共服务端 选项卡
apiSetCb("netlab",function (data)
log.info(
"netlab received",
data.client,
data.data)
end)
local sendResult = apiSend("netlab",nil,
{
client = "aioSession--718957913",
data = "test data~"
})