Android Question Bluetooth Receives Once Only

rodmcm

Active Member
Licensed User
I am sending a small number of bytes via Bluetooth to a B4a App. The app connects okay, but I only can log the first set of readings sent after the BT connection, yet the sending item (ESP32) is sending data every 5 seconds. I have tested the sending end to the HC05 app with no problems. Can anyone spot why I do not see the subsequent readings?
 

Attachments

  • Play-B4A.zip
    16.2 KB · Views: 175

rodmcm

Active Member
Licensed User
Well, I changed from Prefix Mode ( 20 bytes) to ordinary and found that the data stream to Buffer() was initially 20 bytes and then 1 and 19 for subsequent reads... Don't know why. So B4a works, but either send or reception of BT is dodgy. Any ideas?
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Hi Rod,

when you work with streams, there's no guarantee that what is sent as a block (if I understood correctly, the 20 bytes) will always be received as such, even if with some devices it works this way.

Probably, (or at least the reception must be prepared for it) it will be received in more than one event, so you should provide a way (a timeout and/or some sort of frame delimiter) to re-build valid frames on a separate buffer based on the received fragments and known rules (fixed length, minimum time distance between frames, known bytes at the beginning/end, ...)
 
Upvote 0
Top