resetAsync, board.disconnectAsync(), board.tearDown
Hey
I am a bit confused with the functions mentioned in the title. I use connectAsync to connect to a MetaMotionR board and stream accelerometer data.
I have two questions:
Sometimes the connection is lost after a while and a reconnection is not done automatically, yet if I go out of range of my mobile phone, it reconnects automatically afterwards.
Maybe this is the same problem as mentioned here:
https://mbientlab.com/community/discussion/1780/disconnect-failure-behaviour
What is the best way to handle those disconnections?
I use board.onUnexpectedDisconnect(new MetaWearBoard.UnexpectedDisconnectHandler()
and then connect to the board again. Do I have to tearDown everything before connecting again to the board?
Now I also saw the function settings.onDisconnectAsync
. Whats the difference?
2. Sometimes after disconnecting the next connection fails. So I asked myself how to disconnect properly ?
Is it better to use disconnectAsync
and then tearDown
or resetAsync
. And shoudl I unbind the Bluetooth Service as well?
I hope someone has an answer to so many questions
Best regards!
Comments
What do you mean by "reconnection is not done automatically"? Is the disconnect handler not being called, or is it not successfully able to reconnect, or something else?
Probably not, that issue is over 2 years old and the firmware has have several revisions since then
That is how the API notifies you of disconnect events.
No.
tearDown
is explained in the developer documentation:https://mbientlab.com/androiddocs/3/metawearboard.html#tear-down
This is also explained in the developer documentation:
https://mbientlab.com/androiddocs/3/settings.html#handling-disconnects
You can't issue commands to the board if it is disconnected.
You won't always successfully connect on the first attempt. Add some retry logic that attempts to connect for up to X connects.
Hey Eric,
thanks for your answer!
Reagrding your first question:
I meant that if I go out of range with the sensor , after a few minutes when I come back it reconnects, thats fine.
But after an hour it does not reconnect...
That does not fully answer my question, quoted below:
Hey Eric,
I mean teh handler is called but it is not successfully able to reconnect.
Furthermore I noticed another behaviour with the Google Pixel 3, running Android 9. When I minimize the app and reopen it after about an hour, the application restarts and the sensor is not connected anymore. Although I declared my class as a service, it seems that my application is silently killed. In that case the handler is not called.
Post your handler code.
There's nothing the MetaWear API can do if the OS kills your app.
I have a class which implements ServiceConnection. Yet it is not listed as active services in the settings of my device...Do I also have to extend Service in this class?