Bluetooth example - missing/bad characters

headingwest

Member
Licensed User
Longtime User
Hi,

I'm stuck with Bluetooth using the official Bluetooth with Asynchstreams example.

The device I connect to uses Arduino and responds over BT by sending back the characters that it receives.

The only change I've made to the demo is to change Astream.Initializeprefix to Astream.Initialize.

If I send "1234567890" I get back:
1
23467
8'?

or maybe I get back:
1
23467
80

or maybe:
1
23456
p???

So it seems that about half of the characters come back, but some are missing or garbled.

But if I use an app called "Bluetooth Viewer" it all works fine. So it's definitely coming from the VB4A end.

Any ideas?
 

KitCarlson

Active Member
Licensed User
Longtime User
It works correctly. The data handling must combine, since it comes in parts. I add to buffer, check if complete, then process, or keep adding. The data that is processed, is removed from buffer. I find it very reliable.
 
Upvote 0

raphael75

Active Member
Licensed User
Longtime User
So it seems that about half of the characters come back, but some are missing or garbled.

Maybe there are two data streams open at the same time.
You can try to put following code before Astream.Initialize:

B4X:
If Astream.IsInitialized Then Astream.Close
 
Upvote 0
Top