A MetaWear timer can be thought of as an event that is fired at fixed intervals.

These timers are represented by the MblMwTimer struct and can be safely typcased to a MblMwEvent struct.

Timers can be used to schedule periodic tasks or setup a delayed task execution. For example, you can use the timer to record temperature samples are extremely low frequencies such as once per day or once per hour.


MblMwTimer objects are identified by a numerical id; you can retrieve the id by calling mbl_mw_timer_get_id.

The id is used to retrieve existing timers from the API with the mbl_mw_timer_lookup_id function.

As with previous sections, you may want to keep the id handy so that you can retrieve a timer at a later time.

Task Scheduling

Before you can schedule tasks, you first need to create a timer, by calling either mbl_mw_timer_create or mbl_mw_timer_create_indefinite. These functions are asynchronous and will pass a pointer to the caller when the timer is created.

When you have a valid MblMwTimer, you can use the command recording system outlined in Events section to program the board to respond to the periodic events.

Upon recording timer task commands, call mbl_mw_timer_start to start the timer.

When you are done using a timer, you can remove it with mbl_mw_timer_remove.

A good example is the one mentioned above. Because the humidity sensor is a slow sensor, it must be read using a timer to get periodic readings (unlike setting the ODR for the accelerometer):

mbl_mw_humidity_bme280_set_oversampling(device.board, MBL_MW_HUMIDITY_BME280_OVERSAMPLING_16X)

let signal = mbl_mw_humidity_bme280_get_percentage_data_signal(device.board)!
mbl_mw_datasignal_subscribe(signal, bridge(obj: self)) { (context, obj) in
    let humidity: Float = obj!.pointee.valueAs()
    print(String(format: "%.2f", humidity))

// Create a timer to read every 700 ms
device.timerCreate(period: 700).continueOnSuccessWith { timer in
    timer.eventEndRecord().continueOnSuccessWith {