Getting "value": null while trying to react data using characteristicsForService() function with react-native-ble-plx

20 views Asked by At

I am trying to read data from the connected BLE device using react-native-ble-plx. I am using characteristicsForService() function to read the data but the value comes as null. Here is my code:

 const connectToDevice = async (device: Device) => {
        try {
            const deviceConnection = await bleManager.connectToDevice(device.id);
            // setConnectedDevice(deviceConnection);
            await deviceConnection.discoverAllServicesAndCharacteristics(device.id);
            const services = await deviceConnection.services();
            console.log('Discovered services:', services[1].characteristics());

            for (const service of services) {
                const characteristics = await service.characteristics();
                console.log(`Characteristics for service ${service.id}:`, characteristics);
            }

            const heartRateCharacteristic = await deviceConnection.characteristicsForService(
                SERVICE_UUID,
            );
            console.log('Read Characteristic:', heartRateCharacteristic);
            bleManager.stopDeviceScan();
            startStreamingData(deviceConnection);
        } catch (e) {
            console.log('FAILED TO CONNECT', e);
        }
    };

currently I am trying to read data from my heart rate device and display the heart rate but I get the value as null like this:

Characteristics for service 97: [{"_manager": {"_activePromises": [Object], "_activeSubscriptions": [Object], "_errorCodesToMessagesMapping": [Object], "_eventEmitter": [NativeEventEmitter], "_scanEventSubscription": [Object], "_uniqueId": 17}, "deviceID": "D5:78:52:94:83:6B", "id": 98, "isIndicatable": false, "isNotifiable": true, "isNotifying": false, "isReadable": true, "isWritableWithResponse": true, "isWritableWithoutResponse": false, "serviceID": 97, "serviceUUID": "00003802-0000-1000-8000-00805f9b34fb", "uuid": "00004a02-0000-1000-8000-00805f9b34fb", "value": null}

Can anyone find the issue?

0

There are 0 answers