Bluetooth AsyncStreams issue

techknight

Well-Known Member
Licensed User
Longtime User
I notice if my radio reception gets a little noisy (too far away) or somehow any other reason that an asyncstream packet gets corrupted on receive, the entire app will crash and unexpectedly close.

Is there any way to prevent the entire app from crashing on an asyncstream receive malformed packet? For example, just throw the packet out instead of blowing up the entire app.
 

mc73

Well-Known Member
Licensed User
Longtime User
using the prefix mode? I think that by using it, such problems would be avoided. On the other hand, isn't aStreams_error fired, or aStreams_terminated?
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Yes, prefix mode.

I am communicating with an AVR Microcontroller. Asyncstreams prefix isnt an issue as its pretty solid.

But if the packet drops a byte or so from radio interference, or something of that nature, it will not fire the asyncstreams error, it just crashes the app instead.

If there is an extra byte in the packet, the Asyncstreams_error will fire and terminate the transaction. But if the packet comes up short, it crashes. Also if there is an extra byte in the prefix header by some unknown reason, it also, crashes.

In a 2.4Ghz noisy environment, This situation is inevitable. So far, 90% of the time I dont have a problem. But the problem I do have is that 1 packet every 1000 is malformed in a way that there is a byte missing, or corrupt prefix header, the whole app crashes, and of course the current progress while the app is running is lost. That sucks.

The packet going from the phone to the AVR if its corrupted, my firmware in the AVR will toss it out. it has its own checksum check. But the AVR replying back to the phone implements the "prefix" packet mode. My packet is encapsulated in the Async prefix so when the phone gets it, it will decode it properly and buffer it like normal using the normal asyncstream methods, and its waiting for my app to handle the UTF8 response.

its that return path from the AVR to the phone where the issue occurs of the app crashing. Not transmission from phone to AVR, as the AVR is programmed to know how to deal with it.
 
Last edited:
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I see. If it's your phone waiting for a response, I would suggest initiating a timer and after some seconds (perhaps less than 5) close the connection if no response arrives. Tried that?
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Its not that at all. Waiting for a response isnt the issue. Thats taken care of.

The problem is sometimes the responses arnt "perfect" due to radio noise. And asyncstreams will crash the entire app before the response handler is even invoked. I wish i knew how to explain it better. And I cannot debug it because the app will just quit cold turkey before I have a chance to see the actual packet that caused the failure.
 
Upvote 0
Top