DFRobot / BlunoBasicDemo

The basic demo for bluno
GNU General Public License v3.0
166 stars 233 forks source link

onSerialReceived not taking complete Serial Data #10

Closed nmakes closed 7 years ago

nmakes commented 7 years ago

Hi!

This is regarding the onSerialReceive(String theString) function, in MainActivity.

I am using a Bluno Beetle to take readings from a PPG sensor and sending the comma separated raw values over bluetooth to an Android App.

However, if I send 20 values (by appending them in a comma separated string), I receive only 5 values in one execution of the function onSerialReceive.

For eg.

If I send the following from Bluno Beetle:

"231,511,231,524,231,522,231,525,231,513,506,230,509,230,515,522,231,525,231,513"

I receive the following theString values in 4 consecutive executions of the function:

"231,511,231,524,231" ",522,231,525,231,513" ",506,230,509,230,515" ",522,231,525,231,513"

I do not receive the complete string in a go.

Debugging this is a little urgent, so I request you to kindly reply soon. Let me know if you need more information to help me out with this.

Thanks!

yurik94 commented 7 years ago

Buffering/max characteristic length ?

nmakes commented 7 years ago

Hey @yurik94 !

The issue was solved. It turned out that, changing the characteristic length did not help. Each packet is still restricted to 20 bytes (Bluetooth specifications), and the string passed to this function is one packet.

To solve it without hampering the library's architecture, I had to implement an additional, synchronous layer of buffer. The onSerialReceived function would would append the received string into the buffer. I wrote another thread which would run synchronously (with mutex lock applied on this additional layer of buffer), tokenize the buffer and pop out values. Basically, implementing a producer - consumer model.