Bluetooth BytesAvailableToReceive() in timer routine causes my app to hang

279 views
Skip to first unread message

Johann Hugo

unread,
Jun 23, 2016, 1:00:17 PM6/23/16
to MIT App Inventor Forum
I'm busy with an app that connects to an arduino board via Bluetooth, see attached.

The app works fine on all my Samsung android devices, but it hangs on my Alacatel POPC7 phone.

On the POPC7 it looks like the BytesAvailableToReceive() routine does not return, but only when there is no data available on Bluetooth. 

If I call BytesAvailableToReceive() manually (button), after sending data from the arduino, then the app keeps on working, but if call it again after reading the data, then it will cause the app to hang.

I think this guy might have the same problem:

Phone details:
Model:        Alcatel one touch 7041X
Firmware:   4.2.2
Kernel:       3.4.5
Build:         070FZG1

Regards
Johann
screenshot-ai2.appinventor.mit.edu 2016-06-23 18-27-38.png

Taifun

unread,
Jun 23, 2016, 6:47:39 PM6/23/16
to MIT App Inventor Forum
as far as I can see, your blocks look fine

If I call BytesAvailableToReceive() manually (button), after sending data from the arduino, then the app keeps on working, but if call it again after reading the data, then it will cause the app to hang.
if you call it manually, than that method will block
therefore call that method inside the clock.timer event
 
Taifun


Trying to push the limits of App Inventor! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun. 

Johann Hugo

unread,
Jun 25, 2016, 12:02:09 PM6/25/16
to mitappinv...@googlegroups.com
Agreed, inside the clock.timer event is the right place to run it. I only did it to make sure that it's the BytesAvailableToReceive() routine that causes my app to hang. Wonder why it does not work on some phones :(

B.t.w. calling any one of the bluetooth Receive functions, but with no data available from bluetooth, will cause the app the hang (on any Android device). This means that if you are expecting four bytes, but one gets dropped over the bluetooth connection, then it may cause your app to hang. Guess the bluetooth receive functions will wait forever, until it gets the data. Is there any way to set some kind of timeout for the receive functions.

Johann

 
Reply all
Reply to author
Forward
0 new messages