Bluetooth connecting status

While I can click the image and connect to Bluetooth just fine, I wanted to add an intermediate image showing that Bluetooth is attempting to connect:



The idea is when BT is off, the image shows a diconnected status:

Then when it is trying to connect, it shows connecting status;

Then after a successful connection;

My problem is after clicking the image, the flow goes straight to trying to connect and it will either connect and show the proper connection status or the error block will display the "not connected" status. I never see the "Connecting" status.
Any ideas?

It could be that it is just connecting very fast, if you want to add an intentional delay for UI purposes try using the "clock" component and waiting 1 - 3 seconds. Then afterward call the bluetooth connect function. If this doesn't help your UI then try finding someone else

Clock Settings

Screenshot 2025-12-04 10.00.06 AM

timer code

From the time I click the connect button (image), there is already a delay before it connects. This delay is about 4 seconds- lots of time to display a "connecting" image. I just don't understand why it's skipping the image loading.

I even tried this hoping to wait for the image to load before moving on but it made no difference:

Can you send me the .aia? I'll try to help the best I can.

Blocks run on the app's main thread, so until an entire block stack completes (e.g., when imgWelcome_BT.Click) nothing UI related takes effect. This is important because the BluetoothClient1.Connect block is synchronous, so your code will pause at that point until the block either returns true or false. No UI updates will happen until later, so setting the Picture to bluetooth-connecting.png is overridden by setting it to bluetooth-enabled.png within the function.

To achieve what you want you want, you'd have to have something like a Clock with an interval of 1. Set it to enabled when the button is clicked, and in the Timer function (currently your ConnectBluetooth logic), disable the clock again and then run your logic. If the Connect block takes 5 seconds at the point it should be fine because the UI would have updated when the Click event was exited but before the clock's timer fires.

(added to FAQ)

(added to FAQ)

As Evan and the other Power Users have said, once a "block" has started its execution, it lasts until it has finished. The annexed .aia shows you (in a very simple way) how to allow a label to show "Connection in progress" while the BT client is attemping to connect.
This is obtained by launching a clock that allows some 500 milliseconds before effectively starting the connection attempt.
Of course you can eleborate it as per your needs, but the "trick" is to start the Connection only after a while since the last preceding block (in my case, the Text setting of the 'Status' label).
Hoping it can help.
BLUETOOTH_Connection.aia (3.1 KB)

Tested with a Lenovo pad, running Android 9 and an Arduino Uno + HC06 Classic BT shield.

EDIT: :weary:ooops I realized only now that a similar solution has been already suggested before. Then, what I can think about is probably that to show a picture is a long lasting operation, while just setting a text of a label is much faster. Therefore a 500 ms delay between the Connect button is pressed and the Connection attempt is started is enough....

EDIT 2

This does not wait for the image to be loaded, but just assigns the name of the image, so in a few microseconds the equality is set to true. Therefore no delay applies... :thinking:

EDIT 3:
the following .aia shows also a (sample) picture while connecting...(and hides it after the connection, or the timeout in case of connection failure)
BLUETOOTH_Connection (1).aia (42.4 KB)

1 Like

Ahh! I didn't know this but it certainly makes sense of the behavior I'm seeing. Here's what works well:


Thanks for this and thank you to everyone else as well who offered their help and solutions!

These details enhance the BuzzBot!

Thank you. Yes, your code is very good. Do you ever need to perform several retries when implementing a connection? I may try this because sometimes it won't connect on one button press.

Honestly really a very few times the connection didn't work at the first time. In those cases the cause was a not enabled BT line (at Android level) or a permission not yet granted, or a BT address incorrect...or switched off at server level.
Anyway, typically, in the connection procedure I try twice the connection by means of a while loop: i.e. if the first attempt returns false, a trial counter is incremented; if the counter reaches 2, then the while loop exits, issuing a definitive error message.
Of course the limit can be as great as you want, but typically if at the second attempt it doesn't connect, this means that you have to investigate for something else. :smirk:
All the best !

+...