expo-ble模块测试demo 联调BLE模块 take 7 尝试二次设置MTU=512

This commit is contained in:
Yudi Xiao 2025-12-11 12:45:27 +08:00
parent 9100a20a2d
commit b612335d95
1 changed files with 8 additions and 1 deletions

View File

@ -91,7 +91,14 @@ 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, {requestMTU: BLE_UUIDS.REQUEST_MTU});
let device = await this.manager.connectToDevice(deviceId, {
autoConnect: false,
requestMTU: BLE_UUIDS.REQUEST_MTU
});
if (device.mtu !== BLE_UUIDS.REQUEST_MTU) {
console.log("MTU not supported, requesting default to ", BLE_UUIDS.REQUEST_MTU);
device = await device.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});