publishThingModelMessage

版本要求:
DeviceKit≥2.0.7@ray-js/ray≥0.6.23
支持平台:
iOSAndroid
import { device } from '@ray-js/ray';

const { publishThingModelMessage } = device;

// Promise 调用
try {
  const res = await publishThingModelMessage({ ...params });
  console.log(res);
} catch (err) {
  console.log(err.errorMsg);
}

方法签名
publishThingModelMessage(params: )
SDK 最低版本
iOSThingSmartDeviceKitBizBundle
≥ 5.2.0
Androidcom.thingclips.smart:thingsmart-bizbundle-devicekit
≥ 5.2.0

描述

通过物模型投递消息

参数

属性类型必填说明SDK 最低版本
devIdstring是设备id—
typenumber是类型 0:属性, 1:动作, 2:事件—
payloadRecord<string, any>是物模型投递消息体,结构随 type 不同而变化,示例如下: Example: type == property: payload = { "color":"green", "brightness": 50 } type == action: payload = { "actionCode": "testAction", "inputParams": { "inputParam1":"value1", "inputParam2":"value2" } }—
complete() => void否接口调用结束的回调函数(调用成功、失败都会执行)—
success() => void否接口调用成功的回调函数—
fail(params: Object) => void否接口调用失败的回调函数—
fail 回调参数
属性类型说明
errorMsgstring错误信息
errorCodestring | number错误码
错误扩展

返回值

无

示例代码

import { device } from '@ray-js/ray'

device.publishThingModelMessage({
  devId: "xx",
  type: 0,
  payload: {
    color: "green",
    brightness: 50,
  },
  success: data => {
    console.log(data);
  },
  fail: error => {
    console.error(error);
  },
});