Android Question bluetooth and microcontroller (STM32)

yogie

Member
Licensed User
Longtime User
Situation
- existing microcontroller with bluetooth interface and running program
- running Windows program for communication with the microcontroller (in over 100 versions in productive use), as reference
- must transfer the Windows program to an Android tablet

So far
- basics for B4A
- study of various forum contributions
- simple program in B4A for receiving bluetooth messages from the microcontroller
- using AsyncStreams; NOT in prefix mode, Detection of a complete message by scanning for LF (line feed), works.
- display of received message in stream New_Data event, works

Question
I am looking for a way from the stream New_Data event to "distribute" the received messages further to various displays, etc. Of course I can create a "case" in the
Stream New_Data event a "case" and then call various SUBs. But the problem is, that sometimes I have to wait for the answers of the microcontroller. It can take 100 ... 200 mSec until the answer arrives. Attempts with wait for ... were not really successful. I would prefer to trigger my own events, which would then be evaluated by the rest of the program. In the Windows program I use my own messages for this.

I don't expect a ready solution, but I am grateful for any hint.
 

Serge Bertet

Active Member
Licensed User
I had the same problem here between ESP32 (Wifi+BLE) and phone or tablet.
I implemented a finite state machine (with timer) and a fifo (a list) to solve this.
But maybe you problem is harder than mine.
Serge
 
Upvote 0

yogie

Member
Licensed User
Longtime User
thanks for the answer. Is in prefix mode or in no prefix mode gebeiet?

Now I am one step further, the communication with the STM32 works almost correctly.
There must be a sequence of commands to the device. I send a command and
then wait for the response. It is also a kind of state mashine, no timer.

My last command starts a permanent data output on the device. I can also receive
this output (stream) an show it als log, but then it is not possible to send a new command.
The correct place in the program is reached (seen in Log), but nothing is sent.

Furthermore I try to display the permanent data output in an EditText. But the text field
is not updated as long as the permanent data output is running.

I am open to discuss further and would also provide my (incomplete) program.
 
Upvote 0

Serge Bertet

Active Member
Licensed User
I think I will not be able to help you.
My system is working as master / slave using BLE UART or HTTP
The ESP32 is server and phone is client.
It is just a matter of question / response between the 2 devices, no stream.
What I thought, your problem is harder to solve.
 
Upvote 0
Top