diff --git a/example/src/screens/MainStack/DeviceConnectDisconnectTestScreen/DeviceConnectDisconnectTestScreen.tsx b/example/src/screens/MainStack/DeviceConnectDisconnectTestScreen/DeviceConnectDisconnectTestScreen.tsx index 2224e261..c5606d28 100644 --- a/example/src/screens/MainStack/DeviceConnectDisconnectTestScreen/DeviceConnectDisconnectTestScreen.tsx +++ b/example/src/screens/MainStack/DeviceConnectDisconnectTestScreen/DeviceConnectDisconnectTestScreen.tsx @@ -58,7 +58,7 @@ export function DeviceConnectDisconnectTestScreen(_props: DeviceConnectDisconnec setTimeoutTestState('IN_PROGRESS') try { - await BLEService.connectToDevice(device.id, CONNECTION_TIMEOUT) + await BLEService.connectToDevice(device.id, CONNECTION_TIMEOUT, true) setTimeoutTestState('ERROR') setTimeoutTestLabel('Device was able to connect') } catch (error) { @@ -66,7 +66,6 @@ export function DeviceConnectDisconnectTestScreen(_props: DeviceConnectDisconnec error instanceof Error && (error.message === 'Operation was cancelled' || error.message === 'Operation timed out') ) { - console.info('Timeout test successful: Connection timed out as expected') setTimeoutTestState('DONE') setTimeoutTestLabel('Success') } else { diff --git a/example/src/screens/MainStack/DevicenRFTestScreen/DevicenRFTestScreen.tsx b/example/src/screens/MainStack/DevicenRFTestScreen/DevicenRFTestScreen.tsx index 57938256..e0330586 100644 --- a/example/src/screens/MainStack/DevicenRFTestScreen/DevicenRFTestScreen.tsx +++ b/example/src/screens/MainStack/DevicenRFTestScreen/DevicenRFTestScreen.tsx @@ -1,7 +1,7 @@ import React, { useState, type Dispatch } from 'react' import type { NativeStackScreenProps } from '@react-navigation/native-stack' import { Device, type Base64 } from 'react-native-ble-plx' -import { Platform, ScrollView } from 'react-native' +import { Platform, ScrollView, Alert } from 'react-native' import base64 from 'react-native-base64' import type { TestStateType } from '../../../types' import { BLEService, usePersistentDeviceName } from '../../../services' @@ -18,6 +18,7 @@ import { writeWithResponseBase64Time, writeWithoutResponseBase64Time } from '../../../consts/nRFDeviceConsts' +import { isAndroidSdkAbove34 } from '../../../utils/isAndroidAbove14' type DevicenRFTestScreenProps = NativeStackScreenProps @@ -240,10 +241,23 @@ export function DevicenRFTestScreen(_props: DevicenRFTestScreenProps) { new Promise((resolve, reject) => { startTestInfo('startTestMonitorCurrentTimeCharacteristicForDevice') setTestMonitorCurrentTimeCharacteristicForDevice('IN_PROGRESS') + Alert.alert( + 'Monitor Current Time Characteristic', + `Please send the following message to the device: "${monitorExpectedMessage}"`, + [ + { + text: 'OK' + } + ] + ) BLEService.setupMonitor( deviceTimeService, currentTimeCharacteristic, async characteristic => { + console.info( + 'startTestMonitorCurrentTimeCharacteristicForDevice', + `received value: ${characteristic.value && base64.decode(characteristic.value)}, expected value: ${monitorExpectedMessage}` + ) if (characteristic.value && base64.decode(characteristic.value) === monitorExpectedMessage) { setTestMonitorCurrentTimeCharacteristicForDevice('DONE') await BLEService.finishMonitor() @@ -421,7 +435,8 @@ export function DevicenRFTestScreen(_props: DevicenRFTestScreenProps) { runTest(getConnectedDevices, setTestConnectedDevicesState, 'startGetConnectedDevices') const startRequestMTUForDevice = () => { - const expectedMTU = 40 + const expectedMTU = isAndroidSdkAbove34 ? 517 : 40 + return runTest( () => BLEService.requestMTUForDevice(expectedMTU).then(device => { diff --git a/example/src/services/BLEService/BLEService.ts b/example/src/services/BLEService/BLEService.ts index d09e3a62..093ead7e 100644 --- a/example/src/services/BLEService/BLEService.ts +++ b/example/src/services/BLEService/BLEService.ts @@ -120,7 +120,7 @@ class BLEServiceInstance { this.manager.stopDeviceScan() } - connectToDevice = (deviceId: DeviceId, timeout?: number) => + connectToDevice = (deviceId: DeviceId, timeout?: number, ignoreError = false) => new Promise((resolve, reject) => { this.manager.stopDeviceScan() this.manager @@ -133,7 +133,9 @@ class BLEServiceInstance { if (error.errorCode === BleErrorCode.DeviceAlreadyConnected && this.device) { resolve(this.device) } else { - this.onError(error) + if (!ignoreError) { + this.onError(error) + } reject(error) } }) diff --git a/example/src/utils/isAndroidAbove14.ts b/example/src/utils/isAndroidAbove14.ts new file mode 100644 index 00000000..57530046 --- /dev/null +++ b/example/src/utils/isAndroidAbove14.ts @@ -0,0 +1,3 @@ +import { Platform } from 'react-native' + +export const isAndroidSdkAbove34 = Platform.OS === 'android' && Platform.Version >= 34