connectBluetoothDevice
蓝牙连接
聚合接口,支持 Bluetooth LE、双模中 Bluetooth LE、Beacon、Mesh、Mesh 单火类连接。
引入
import { connectBluetoothDevice } from '@ray-js/ray';
需引入
DeviceKit
,且在>=3.1.0
版本才可使用。
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
devId | string | 是 | 设备 ID | |
timeoutMillis | number | 否 | 连接超时时限 单位: 毫秒 | |
souceType | number | 否 | 来源类型,如果是面板进来的自动连接,输入 1;否则默认 0,为主动连接 | |
connectType | number | 否 | 蓝牙连接方式,默认 0。0:网关和 app 都需要,默认值,本地和网关两个途径任何一个可用均可生效。1:仅 app,只会判定本地是否在线,以及本地连接是否成功。2:仅网关连接,只会判定网关是否在线,以及坚持网关连接是否成功 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 |
函数定义示例
/**
* 蓝牙连接
*聚合接口,Bluetooth LE、双模中 Bluetooth LE、Beacon、Mesh、Mesh 单火类连接。
*/
export function connectBluetoothDevice(params: {
/** 设备 ID */
devId: string;
/**
* 连接超时时限
* 单位: 毫秒
*/
timeoutMillis?: number;
/**
* 来源类型
* 如果是面板进来的自动连接, 输入 1; 否则,默认 0,为主动连接
*/
souceType?: number;
/**
* 蓝牙连接方式,默认0
* 0:网关和 app 都需要,默认值,本地和网关两个途径任何一个可用均可生效
* 1:仅 app,只会判定本地是否在线,以及本地连接是否成功
* 2:仅网关连接,只会判定网关是否在线,以及坚持网关连接是否成功
*/
connectType?: number;
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: () => void;
/** 接口调用成功的回调函数 */
success?: (params: null) => void;
/** 接口调用失败的回调函数 */
fail?: (params: {
errorMsg: string;
errorCode: string | number;
innerError: {
errorCode: string | number;
errorMsg: string;
};
}) => void;
}): void;
👉 立即免费领取开发资源,体验涂鸦 MiniApp 小程序开发。
disconnectBluetoothDevice
蓝牙断开连接
聚合接口, 支持 Bluetooth LE、双模中的 Bluetooth LE、Mesh 单火类以及 Mesh 连接断开。Beacon 设备调用无效。
引入
import { disconnectBluetoothDevice } from '@ray-js/ray';
需引入
DeviceKit
,且在>=3.1.0
版本才可使用。
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
devId | string | 是 | 设备 ID | |
connectType | number | 否 | 蓝牙连接方式,默认 0。0:网关和 app 都需要,默认值,本地和网关两个途径任何一个可用均可生效。1:仅 app,只会判定本地是否在线,以及本地连接是否成功。2:仅网关连接,只会判定网关是否在线,以及坚持网关连接是否成功 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 |
函数定义示例
/**
* 蓝牙断开连接
*聚合接口,支持 Bluetooth LE、双模中的 Bluetooth LE、Mesh 单火类以及 Mesh连接断开。Beacon 设备调用无效。
*/
export function disconnectBluetoothDevice(params: {
/** 设备 ID */
devId: string;
/**
* 蓝牙连接方式,默认 0
* 0:网关和 app 都需要,默认值,本地和网关两个途径任何一个可用均可生效
* 1:仅 app,只会判定本地是否在线,以及本地连接是否成功
* 2:仅网关连接,只会判定网关是否在线,以及坚持网关连接是否成功
*/
connectType?: number;
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: () => void;
/** 接口调用成功的回调函数 */
success?: (params: null) => void;
/** 接口调用失败的回调函数 */
fail?: (params: {
errorMsg: string;
errorCode: string | number;
innerError: {
errorCode: string | number;
errorMsg: string;
};
}) => void;
}): void;
👉 立即免费领取开发资源,体验涂鸦 MiniApp 小程序开发。