user_script/channel-demo.lua

54 lines
1.2 KiB
Lua
Raw Normal View History

2024-06-24 07:05:17 +00:00
--[[
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~"
})