Logger

The MetaWear board can log sensor data and store it in the internal memory of the device using loggers to be retrieved at a later time.

Loggers record data from a data signal and are represented by the MblMwDataLogger struct.

Create an MblMwDataLogger object by calling mbl_mw_datasignal_log with the data signal you want to log.

If successful, the callback function will be executed with a MblMwDataLogger pointer and if creating the logger failed, a null pointer will be returned.

#include "metawear/core/datasignal.h"
#include "metawear/core/logging_fwd.h"
#include "metawear/sensor/multichanneltemperature.h"

auto temp_signal = mbl_mw_multi_chnl_temp_get_temperature_data_signal(board, 0);
mbl_mw_datasignal_log(temp_signal, [](MblMwDataLogger* logger) -> void {
    if (logger != nullptr) {
        printf("logger ready\n");
    } else {
        printf("Failed to create the logger\n");
    }
});

MblMwDataLogger objects only interact with the specific data signal, they do not control the logging features. Logging control functions are detailed in the Logging section.

ID

MblMwDataLogger objects are identified by a numerical id.

This id can be used to keep track of loggers when there is considerable time between the start of a log and the download of a log. It is also useful to get the state of the device (i.e is my device still downloading?).

You can retrieve the id by calling mbl_mw_logger_get_id.

The id is used to retrieve existing loggers from the API with the mbl_mw_logger_lookup_id function.

A skeleton example:

// SETUP LOGGER
auto SAVED_LOGGER_PTR = nullptr
auto temp_signal = mbl_mw_multi_chnl_temp_get_temperature_data_signal(board, 0);
mbl_mw_datasignal_log(temp_signal, [](MblMwDataLogger* logger) -> void {
    if (logger != nullptr) {
        SAVED_LOGGER_PTR = logger;
        printf("logger ready\n");
    }
});
auto SAVED_LOGGER_ID = mbl_mw_logger_get_id(SAVED_LOGGER_PTR)

// TIME PASSES //

// DOWNLOAD LOGGER
auto LOGGER = mbl_mw_logger_lookup_id(board, SAVED_LOGGER_ID)
mbl_mw_logger_subscribe(LOGGER, [](const MblMwData* data) -> void {
    printf("got data\n");
});

Handling Data

Like a data signal, you can subscribe to an MblMwDataLogger to process the downloaded data.

Call mbl_mw_logger_subscribe to attach a callback function to the MblMwDataLogger which handles all received data.

void logger_subscribe(MblMwDataLogger* temp_logger) {
    mbl_mw_logger_subscribe(temp_logger, [](const MblMwData* data) -> void {
        printf("temperature= %.3fC\n", *((float*) data->value));
    });
}

Removal

When you no longer want to log the values from a data signal, call mbl_mw_logger_remove to remove the logger.

mbl_mw_logger_remove(temp_logger)