Event on BLE disconnect

Hi,

I have an application for the sensor that requires constant accelerometer data streaming to the handset which works very well on a RG running latest firmware and iOS SDK, the app also uses the LED to provide state feedback to the end user (eg connected, data streaming, etc).  It would be extremely beneficial to be able to trigger certain activities on BLE disconnect within the device, for example,  flashing the LED to signify the disconnection of the BLE, switching the accelerometer off and enabling iBeacon mode.  Clearly there are battery consumption benefits to be had by shutting down peripheralson BLE disconnect for some applications too.

Looking through the iOS API I can't see any 'device' level events that can be hooked to achieve the above via programCommandsToRunOnEvent, is there a work around or something that can be added to the roadmap - I would think that disconnect events would be useful in a number of applications.

Cheers,
Matt

Comments

  • Yes, this is a feature we have on our TODO list.  Currently, there is no way to do this with the MetaWear API until the firmware is updated to support the disconnect event.
  • matthew,

    This is a good idea, can you file this in the feature request section?

    Thanks!
  • Eric & Laura,

    any update on this feature request?

    Thanks
  • This was added in the previous firmware and android api release.
  • Hi Eric, 

    does the disconnect event on the board send a notification to the api?

    any link to the documentation on how to use it?

    Thanks
  • Disconnected notification is sent through the ConnectionStateHandler class.

    I haven't updated the docs yet.  Here's a code snippet on how to use it:

    mwBoard.getModule(Settings.class).handleEvent().fromDisconnect().monitor(new ActivityHandler() {...})
        .commit();
  • HI Eric,

    thank you for the snippet. 

    Is there any way to simulate an on board disconnect/reset to trigger the api callback?

    Thanks again for your help.
  • Hi Eric,

    Just a quick note to say I think the feature has regressed in the latest firmware (1.1.2) the disconnect event doesn't seem to be firing any more.  I have the following code in my Config class which has been applied to a couple of modules running 1.1.2:







     [device.settings.disconnectEvent programCommandsToRunOnEventAsync:^{

            [device.led setLEDColorAsync:[UIColor redColor] withIntensity:1.0];

        }];


    Prior to upgrade (v1.0.0 FW) the same code worked perfectly and the Red LED lit on disconnect.


    Matt

  • Turning on the LED on disconnect is working fine for me on firmware v1.1.2 using the Android API.
  • Confirmed an SDK bug, will publish release within 48 hours.
  • Thanks for the report, please see if SDK 2.1.1 fixes your issue.  Thanks!
  • Yep, iOS SDK 2.1.1 resolves the issue with the latest FW.


    Thanks guys,
    Matt
  • @Override
    public void onSignalActive(Map<String, DataProcessor> map, DataSignal.DataToken dataToken) {
    mCallbacks.onRemoteFailure();
    }
    please can I get more info on this:
    dataToken expose only offset() and length(). How is it suppose to be used to match the disconnect event? 
    any suggestion?
    Thanks
  • I don't think you understand the purpose of matthewpjw's request.  The point of this feature is so the board can react to a btle disconnect event, which you setup with the provided code snippet.  If you want the phone to react to a disconnected event, then you use the ConnectionStateHandler class.
  • Hi  Eric,

    sometime the board reset itself and leave the connection in inconsistent state. This happen after 2/3 days of continuous connection. My app needs to be notified if something happen to the board (for whatever reason) so I can reconnect to the board.
    If I'm not wrong onSignalActive is being called when something happen to the board. If that's the case I can catch the event and notify my app of the failure accessing the params details.

    If that's not the case, is there any way to be notified in case of board reset?

    hope this explain my need.

    Thanks
  • The code in the onSignalActive function is for MetaWear commands only, and they are executed on the board, not on your app.

    A board reset means the connection is terminated from the board side.  You can use the failure function from ConnectionStateHandler to handle these types of connection loss.
This discussion has been closed.