原子操作

飞道科技

@dfeidao/atom-wxapp > api_quipment蓝牙

External module: api_quipment蓝牙

Index

Functions


Functions

close_ble_connection

close_ble_connection(deviceId: string): Promise<boolean>

Defined in api/equipment/close-ble-connection.ts:16

断开与低功耗蓝牙设备的连接。

see: 微信官方文档

example:

import close_ble_connection from '@dfeidao/atom-wxapp/api/equipment/close-ble-connection';
await close_ble_connection('a4:50:40:df:a8:45');

Parameters:

Name Type Description
deviceId string 用于区分设备的 id

Returns: Promise<boolean>


close_bluetooth_adapter

close_bluetooth_adapter(): Promise<boolean>

Defined in api/equipment/close-bluetooth-adapter.ts:16

关闭蓝牙模块。

description: 调用该原子操作将断开所有已建立的连接并释放系统资源。建议在使用蓝牙流程后,与 open-bluetooth-adapter 成对调用。

see: 微信官方文档

example:

import close_bluetooth_adapter from '@dfeidao/atom-wxapp/api/equipment/close-bluetooth-adapter';
await close_bluetooth_adapter();

Returns: Promise<boolean>


create_ble_connection

create_ble_connection(deviceId: string): Promise<boolean>

Defined in api/equipment/create-ble-connection.ts:17

连接低功耗蓝牙设备

description: 若小程序在之前已有搜索过某个蓝牙设备,并成功建立连接,可直接传入之前搜索获取的 deviceId 直接尝试连接该设备,无需进行搜索操作。

see: 微信官方文档

example:

import close_ble_connection from '@dfeidao/atom-wxapp/api/equipment/close-ble-connection';
await close_ble_connection('admin');

Parameters:

Name Type Description
deviceId string 用于区分设备的 id

Returns: Promise<boolean>


get_ble_device_characteristice

get_ble_device_characteristice(deviceId: string, serviceId: string): Promise<object>

Defined in api/equipment/get-ble-device-characteristice.ts:19

获取蓝牙设备某个服务中所有特征值(characteristic)。

see: 微信官方文档 get-ble-device-services

example:

import get_ble_device_characteristice from '@dfeidao/atom-wxapp/api/equipment/get-ble-device-characteristice';
import get_ble_device_services from '@dfeidao/atom-wxapp/api/equipment/get-ble-device-services';
const device_services = await get_ble_device_services('deviceId');
const res = await get_ble_device_characteristice('deviceId', device_services.services[0].uuid);

Parameters:

Name Type Description
deviceId string 蓝牙设备 id
serviceId string 蓝牙服务 uuid,需要使用 get-ble-device-services 获取

Returns: Promise<object>


get_ble_device_services

get_ble_device_services(deviceId: string): Promise<object>

Defined in api/equipment/get-ble-device-services.ts:16

获取蓝牙设备所有服务(service)

see: 微信官方文档

example:

import get_ble_device_services from '@dfeidao/atom-wxapp/api/equipment/get-ble-device-services';
const device_services = await get_ble_device_services('deviceId');

Parameters:

Name Type Description
deviceId string 蓝牙设备 id

Returns: Promise<object>


get_bluetooth_adapter_state

get_bluetooth_adapter_state(): Promise<BluetoothAdapterStateData>

Defined in api/equipment/get-bluetooth-adapter.ts:15

获取本机蓝牙适配器状态

see: 微信官方文档

example:

import get_bluetooth_adapter_state from '@dfeidao/atom-wxapp/api/equipment/get-bluetooth-adapter';
const res = await get_bluetooth_adapter_state();

Returns: Promise<BluetoothAdapterStateData>


get_bluetooth_devices

get_bluetooth_devices(): Promise<object>

Defined in api/equipment/get-bluetooth-devices.ts:16

获取在蓝牙模块生效期间所有已发现的蓝牙设备

description: 包括已经和本机处于连接状态的设备。

see: 微信官方文档

example:

import get_bluetooth_devices from '@dfeidao/atom-wxapp/api/equipment/get-bluetooth-devices';
const res = await get_bluetooth_devices();

Returns: Promise<object>


notify_ble_characteristic_value_change

notify_ble_characteristic_value_change(deviceId: string, serviceId: string, characteristicId: string, state: boolean): Promise<boolean>

Defined in api/equipment/notify-ble-characteristic-value-change.ts:20

启用低功耗蓝牙设备特征值变化时的 notify 功能,订阅特征值

description: 注意:必须设备的特征值支持 notify 或者 indicate 才可以成功调用。另外,必须先启用 notifyBLECharacteristicValueChange 才能监听到设备 characteristicValueChange 事件

see: 微信官方文档

example:

import notify_ble_characteristic_value_change from '@dfeidao/atom-wxapp/api/equipment/notify-ble-characteristic-value-change';
await notify_ble_characteristic_value_change('deviceId', 'serviceId', 'characteristicId', true);

Parameters:

Name Type Description
deviceId string 蓝牙设备 id
serviceId string 蓝牙特征值对应服务的 uuid
characteristicId string 蓝牙特征值的 uuid
state boolean 是否启用 notify

Returns: Promise<boolean>


on_ble_characterisitic_value_change

on_ble_characterisitic_value_change(): Promise<object>

Defined in api/equipment/on-ble-characteristic-value-change.ts:16

监听低功耗蓝牙设备的特征值变化事件

description: 必须先启用 notify-ble-characteristic-value-change 原子操作才能接收到设备推送的 notification。

see: 微信官方文档

example:

import on_ble_characterisitic_value_change from '@dfeidao/atom-wxapp/api/equipment/on-ble-characteristic-value-change';
await on_ble_characterisitic_value_change();

Returns: Promise<object>


on_ble_connection_state_change

on_ble_connection_state_change(): Promise<object>

Defined in api/equipment/on-ble-connection-state-change.ts:16

监听低功耗蓝牙连接状态的改变事件

description: 包括开发者主动连接或断开连接,设备丢失,连接异常断开等等

see: 微信官方文档

example:

import on_ble_connection_state_change from '@dfeidao/atom-wxapp/api/equipment/on-ble-connection-state-change';
await on_ble_connection_state_change();

Returns: Promise<object>


on_bluetooth_adapter_state_change

on_bluetooth_adapter_state_change(): Promise<BluetoothAdapterState>

Defined in api/equipment/on-bluetooth-adapter-state-change.ts:15

监听蓝牙适配器状态变化事件

see: 微信官方文档

example:

import on_bluetooth_adapter_state_change from '@dfeidao/atom-wxapp/api/equipment/on-bluetooth-adapter-state-change';
await on_bluetooth_adapter_state_change();

Returns: Promise<BluetoothAdapterState>


on_bluetooth_devices_found

on_bluetooth_devices_found(): Promise<object>

Defined in api/equipment/on-bluetooth-devices-found.ts:15

监听寻找到新设备的事件

see: 微信官方文档

example:

import on_bluetooth_devices_found from '@dfeidao/atom-wxapp/api/equipment/on-bluetooth-devices-found';
await on_bluetooth_devices_found();

Returns: Promise<object>


open_bluetooth_adapter

open_bluetooth_adapter(): Promise<boolean>

Defined in api/equipment/open-bluetooth-adapter.ts:15

初始化蓝牙模块

see: 微信官方文档

example:

import open_bluetooth_adapter from '@dfeidao/atom-wxapp/api/equipment/open-bluetooth-adapter';
await open_bluetooth_adapter(fd);

Returns: Promise<boolean>


read_ble_characteristic_value

read_ble_characteristic_value(deviceId: string, serviceId: string, characteristicId: string): Promise<object>

Defined in api/equipment/read-ble-characteristic-value.ts:18

读取低功耗蓝牙设备的特征值的二进制数据值

see: 微信官方文档

example:

import read_ble_characteristic_value from '@dfeidao/atom-wxapp/api/equipment/read-ble-characteristic-value';
const res = await read_ble_characteristic_value(fd);

Parameters:

Name Type Description
deviceId string 蓝牙设备 id
serviceId string 蓝牙特征值对应服务的 uuid
characteristicId string 蓝牙特征值的 uuid

Returns: Promise<object>


start_bluetooth_devices_discovery

start_bluetooth_devices_discovery(services?: string[], allowDuplicatesKey?: undefined | false | true, interval?: undefined | number): Promise<boolean>

Defined in api/equipment/start-bluetooth-devices-discovery.ts:19

开始搜寻附近的蓝牙外围设备

description: 此操作比较耗费系统资源,请在搜索并连接到设备后调用 stop-bluetooth-devices-discovery 原子操作停止搜索。

see: 微信官方文档 stop-bluetooth-devices-discovery

example:

import start_bluetooth_devices_discovery from '@dfeidao/atom-wxapp/api/equipment/start-bluetooth-devices-discovery';
const res = await start_bluetooth_devices_discovery(['services1', 'services2'], false, 0);

Parameters:

Name Type Description
Optional services string[] 是否允许重复上报同一设备, 如果允许重复上报,则onBlueToothDeviceFound 方法会多次上报同一设备,但是 RSSI 值会有不同
Optional allowDuplicatesKey undefined | false | true  
Optional interval undefined | number  

Returns: Promise<boolean>


stop_bluetooth_devices_discovery

stop_bluetooth_devices_discovery(): Promise<boolean>

Defined in api/equipment/stop-bluetooth-devices-discovery.ts:16

停止搜寻附近的蓝牙外围设备

description: 若已经找到需要的蓝牙设备并不需要继续搜索时,建议调用该原子操作停止蓝牙搜索。

see: 微信官方文档

example:

import stop_bluetooth_devices_discovery from '@dfeidao/atom-wxapp/api/equipment/stop-bluetooth-devices-discovery';
await stop_bluetooth_devices_discovery();

Returns: Promise<boolean>


write_ble_characteristic_value

write_ble_characteristic_value(deviceId: string, serviceId: string, characteristicId: string, value: ArrayBuffer): Promise<boolean>

Defined in api/equipment/write-ble-characteristic-value.ts:20

向低功耗蓝牙设备特征值中写入二进制数据

description: 注意:必须设备的特征值支持 write 才可以成功调用。

see: 微信官方文档

example:

import write_ble_characteristic_value from '@dfeidao/atom-wxapp/api/equipment/write-ble-characteristic-value';
const res = await write_ble_characteristic_value('deviceId', 'serviceId', 'characteristicId', new ArrayBuffer(1));

Parameters:

Name Type Description
deviceId string 蓝牙设备 id,参考 device 对象
serviceId string 蓝牙特征值对应服务的 uuid
characteristicId string 蓝牙特征值的 uuid
value ArrayBuffer 蓝牙设备特征值对应的二进制值

Returns: Promise<boolean>