Error 515 not connected to bluetooth

I know there are posts regarding this issue, but none seem to correspond to my issue.
My app has four screens a main menu plus 3 child screens, each of the child screens connects to an Arduino controller via BlueTooth. Each child screen makes a new connection to BlueTooth and disconnects when closing. Each screen tests the connection on opening and reports if the connection is successful. When testing using the Al download it works fine. When the app is built and installed changing screens produces the Error 515, although the connection test has reported the connection has been established and remains on the screen.

Is this a bug within the Bluetooth client extension? As each screen is fully populated it is not possible to reduce it to one screen. Example of code for one screen.

Fully populated with what?

Copy each screen in the Designer using Ctrl-C, and paste (Ctrl-V) each into a separate Vertical Arrangement in Screen1.
Have only one Arrangement visible at a time.

That should avoid the problem.

1 Like

Hello John

What ABG suggests is known as "Virtual Screens". It is usually the method of choice for Apps that require multiple screens.

When we define virtual screens, we use one 'real' App Inventor Screen (most often Screen1). Screen-sized Vertical Arrangements on it are displayed/hidden as required - they are the Virtual Screens. This is generally a better approach for multi-screen Apps, they share data without having to "pass" it between screens and it also reduces code duplication, making the App more efficient and the code easier to follow if you have to return to it at a later date.
So, instead of separate "houses", virtual screens are "rooms" of the same "house".

In your case, using Virtual screens means you require only one instance of the BT Client and only one Connect block, one Send block. It won't remove error 515 if you leave the connect block in a Screen Initialize block - sometimes a connection can take a while, or fail on the first attempt, so put it in a Clock Timer block, time interval 200 milliseconds, something like this:

There may be a flaw in your code that allows connection success to be reported when it has actually failed.

It's important to ensure both your Android device and your Arduino have Bluetooth switched on. Depending on your version of Android, you may need to have Location switched on too - a Google security thing.

1 Like

Dear @bluey,
what have already said @ABG and @ChrisWard is perfect, but I would add also some other comments.
The BT communication of each screen is it handled via a "local" clock ? In other words, are you polling the BT communication via a clock that rises a communication attempt every (for example) 10 milliseconds ? If yes, are you switching it off before leaving the screen ? Otherwise the clock could still try to communicate when the screen has already changed. So the error message isn't issued by the "current" screen but by the former one.
Else, if you are sure that the error message is issued by the current screen, and you are sure that the BT has successfully been connected instead, you can simply avoid the error message by trapping it with an empty "ScreenX ErrorOccurred" block in which you can do something like the following (obviously Label1 is a "fake" label, it is just to do something that is doing nothing :grimacing::

Another doubt is: do you use the same name for the BT client in your 4 screens ? Or do you use different names like Client_BT_Scr1; Client_BT_Scr2;.... it could help to have different names in order to have a clearer separation between tasks.

Best wishes ! :crossed_fingers:

Thanks USkiara,
your suggestion has fixed the problem. It was the closing screen giving the error.

1 Like

Hi @bluey,
glad to have helped !
BTW, if you check the "solution" box, the post can be considered solved and all the participants will be noticed of that.
Many thanks and ciao, Ugo.