MBLEvent Class Reference

Conforms to ResultType
Declared in MBLEvent.h


This object represents “events” generated by sensors and peripherals on the MetaWear board.

There are several things you can do when an event occurs, all of which are programmable using this object, they are:

  1. Send notifications to the connected iOS device when the event occurs, see startNotificationsWithHandlerAsync: and stopNotificationsAsync
  2. Program other commands to be executed offline on the MetaWear device when the event occurs, see programCommandsToRunOnEventAsync: and eraseCommandsToRunOnEventAsync.
  3. Log the event in the MetaWear’s flash storage, see startLoggingAsync and downloadLogAndStopLogging:handler:progressHandler:
  4. Pass the event data into a filter, which and process the data in some way and outputs the result in a new MBLEvent. See summationOfEvent and periodicSampleOfEvent:.


Consider the switch update event, [MBLMechanicalSwitch switchUpdateEvent].


If you call startNotificationsWithHandlerAsync: and keep a live connection to the MetaWear, any time you press or release the switch you will get a callback to the provided block.

[device.mechanicalSwitch.switchUpdateEvent startNotificationsWithHandlerAsync:^(id obj, NSError *error) {
    // Handle the button press/release


If you call startLoggingAsync, then anytime you press or release the button, an entry will be created in the log which can be download later using downloadLogAndStopLogging:handler:progressHandler:.

[device.mechanicalSwitch.switchUpdateEvent startLoggingAsync];
// Some time later..
[device.mechanicalSwitch.switchUpdateEvent downloadLogAndStopLogging:YES/NO handler:{...} progressHandler:{...}];


If you want the device to buzz when you press the switch then you would do the following:

[device.mechanicalSwitch.switchUpdateEvent programCommandsToRunOnEventAsync:^{
    [device.hapticBuzzer startHapticWithDutyCycle:248 pulseWidth:500 completion:nil]


If you want to log a running count of pushbutton events, you could do the following:

MBLEvent *event = [device.mechanicalSwitch.switchUpdateEvent summationOfEvent];
[event startLoggingAsync];
// Some time later..
[event downloadLogAndStopLogging:YES/NO handler:{...} progressHandler:{...}];


Warning: Calling summationOfEvent or any other filter method returns a freshly created MBLEvent object which you must retain for later use. This is different from the MBLEvent properties on the various modules which internally save the MBLEvent object and always return the same pointer through the property.

Warning: Since all MBLEvent’s are invalidated on disconnect, you need a way to restore your custom event on reconnect. This is where the MBLRestorable comes in, you can call setConfiguration:handler: on the MBLMetaWear object to save any properties on your custom MBLRestorable object.