From 1689fff721a7d0ffe3f9d21f08da05f3457618eb Mon Sep 17 00:00:00 2001 From: Yudi Xiao <463708580@qq.com> Date: Thu, 11 Dec 2025 12:23:26 +0800 Subject: [PATCH] =?UTF-8?q?expo-ble=E6=A8=A1=E5=9D=97=E6=B5=8B=E8=AF=95dem?= =?UTF-8?q?o=20=E8=81=94=E8=B0=83BLE=E6=A8=A1=E5=9D=97=20take=204=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0MTU=E8=AE=BE=E7=BD=AE=E5=92=8Clog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 18 +++++++++++++++++- ble/core/BleClient.ts | 4 +++- ble/protocol/Constants.ts | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index df7326a..33bd40b 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,26 @@ 安装 bun https://bun.com/docs/installation#windows -```bash +```powershell powershell -c "irm bun.sh/install.ps1|iex" ``` +检查bun是否正确安装 + +```powershell +& "$env:USERPROFILE\.bun\bin\bun" --version +``` + +添加bun到系统路径 + +```powershell +[System.Environment]::SetEnvironmentVariable( + "Path", + [System.Environment]::GetEnvironmentVariable("Path", "User") + ";$env:USERPROFILE\.bun\bin", + [System.EnvironmentVariableTarget]::User +) +``` + 安装项目依赖 ```bash diff --git a/ble/core/BleClient.ts b/ble/core/BleClient.ts index 1aea076..f72a540 100644 --- a/ble/core/BleClient.ts +++ b/ble/core/BleClient.ts @@ -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}); diff --git a/ble/protocol/Constants.ts b/ble/protocol/Constants.ts index 95b07ca..7a917b7 100644 --- a/ble/protocol/Constants.ts +++ b/ble/protocol/Constants.ts @@ -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 = {