Reading data from ble device after writing
See original GitHub issueVersion
- 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:
- Created 5 years ago
- Comments:8 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
Do you have any idea how I can see BLE SCANNER data on run time in any Android device?