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.
var accSignal = MetaWear.mbl_mw_acc_get_acceleration_data_signal(device.board);
MetaWear.mbl_mw_datasignal_log(accSignal, ref.NULL, MetaWear.FnVoid_VoidP_DataLoggerP.toPointer(function (context, logger) {
accelLogger = logger;
callback(logger.address() ? null : new Error('failed to start logging accel'));
}))
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.
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.
// Subscribe to the accelerometer data
MetaWear.mbl_mw_logger_subscribe(accelLogger, ref.NULL, MetaWear.FnVoid_VoidP_DataP.toPointer(function onSignal(context, dataPtr) {
var data = dataPtr.deref();
var pt = data.parseValue();
console.log(data.epoch + ' ' + pt.x + ',' + pt.y + ',' + pt.z);
}));
Removal¶
When you no longer want to log the values from a data signal, call mbl_mw_logger_remove to remove the logger.
MetaWear.mbl_mw_logger_remove(accelLogger);