The module offers two ways to retrieve the stored data.
The STORAGE_FLUSH message emits individual STORAGE_DATA messages. Use it for small datasets.
For bulk access, use STORAGE_BATCH_REQUEST with a unique session_id, as in the following example:
struct storage_msg msg = { .type = STORAGE_BATCH_REQUEST, .session_id = 0x12345678 };
err = zbus_chan_pub(&storage_chan, &msg, K_SECONDS(1));
// Wait for STORAGE_BATCH_AVAILABLE, then:
struct storage_data_item item;
while (storage_batch_read(&item, K_SECONDS(1)) == 0) {
switch (item.type) {
case STORAGE_TYPE_BATTERY:
double battery = item.data.BATTERY;
break;
// ... handle other types
}
}
// Close session
struct storage_msg close = { .type = STORAGE_BATCH_CLOSE, .session_id = 0x12345678 };
zbus_chan_pub(&storage_chan, &close, K_SECONDS(1));
The module responds with STORAGE_BATCH_AVAILABLE on success, or with STORAGE_BATCH_EMPTY, STORAGE_BATCH_BUSY, or STORAGE_BATCH_ERROR.