Android Question Asyncstream proper recovery ?

sanduro

Member
Licensed User
Longtime User
I have a control unit(microprocessor) connected via Bluetooth.
I am trying to create ALL possible error recovery procedure.

So Far success. If I use Asyncstream without prefix with the code I attached, it recovers properly.
1. if I turn off the unit, I get
java.io.IOException: bt socket closed, read return: -1
error and I am able to recover connection

2. if I turn OFF blue tooth on tablet, it turns the BT back on and recovers (data are coming from controlbox to android again.)

This should cover all lost signal, BT disabled problems.

NOW PROBLEM.

if I try to do the same thing with same code I just replace
B4X:
Asyx.Initialize(Ser.InputStream,  Ser.OutputStream, "Asyx")
with
B4X:
Asyx.InitializePrefix(Ser.InputStream, False, Ser.OutputStream, "Asyx")
I see strange behavior. My app tries to connects to box properly, then i manually turn off BT on android.
Log says
java.io.IOException: bt socket closed, read return: -1
as before and app tries to connect again.
It enables BT etc.....
But I never get connection running again, and my app hangs. Android says app stopped working.
What is worst even if i close my application and run it again it never ever connects .

Only solution is to REBOOT the android.

Can you help me with that ?
How to properly recover from any AsyncStream_error in PREFIX mode?
e.g BT died, other side died but it will be turned on in minute after reboots, async size error, when I have some interference. ???

I enclose the WORKING version of code with NON-PREFIX, to make it PREFIX comment line 89 and uncomment line 90 in
service
 

Attachments

  • BTCON.zip
    9 KB · Views: 174

sanduro

Member
Licensed User
Longtime User
I have fixed it, the curious way BUT it works, I am killing the whole communication service and staring it again.

Once I finish this can be used as general code template for ANY communication via BLUETOOTH and ASYNCSTREAM.

You can use it as general template for communication via BT with any microcontroller includeing ARDUINO.

Would you be interested in such a code ?

San
 
  • Like
Reactions: Sia
Upvote 0

Sia

Member
Licensed User
Longtime User
I have fixed it, the curious way BUT it works, I am killing the whole communication service and staring it again.

Once I finish this can be used as general code template for ANY communication via BLUETOOTH and ASYNCSTREAM.

You can use it as general template for communication via BT with any microcontroller includeing ARDUINO.

Would you be interested in such a code ?

San

Yes please share your solution or code
 
Upvote 0
Top