question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Device was Disconnected - monitorCharacteristicForService

See original GitHub issue

Prerequisites

  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed

Expected Behavior

Monitoring a characteristic for notifications, should receive the notifications.

Current Behavior

Receive an error that is not very detailed, I tried adding logs to the java code, to see what happens and where. This is as far as I’ve come:

In BleModule.java, the function “safeMonitorCharacteristicForDevice”, the setupMode is set to “QUICK_SETUP”, and it setup a notification (

if ((properties & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0) {
                    Log.e("BleModule", "[safeMonitorCharacteristicForDevice] setupNotification");
                    return connection.setupNotification(gattCharacteristic, setupMode);
}

And the error function gets invoked:

@Override
public void onError(Throwable e) {
                        Log.e("BleModule", "[safeMonitorCharacteristicForDevice] onError error toString: " + e.toString());
                        Log.e("BleModule", "[safeMonitorCharacteristicForDevice] onError error message: " + e.getMessage());
                        errorConverter.toError(e).reject(promise);
                        transactions.removeSubscription(transactionId);
}

The Log.e produce the following:

E/BleModule: [safeMonitorCharacteristicForDevice] setup mode: Quick Setup
E/BleModule: [safeMonitorCharacteristicForDevice] setupNotification
E/BleModule: [safeMonitorCharacteristicForDevice] onError error toString: com.polidea.rxandroidble.exceptions.BleDisconnectedException: Disconnected from .... with status 0 (GATT_SUCCESS)
E/BleModule: [safeMonitorCharacteristicForDevice] onError error message: Disconnected from .... with status 0 (GATT_SUCCESS)

Where “…” is a unique device ID.

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. writeCharacteristicWithoutResponseForService for the RECORD_ACCESS_CONTROL_POINT, with the byte values [1, 1], encoded in Base64 format.
  2. monitorCharacteristicForService for the Glucose Measurement (00002A18) and Glucose Measurement Context (00002A34) characteristic.
  3. Experience the error.

Context

  • Library version: “react-native-ble-plx”: “^1.0.3”
  • Platform: Android

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12

github_iconTop GitHub Comments

2reactions
tymoxxcommented, Nov 12, 2021

@harguus I put setInterval inside the connect() function. Here is a simplified code. Your code will be different depending on how you connect to your device:


async connect(id) {
            const device = await deviceManager.connectToDevice(id);
            const discoveredDevice = await device.discoverAllServicesAndCharacteristics();

            /* Sync periodically - to keep device connected*/
            const interval = setInterval(function () {
                const value = 'your_value'; // in my case, I synchronize time between the app and device. But you can do anything - it's just to keep the device connected.
                discoveredDevice.writeCharacteristicWithResponseForService(SERVICE_UUID, WRITE_CHARACTERISTIC_UUID, value);
            }, 40000);
            dispatch(saveInterval(interval)); // I also save the instance of the interval to the state, so I can do clearInterval later.
}
1reaction
tymoxxcommented, Jul 18, 2021

@joaovitorqueiroz In my case, the device was disconnecting after 45 seconds. So I added setInterval to do writeCharacteristicWithoutResponseForService every 40 seconds(which just gets the status of the device). And it keeps the device connected.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotintent/react-native-ble-plx - Device was Disconnected
Prerequisites I am running the latest version I checked the documentation and found no answer I checked to make sure that this issue...
Read more >
RxBLELibraries/react-native-ble - Gitter
Hi, I'm facing same problem as @pride7 I'm not able to send data through my Bluetooth device. After connection I do : device....
Read more >
react-native-ble-plx 2.0.2 | Documentation
Connecting and discovering services and characteristics. Once device is scanned it is in disconnected state. We need to connect to it and discover...
Read more >
cant subscribe to a ble service with react native ble-plx
new here. I am trying to write an app which pulls data from an ESP32 ble device. I am using the ble-plx library....
Read more >
react-native-ble-plx - npm
Monitors if device was disconnected due to any errors or connection ... monitorCharacteristicForService(serviceUUID, characteristicUUID ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found