# sendLuaRequest ^5.1.2

通过 LUA 查询控制设备状态

# 请求参数

Prop Type Required Default Description
options Object Y
{}
属性:
params:{
Type: Object,
Default: N/A,
Description: 查询/控制参数
}
operation:{
Type: String,
Default: luaControl,
Description: 可选值为luaQuery或者luaControl
}
applianceId:{
Type: String,
Default: N/A,
Description: 设备 Id 为deviceId
}
}
mode:{// ^5.12
Type: Number,
Default: 0,
Description: 0优先局域网发送,不在局域网则广域网透传(默认);1只发送广域网透传,若广域网透传失败,则直接返回错误信息;
}
控制状态参数
isShowLoading Boolean Y true 是否显示加载图标

# 接口调用示例

const options = {
  operation: 'luaControl',
  params: {
    power: 'on',
  },
}
this.$bridge
  .sendLuaRequest(options)
  .then((res) => {
    this.$alert(res)
  })
  .catch((err) => {
    this.$toast(err)
  })
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  • 调用示例:

export default {
    ...
    methods: {
        powerHandler(flag) {
            let options = {
                operation: "luaControl",
                params: {
                    power: flag == 1 ? "on" : "off";,
                }
            };
            this.$bridge
            .sendLuaRequest(options)
            .then((resp) => {
                // 成功获取返回数据 resp
                // 执行自定义业务逻辑


            }, (error) => {
                console.log("error");
            });
        }
    }
    ...
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

# 返回参数

Prop Type Required Default Description
result Object N
{}
属性:
error_code:{
Type: Number,
Default: N/A,
Description: 错误码
}
version:{
Type: Number,
Default: N/A,
Description: 版本
}
结果
data Object N N/A 设备状态十六进制编码
errorCode Number Y N/A 错误码: 0 正常回调 /-1 请求超时

tip

  • lua 和设备的通信调试工具
  • 如使用 lua 调试工具时,参数的格式应按照 lua 的参数格式说明来传(详情请查看 lua 相关的文档)。
  • 而在插件中使用sendLuaRequest接口的参数格式仍然按照文档中约定格式。
Last Updated: 8/17/2021, 3:34:44 PM