sendLuaRequest 通过 LUA 查询或控制设备状态

sendLuaRequest ^5.1.2

通过 LUA 查询控制设备状态

#请求参数

Prop Type Required Default Description
options Object Y {} 属性: params: 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)
  })
  • 调用示例:
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");
            });
        }
    }
    ...
}

#返回参数

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

tip

  • lua 和设备的通信调试工具
  • 如使用 lua 调试工具时,参数的格式应按照 lua 的参数格式说明来传(详情请查看 lua 相关的文档)。
  • 而在插件中使用sendLuaRequest接口的参数格式仍然按照文档中约定格式。
posted on 2024-12-17 09:32  AtlasLapetos  阅读(35)  评论(0)    收藏  举报