publishDps
下发 DP 功能点
引入
import { publishDps } from '@ray-js/ray';
需引入DeviceKit,且在>=1.2.6版本才可使用
publishDps 在 @ray-js/ray^0.10.4 支持以下两种模式,在之前的版本仅支持 模式二。
模式一
若无特殊场景需求,建议使用智能设备模型控制 DP 功能点
请求参数
| 参数 | 数据类型 | 说明 | 是否必填 |
|---|---|---|---|
| data | DpState | 要下发的 DP 功能点集合 | 是 |
| options | PublishDpsOptions | 下发配置 | 否 |
类型
declare type DpValue = boolean | number | string;
declare type DpState = Record<string, DpValue>;
declare type PublishDpsOptions = {
/**
* 下发通道类型
* 0: 局域网
* 1: 网络
* 2: 自动
*/
mode: number;
/**
* 下发通道的优先级
* LAN = 0, // LAN
* MQTT = 1, // MQTT
* HTTP = 2, // Http
* BLE = 3, // Single Point Bluetooth
* SIGMesh = 4, // Sig Mesh
* BLEMesh = 5, // Tuya Private Mesh
* BLEBeacon = 6, // Beacon
*/
pipelines: number[];
/** 预留下发逻辑配置标记,后续可以拓展,例如下发声音,下发操作后续动作等等 */
options: Record<string, {}>;
};
export declare function publishDps(
data: DpState,
options?: PublishDpsOptions,
): Promise<boolean>;
返回结果
- success
Boolean boolean
- fail
| 属性 | 类型 | 说明 |
|---|---|---|
| errorMsg | string | 插件错误信息 |
| errorCode | string | 错误码 |
| innerError | object | 插件外部依赖错误信息 {errorMsg: string, errorCode: string } |
请求示例
import { publishDps } from '@ray-js/ray';
// 功能点 code 为 key
await publishDps({ power: true });
// 功能点 id 为 key
await publishDps({ 1: true });
返回示例
true;
true;
👉 立即免费领取开发资源,体验涂鸦 MiniApp 小程序开发。
模式二
请求参数
Object object
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| deviceId | string | 是 | 设备 id | |
| dps | Record<dpId, any> | 是 | dps | |
| mode | number | 是 | 下发通道类型 0: 局域网 1: 网络 2: 自动 | |
| pipelines | Array<number> | 是 | 下发通道的优先级 LAN = 0, // LAN MQTT = 1, // MQTT HTTP = 2, // Http BLE = 3, // Single Point Bluetooth SIGMesh = 4, // Sig Mesh BLEMesh = 5, // Thing Private Mesh BLEBeacon = 6, // Beacon | |
| options | Object | 是 | 预留下发逻辑配置标记,后续可以拓展,例如下发声音,下发操作后续动作等等 | |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | |
| success | function | 否 | 接口调用成功的回调函数 | |
| fail | function | 否 | 接口调用失败的回调函数 |
返回结果
- success
Boolean boolean
- fail
| 属性 | 类型 | 说明 |
|---|---|---|
| errorMsg | string | 插件错误信息 |
| errorCode | string | 错误码 |
| innerError | object | 插件外部依赖错误信息 {errorMsg: string, errorCode: string } |
请求示例
publishDps({
deviceId: 'vdevo169477319679442',
dps: { 1: false },
mode: 1,
pipelines: [0, 1, 2, 3, 4, 5, 6],
options: {},
success: res => {
console.log(res);
},
fail: error => {
console.log(error);
},
});
返回示例
true
publishDpsWithPipeType
指定通道发送 dps 控制指令
引入
import { publishDpsWithPipeType } from '@ray-js/ray';
需引入
DeviceKit,且在>=1.2.6版本才可使用
请求参数
Object object
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| deviceId | string | 是 | 设备 id | |
| dps | Record<dpId, any> | 是 | dps | |
| mode | number | 是 | 下发通道类型 0: 局域网 1: 网络 2: 自动 | |
| pipelines | Array<number> | 是 | 下发通道的优先级 LAN = 0, // LAN MQTT = 1, // MQTT HTTP = 2, // Http BLE = 3, // Single Point Bluetooth SIGMesh = 4, // Sig Mesh BLEMesh = 5, // Thing Private Mesh BLEBeacon = 6, // Beacon | |
| options | Object | 是 | 预留下发逻辑配置标记,后续可以拓展,例如下发声音,下发操作后续动作等等 | |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | |
| success | function | 否 | 接口调用成功的回调函数 | |
| fail | function | 否 | 接口调用失败的回调函数 |
返回结果
- success
无
- fail
| 属性 | 类型 | 说明 |
|---|---|---|
| errorMsg | string | 插件错误信息 |
| errorCode | string | 错误码 |
| innerError | object | 插件外部依赖错误信息 {errorMsg: string, errorCode: string } |
请求示例
publishDpsWithPipeType({
deviceId: 'vdevo169477319679442',
dps: {
1: false,
},
mode: 1,
pipelines: [0, 1, 2, 3, 4, 5, 6],
options: {},
success: res => {
console.log(res);
},
fail: error => {
console.log(error);
},
});
👉 立即免费领取开发资源,体验涂鸦 MiniApp 小程序开发。
&spm=1001.2101.3001.5002&articleId=139240356&d=1&t=3&u=75712987a6ee4d019dda6ccd2b2a8837)
1014

被折叠的 条评论
为什么被折叠?



