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.

Hang up at await BleManager.retrieveServices()

See original GitHub issue

Version

react-native-ble-manager v ^6.4.0 react-native v 0.55.4 iOS/Android v 10.3/8.0

Actual behaviour

Hang up at ### await BleManager.retrieveServices() after connected successful.

async function connectAndPrepare(peripheral, data_wr) 
{
  // Before startNotification you need to call retrieveServices
  await BleManager.retrieveServices(peripheral.id).then((peripheralInfo) => {
        console.log("retrieveServices",peripheralInfo);
        }); 
  // To enable BleManagerDidUpdateValueForCharacteristic listener
  await BleManager.startNotification(peripheral.id, service, characteristic).then(() => {
            console.log('Started notification on ' + peripheral.id);
        });    
  await BleManager.write(peripheral.id, service, characteristic, data_wr).then(() => {
                console.log('Write to peripheral');
        });
}

Stop without any error log… Any idea?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
marcosinigagliacommented, Nov 7, 2018

I don’t know if you can use ‘await’ and ‘then’ in an async function.

0reactions
pkyeckcommented, Jan 25, 2019

rewrite that as

async function connectAndPrepare(peripheral, data_wr) 
{
  try {
    // Before startNotification you need to call retrieveServices
    const peripheralInfo = await BleManager.retrieveServices(peripheral.id);
    console.log("retrieveServices",peripheralInfo);
    
    // To enable BleManagerDidUpdateValueForCharacteristic listener
    await BleManager.startNotification(peripheral.id, service, characteristic);
    console.log('Started notification on ' + peripheral.id);

    await BleManager.write(peripheral.id, service, characteristic, data_wr);
    console.log('Write to peripheral');
  } catch(err) {
    console.error(err);
  }
}

so then at least you get errors when something goes wrong

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript react-native-ble-manager retrieveServices Examples
These are the top rated real world JavaScript examples of react-native-ble-manager.retrieveServices extracted from open source projects.
Read more >
How to use the react-native-ble-manager ... - Snyk
To help you get started, we've selected a few react-native-ble-manager examples, based on popular ways it is used in public projects.
Read more >
React Native BLE Manager (Android) status code 14 on write ...
I'm using the react native ble manager package to build a react ... retrieveServices(peripheralID) } catch (error) { reject() } if (this.
Read more >
react-native-ble-manager - npm
Start the notification on the specified characteristic, you need to call retrieveServices method before. Returns a Promise object. Arguments.
Read more >
React-native-ble-manager - npm.io
Start the notification on the specified characteristic, you need to call retrieveServices method before. Returns a Promise object. Arguments. peripheralId - ...
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