diff --git a/uni/basic.js b/uni/basic.js index cae8c1e..3d5ea52 100644 --- a/uni/basic.js +++ b/uni/basic.js @@ -49,6 +49,18 @@ export function searchAndConnectDevice(name, reset = true) { } break } + if (uuid && uuid.slice(0, 2) === '75') { + await stopBluetoothDevicesDiscovery() + clearTimeout(timeoutTimer) + clearInterval(timer) + if (uuid.slice(4, 6) === '00' && reset) { + resolve(Result.DeviceHasBeenReset) + } else { + const connectResult = await createBLEConnection(deviceList[i].deviceId) + resolve(connectResult) + } + break + } } } } else { @@ -177,6 +189,25 @@ export function createBLEConnection(deviceId, reconnectNumber = 0) { res.data.serviceId, res.data.notifyCharacteristicId ) + // 使用同步方法获取系统信息 + const systemInfo = uni.getSystemInfoSync(); + + if (systemInfo.platform === 'android') { + // 如果是Android机型,则设置BLE MTU + uni.setBLEMTU({ + deviceId: deviceId, + mtu: 512, + fail: res => { + console.log('mtu fail', res); + }, + success: res => { + console.log('mtu success', res); + } + }); + } else { + // 对于非Android设备,可以在这里添加其他逻辑或者直接忽略 + console.log('当前设备不是Android,跳过设置BLE MTU'); + } resolve(res) }, async fail(err) {