cas6678 Active Member Licensed User Longtime User Jan 31, 2021 #1 Hi How can I know when the BT connection is broken in order to try a new connection? thanks
Erel B4X founder Staff member Licensed User Longtime User Feb 1, 2021 #2 You should implement AsyncStreams Error and Terminated events. Upvote 0
cas6678 Active Member Licensed User Longtime User Feb 1, 2021 #3 I've AsyncStreams Error and Terminated event, but when turn off the other device (broken the connection) the Subs not work. B4X: Copy 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
I've AsyncStreams Error and Terminated event, but when turn off the other device (broken the connection) the Subs not work. B4X: Copy 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
Erel B4X founder Staff member Licensed User Longtime User Feb 1, 2021 #4 This means that the device hasn't yet recognized that the connection broke. You can try to send a "ping" message every few seconds. Upvote 0
This means that the device hasn't yet recognized that the connection broke. You can try to send a "ping" message every few seconds.
f0raster0 Well-Known Member Licensed User Longtime User Feb 1, 2021 #5 Erel said: This means that the device hasn't yet recognized that the connection broke. You can try to send a "ping" message every few seconds. Click to expand... 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. cas6678 said: Hi How can I know when the BT connection is broken in order to try a new connection? thanks Click to expand... 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: Feb 2, 2021 Upvote 0
Erel said: This means that the device hasn't yet recognized that the connection broke. You can try to send a "ping" message every few seconds. Click to expand... 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. cas6678 said: Hi How can I know when the BT connection is broken in order to try a new connection? thanks Click to expand... 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.
cas6678 Active Member Licensed User Longtime User Feb 2, 2021 #6 f0raster0 said: 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. Click to expand... If the BT printer is disconnected from the electrical network, the communication is broken. For example ? . I need to acknowledge it to reconnect. Erel said: This means that the device hasn't yet recognized that the connection broke. You can try to send a "ping" message every few seconds. Click to expand... 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: Copy astrem.write(send) and for listen: B4X: Copy Sub AStreams_NewData (Buffer() As Byte) ... with ping? Thanks Upvote 0
f0raster0 said: 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. Click to expand... If the BT printer is disconnected from the electrical network, the communication is broken. For example ? . I need to acknowledge it to reconnect. Erel said: This means that the device hasn't yet recognized that the connection broke. You can try to send a "ping" message every few seconds. Click to expand... 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: Copy astrem.write(send) and for listen: B4X: Copy Sub AStreams_NewData (Buffer() As Byte) ... with ping? Thanks
Erel B4X founder Staff member Licensed User Longtime User Feb 2, 2021 #7 The exact details depend on the messages protocol that you are using. For example, I like to start each message with a byte or int that identifies the message. This way you can create a "ping" type. Upvote 0
The exact details depend on the messages protocol that you are using. For example, I like to start each message with a byte or int that identifies the message. This way you can create a "ping" type.