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.

Reading data from ble device after writing

See original GitHub issue

Version

  • react-native-ble-manager v6.5.1
  • react-native v0.57.4
  • Android

Hi

Our ble device HM10 bluetooth 4.0 runing on a custom electronic card . When i writing data to device, card returning me data. but i can’t read that data .We tested it with BLE Scanner app it is on the apple store and its working perfectly. BLE Scanner getting data what we should to see. I’ve tried to use read() function after write function but read function returning me something strange. How can i do this and what am i doing wrong

This is my console after writing and reading.

Peripheral is connected
Writed :  566666
ReadData:  Ô69ØCT

This is my code

 bleManagerEmitter.addListener(
      'BleManagerConnectPeripheral',
      (device) => {
        BleManager.isPeripheralConnected(device.peripheral, [])
          .then((isConnected) => {
            if (isConnected) {
              console.log('Peripheral is connected')
              BleManager.retrieveServices(device.peripheral)
                .then((peripheralDevice) => {
                  let service = peripheralDevice.characteristics[6].service
                  let characteristic = peripheralDevice.characteristics[6].characteristic
                  this.write(this.state.message, device, service, characteristic)
                })
            } else {
              console.log('Peripheral is NOT connecteddd!');
            }
          })
      })


write(message, device, service, characteristic) {

    let byteMsg = stringToBytes(message);
    BleManager.write(device.peripheral, service, characteristic, byteMsg)
      .then(() => {
        console.log('Writed : ', message)
        BleManager.read(device.peripheral, service, characteristic, byteMsg)
          .then((readData) => {
            this.setState({ connecting: false, connectingId: null, writedId: device.peripheral, writeErrorDeviceId: null }, () => {
              let readedData = bytesToString(readData)
              console.log('ReadData: ', readedData)
              this.disconnect(device.peripheral)
            })
          }).catch((err) => console.log(err))
      }).catch((err) => {
        console.log(err, " Error Write")
        this.setState({ connecting: false, connectingId: null, writedId: null, writeErrorDeviceId: device.peripheral })
        this.disconnect(device.peripheral)

      })

  }

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
MrDockalcommented, Nov 21, 2018

Hi @KayhanB in order to get an understanding of the BLE communication, I would recommend you to go through these posts Very nice explained here This medium post is more about programming Download the starter kit, which contains more theory

If you want to check your peripheral profiles, services and characteristics I would recommend you to use nRF Connect for android

Hope it helps you to get the problem solved.

0reactions
malikowaisghafoorcommented, Jun 13, 2020

Do you have any idea how I can see BLE SCANNER data on run time in any Android device?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Write data to BLE device and read its response flutter?
I am writing ASCII encoded string to the Characteristic. The problem arises when its time to decode the data back. Exact data is...
Read more >
MagicLight Bulb Color Mixer with Circuit Playground Bluefruit
A good way to get familiar with BLE is to read and write to individual Characteristics using the Nordic nRF Connect app for...
Read more >
Transfer BLE data - Android Developers
The first thing to do once you connect to the GATT Server on the BLE device is to perform service discovery. This provides...
Read more >
How to Read BLE Characteristics in Swift - QuickBird Studios
The ultimate guide for decoding characteristics' raw data received from Bluetooth Low Energy devices to meaningful Swift types.
Read more >
Reading Data From Wearable BLE Device - NI Community
Finally was able to get the data by the following method: -Disable Firewall and/or Antivirus. ... Getting Device Address: -Query or enter the ......
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