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});
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ export const BLE_UUIDS = {
|
||||
BROADCAST_CHARACTERISTIC: "000002c1-0000-1000-8000-00805f9b34fb",
|
||||
WRITE_CHARACTERISTIC: '000002c5-0000-1000-8000-00805f9b34fb',
|
||||
READ_CHARACTERISTIC: '000002c6-0000-1000-8000-00805f9b34fb',
|
||||
REQUEST_MTU: 517,
|
||||
} as const;
|
||||
|
||||
export const FRAME_CONSTANTS = {
|
||||
|
||||
Reference in New Issue
Block a user