douglasjunior / AndroidBluetoothLibrary

A Library for easy implementation of Serial Bluetooth Classic and Low Energy on Android. 💙
MIT License
224 stars 68 forks source link

Does it have any code to read back from the device ?...I can write using the bluetoothwriter but a reverse functionality does'nt seem to be available. #34

Closed faizanmir closed 5 years ago

faizanmir commented 5 years ago

Hi, I have used your library in one of my projects and seems to work fine except for one part , i dont seem to have any control with the data sent back from the BLE device ...

douglasjunior commented 5 years ago

Hi @faizanmir , you need to control the received data with characterDelimiter and bufferSize.

faizanmir commented 5 years ago

HI douglas ,Thanks for your prompt reply ,I am pretty new to android as well as ble ,Your library seems to simplify the otherwise tedious task of making the bluetooth connection ...Could your please point me to an implementation of the same ...that would be so much more helpful....

faizanmir commented 5 years ago

I can see that there is a an over ridden method OnDataRead ....is this where the data that is read from the device can be accessed ...sorry for being such a noob

douglasjunior commented 5 years ago

The library will retains the received data until find a characterDelimiter or fill the bufferSize. Then, the library will call the onDataRead listener.

faizanmir commented 5 years ago

could you please point me towards a resource for the characterDelimiter ,I cant seem to find much about it ,Your help is appreciated

faizanmir commented 5 years ago

I am able to see the data back in logs but not in dataread

douglasjunior commented 5 years ago

You need to find a pattern in the data received from your device.

For example, if your data received is something like this:

1;some value;234;other valeu
2;some value;567;other valeu
3;some value;901;other valeu

And you specify the 'break line' \n as the characterDelimiter, then the onDataRead will receive:

If you specify the ; as the characterDelimiter:

faizanmir commented 5 years ago

V/BluetoothLeService: onCharacteristicChanged: " av,9,,NOCON,~ " is the data I receive however if I try to access the OnDataRecieved in the library nothing shows ....even in the logs ....

faizanmir commented 5 years ago

TYSM i decreased the size of buffer and got the data ....tysm for your help

douglasjunior commented 5 years ago

The ~ indicated the end of the data? If yes, you can use ~ as the characterDelimiter.