I'm using the official BLE extension. No issue connecting or sending/receiving data. But, whenever the Companion App Screen refreshes I can no longer interact with the BLE device. This occurs with every Design change.
Understandable, however... the connection persists. The device still thinks it is connected and if I close the companion app the connection does terminate.
If I try disconnecting, I get the following error:
Error 3000: Error 9005 in extension BluetoothLE: Disconnect cannot be called before you are currently connected.
Do you see the same behavior if you compile the apk rather than live test with the Companion?
Do you change real Screens in your app? You might want to show an image of your relevant Blocks.
You may have to provide a StayAwake routine or extension to maintain the connection.
Fortunetely, that is the way it works. If you refresh the companion screen (and that happens automatically when you make a change in the design), then everything is reset. Otherwise it would be really difficult to know what to initialize again etc.
@Ghica. I am expecting everything to reset when the screen refreshes, but...
It doesn't appear that the BLE Extension is fully resetting. I would think it should be terminating its connections upon a reset. It is not, and it leaves connection un-disconnect-able.
Extensions are not an integral part of the app inventor and I don't think there's anything we can implement in extensions that would prevent this problem. Just disconnect before making any changes in the designer, or don't make changes while bluetooth is connected.
Is it possible the extension management in App Inventor proper is missing a step (for all extensions)? This situation sounds like resources are being leaked.
I am disciplined enough to connect/disconnect/connect/disconnect, but I can't say the same for high school students who are focusing on their learning.
I think the extension should support the activity lifecycle, and in the onDestroy method it should disconnect the obtained bluetooth connection. I haven't looked into the ble extension sources, so I don't know if it does that.
In fact, I don't even know if the BLE extension has an open source codebase.
Thanks, I was looking in this repository but I didn't know that extensions are in different branches. If you want I can make changes, compile and send it to you for testing.
If you're looking to submit a patch, you'll want to have BluetoothLE implement OnClearListener and then have its constructor call registerForOnClear with the form. The onClear method is called when the form is refreshed.