The MetaWear firmware comes with a timer that can be used to schedule tasks on the board. Unlike using a Timer or Handler from the Android side, the MetaWear timer is only used with MetaWear commands and solely exists on the board.

Scheduling a Task

Use ScheduleAsync to schedule tasks to be run in the future. Typically this is used with the forced data producer’s Read function to have the board periodically request data from that producer.

// send a read command to the dadta producer every 30 seconds, start immediately
public async Task<IScheduledTask> ScheduleRead(IForcedDataProducer producer) {
    return await metawear.ScheduleAsync(30000, false, () => producer.read());

Task Management

After scheduling a task, use the created IScheduledTask object to Start, Stop, and Remove the task. Furthermore, all IScheduledTask objects have a unique numerical value that is used to retieve a previously created task at any time with LookupScheduledTask.

IScheduledTask mwTask;

// lookup a task with id = 0
if ((mwTask = metawear.LookupScheduledTask((byte)0)) != null) {
    // start the task

    // stop the task

    // remove the task, id 0 no longer valid id