Custom Code: Redirect logged data and store it in a file (or anywhere)

In this guide we redirect accelerometer data to a file on disk, but the functionality is general and the procedure can also be used for OBD data, GPS data etc.

  1. Start by creating a custom code module of type Returner. Go to Advanced > Custom Code:

create_custom_returner

This default returner implementation will append results to a file on disk located at /tmp/returner_data.txt. But in reality it possible to integrate with any storage system here.

  1. For the accelerometer service named ACC_MANAGER register the created custom returner as a hook so it can be used in worker workflows. Go to Advanced > Services > ACC_MANAGER > Hooks > Create:

register_custom_returner_hook

  1. Next we have to use the registered hook by editing the workflow for the xyz_logger worker. Go to Advanced > Services > ACC_MANAGER > Workers > xyz_logger. Here we have to change the returner from cloud to my_returner:

use_custom_returner_in_workflow

When above changes have been successfully synchronised to the device, it will start logging accelerometer data to the specified file.

When logged onto the device using SSH, it is possible to monitor the data in realtime with the command:

tail -f /tmp/returner_data.txt

:warning: NOTE: We currently (January 21st 2020) have a minor issue where it’s not possible to assign the custom hook to a default worker. Which the xyz_worker is.

To get around this issue, you can do the following

  1. Click the xyz_logger worker to bring up the edit view, and change the name to something else, and then click save. This will create a duplicated version of the logger.

  2. Disable the old xyz_logger, by clicking the trash icon to the right.

Now you should be able to set the correct returner on the custom worker you created.

2 Likes