expo-ble模块测试demo 联调BLE模块 take 4 添加MTU设置和log
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {BleManager, Device, Characteristic, BleError as PlxError, ScanOptions} from 'react-native-ble-plx';
|
||||
import {Platform, PermissionsAndroid} from 'react-native';
|
||||
import {BleDevice, ConnectionState, BleError, ScanResult} from './types';
|
||||
import {BLE_UUIDS} from "@/ble";
|
||||
|
||||
export class BleClient {
|
||||
private static instance: BleClient;
|
||||
@@ -90,7 +91,8 @@ export class BleClient {
|
||||
if (!this.manager) throw new Error('BLE not supported on web');
|
||||
try {
|
||||
this.emit('connectionStateChange', {deviceId, state: ConnectionState.CONNECTING});
|
||||
const device = await this.manager.connectToDevice(deviceId);
|
||||
const device = await this.manager.connectToDevice(deviceId, {requestMTU: BLE_UUIDS.REQUEST_MTU});
|
||||
console.log("Connected to device with MTU = ", device.mtu);
|
||||
this.connectedDevice = await device.discoverAllServicesAndCharacteristics();
|
||||
this.emit('connectionStateChange', {deviceId, state: ConnectionState.CONNECTED});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user