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

  • edited January 15

    @Calmarla said:
    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.

    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?

    Maybe this is the same problem as mentioned here:
    https://mbientlab.com/community/discussion/1780/disconnect-failure-behaviour

    Probably not, that issue is over 2 years old and the firmware has have several revisions since then

    What is the best way to handle those disconnections?
    I use board.onUnexpectedDisconnect(new MetaWearBoard.UnexpectedDisconnectHandler() and then connect to the board again.

    That is how the API notifies you of disconnect events.

    Do I have to tearDown everything before connecting again to the board?

    No. tearDown is explained in the developer documentation:
    https://mbientlab.com/androiddocs/3/metawearboard.html#tear-down

    Now I also saw the function settings.onDisconnectAsync. Whats the difference?

    This is also explained in the developer documentation:
    https://mbientlab.com/androiddocs/3/settings.html#handling-disconnects

    1. 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?

    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...

  • edited January 31

    That does not fully answer my question, quoted below:

    @Eric said:

    @Calmarla said:
    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.

    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?

  • 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.

  • @Calmarla said:
    Hey Eric,
    I mean teh handler is called but it is not successfully able to reconnect.

    Post your handler code.

    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.

    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?

Sign In or Register to comment.