Android Question Bluetooth Text format.

Luciano Veneziano

Active Member
Licensed User
Longtime User
Hello everyone.
I would like to replace the keyboard and display on a machine with arduino using bluetooth HC-05.
I was able to connect and communicate in both directions, with no problems between programs
terminal on the mobile phone and the arduino. I started writing an app with B4A the only stumbling block is that the transmission format
and the receiving one do not coincide. When I send (from the phone) the string "AAA" is actually transmitted (in bytes)
03 00 00 00 65 65 65, when should I transmit 65 65 65 0D 0A.
I think there is an alternative way to initialize in BT on the phone side or else the send routine is not
appropriate.
I thank you all.
 

emexes

Expert
Licensed User
Your logged data looks like the first four bytes are a 32-bit count of the number of bytes following, which makes me think you are using "prefix" mode of AsyncStreams:

1642323622659.png


and if you change from .InitializePrefix to just plain old boring .Initialize, it might operate more like you expect it to.
 
Upvote 0

emexes

Expert
Licensed User
Note that if you don't use prefix mode, then packets might be split up, eg you do one call to send 65 65 65 0D 0A, but the other end gets two receive events, the first being say 65 65 and the second being the remaining 65 0D 0A.

Might not matter for your use case, where presumably the bytes (keyboard scan codes?) are handled one-at-a-time.
 
Upvote 0
Top