Android Question [SOLVED]know when the BT connection is broken

cas6678

Active Member
Licensed User
Longtime User
Hi

How can I know when the BT connection is broken in order to try a new connection?

thanks
 

cas6678

Active Member
Licensed User
Longtime User
I've AsyncStreams Error and Terminated event, but when turn off the other device (broken the connection) the Subs not work.

B4X:
Sub Process_Globals
    Dim admin As BluetoothAdmin
    Dim serial1 As Serial
    Dim AStream As AsyncStreams
End Sub

Sub AStream_Error
    ToastMessageShow("Connection is broken.", True)

End Sub

Sub AStream_Terminated
    AStream_Error
End Sub
 
Upvote 0

f0raster0

Well-Known Member
Licensed User
Longtime User
This means that the device hasn't yet recognized that the connection broke. You can try to send a "ping" message every few seconds.
yes, agree.
Testing using my Smartphone it works super. But when using my old tablet you can see how slow it works to tell the broken connexion.


Hi

How can I know when the BT connection is broken in order to try a new connection?

thanks
I think you should not only look at your code but also have a look how your "system/app/product" works.

Example:
We have an App receiving food orders from our takeaways App, this App is always screen on and at just one location close to the printer bluetooth, then the bluetooth connexion is never missed.
 
Last edited:
Upvote 0

cas6678

Active Member
Licensed User
Longtime User
I think you should not only look at your code but also have a look how your "system/app/product" works.

Example:
We have an App receiving food orders from our takeaways App, this App is always screen on and at just one location close to the printer bluetooth, then the bluetooth connexion is never missed.
If the BT printer is disconnected from the electrical network, the communication is broken. For example šŸ˜ . I need to acknowledge it to reconnect.

This means that the device hasn't yet recognized that the connection broke. You can try to send a "ping" message every few seconds.

Do you have any example. I just saw one about MQTT connect & reconnect. I understand the logic of what you propose and it's fine. I need to know how to send that ping. For example to send I use:
B4X:
astrem.write(send)
and for listen:
B4X:
Sub AStreams_NewData (Buffer() As Byte)
... with ping?

Thanks
 
Upvote 0
Top