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.

startNotification doesn't enable NOTIFY property

See original GitHub issue

Version

Tell us which versions you are using:

  • react-native-ble-manager v6.2.6
  • react-native v0.53.0
  • Android 7.0

Expected behaviour

When calling startNotification, as i can see from the native code (Android in particular, but i hope also iOS), the library should enable the NOTIFY char configuration descriptor value to 1 so the BLE device will start notifying data.

Actual behaviour

This doesn’t happen, and the BLE device stays with NOTIFY set to 0. If we enable first notify via another app then it works as it is already enabled.

Steps to reproduce

  1. Connect to BLE device, retrieve services, make sure Notify is disabled by default in ble device
  2. Call startNotification on any service/char which has notify disabled by default
  3. No notifications incoming

Stack trace and console log

No error is thrown, no stacktrace either

Hope to get some help, thanks in advance!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Girumcommented, Nov 29, 2020

If someone if still interested in this issue, here is a sample to enable multiple notifications on Android.

async startNotifications(deviceID) {
  try {
    await BleManager.startNotification(deviceID, ServiceDemo, Characteristic1);
    await BleManager.startNotification(device.id, ServiceDemo, Characteristic2);
    await BleManager.startNotification(device.id, ServiceDemo, Characteristic3);
  } catch (error) {
    warn('Could not start notifications for all characteristics:', error);
    // don't forget to throw the error again to reject the promise
    throw error;
  }
}

If you want to use the then style, you can do this instead.

startNotifications(deviceID) {
  return BleManager.startNotification(deviceID, ServiceDemo, Characteristic1)
    .then(() => BleManager.startNotification(deviceID, ServiceDemo, Characteristic2))
    .then(() => BleManager.startNotification(deviceID, ServiceDemo, Characteristic3))
    .catch(error => {
      warn('Could not start notifications for all characteristics:', error);
      // don't forget to throw the error again to reject the promise
      throw error;
    });
}

Hi! How can you render the notification data in the screen without load and "freeze"the screen because the re-render?

0reactions
drash-coursecommented, Nov 8, 2018

If someone if still interested in this issue, here is a sample to enable multiple notifications on Android.

async startNotifications(deviceID) {
  try {
    await BleManager.startNotification(deviceID, ServiceDemo, Characteristic1);
    await BleManager.startNotification(device.id, ServiceDemo, Characteristic2);
    await BleManager.startNotification(device.id, ServiceDemo, Characteristic3);
  } catch (error) {
    warn('Could not start notifications for all characteristics:', error);
    // don't forget to throw the error again to reject the promise
    throw error;
  }
}

If you want to use the then style, you can do this instead.

startNotifications(deviceID) {
  return BleManager.startNotification(deviceID, ServiceDemo, Characteristic1)
    .then(() => BleManager.startNotification(deviceID, ServiceDemo, Characteristic2))
    .then(() => BleManager.startNotification(deviceID, ServiceDemo, Characteristic3))
    .catch(error => {
      warn('Could not start notifications for all characteristics:', error);
      // don't forget to throw the error again to reject the promise
      throw error;
    });
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

ble.startNotification not working - Ionic Framework
I am using this library: import { BLE } from '@awesome-cordova-plugins/ble/ngx';. I am able to connect to my bluetooth remote and to get...
Read more >
Web BLE Characteristic startNotifications sometimes doesn't ...
I have based my code according to the example of the heart rate measurement. Everything is working fine most of the time. But...
Read more >
Notifications not received - Infineon Developer Community
I'm making a simple project with a custom characteristic (with read, write and notify properties enabled) where I can modify a uint8 value....
Read more >
Create a Notification - Android Developers
Notifications provide short, timely information about events in your app while it's not in use. This page teaches you how to create a...
Read more >
Calling startNotifications() and getting "GATT Error
You also need a CCC Descriptor for notifications to be enabled. ... were optional and that the "Notify" Property of the characteristic itself...
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