ES Libraries Documentation

Online documentation:
Home
What Sensor Data?
Collecting Sensor Data
Formatting Sensor Data
Store/Transfer Data
Research
Contributing
Project Github Page

Storing and Transmitting Data

1. Start by Extending an Abstract Data Logger

The ES Sensor Data Manager library defines a number of abstract logger types; to create a data logger, you need to extend one of these. You can find examples of all of these loggers in the Demo Project. Select from:

  1. The AbstractStoreOnlyLogger, which will only store any captured data.
  2. The AbstractAsyncTransferLogger, which will store data that it receives and then regularly attempt to batch upload compressed files of data.

For example, to create a logger that only stores data, start with:

public class MyDataLogger extends AbstractStoreOnlyLogger {

}

a. Pick a storage type

All of the constructors for the logger types require you to specify a storage type. This can be one of:

  1. DataStorageConfig.STORAGE_TYPE_DB to store the data in a local SQLite database.
  2. DataStorageConfig.STORAGE_TYPE_FILES to store the data in the file system; your app must have the permission to write to the external storage.

b. Configure the logger

You configure your data logger by implementing the methods you inherit from your abstract logger type. All loggers, regardless of their type, must implement:

  1. shouldPrintLogMessages(): whether the library should print Log.d messages, for debug purposes.
  2. getUniqueUserId(): a String that identifies this user.
  3. getDeviceId(): a String that identifies this device.
  4. getEncryptionPassword(): a String that will be used to encrypt the data. If this is left as null, the data will not be encrypted.

If you do not have a user or device id (e.g., your app will ask the user to select a login account), you can use setUniqueUserId() and setDeviceId() at a later time.

Beyond these, the loggers that transmit data also require:

  1. getPostKey(): a String that will be used as a key when transmitting the data to the server.
  2. getPostParameters(): a map of key-value pairs that contain any additional data that should be sent when transmitting data; e.g., an API key.
  3. getDataPostURL(): a String of the URL that you are sending data to.
  4. getSuccessfulPostResponse(): the String that the server will reply with when it has successfully received some data.

And the loggers that store data also require:

  1. getStorageName(): the name for the file system directory that will hold your data.

2. Log Data

You can log data with this library by providing a tag for that data.

String tag = "Greeting";
String data = "Hello!";

AbstractDataLogger logger = new MyDataLogger(context);
logger.log(tag, data);

This will create a JSON object log entry, and automatically add the user's details and the current time.

When logging sensor data directly, the tag is the sensor's name; you can log the data directly by:

SensorData d = ...;
logger.logSensorData(d);

4. Upload Data

To upload data, select the AsyncTransfer logger. Your app will require permissions to use the Internet and to check the network state; you will also have to implement methods that tell gives the logger details to use when posting data.

To manually trigger a data upload, use the postAllStoredData() method; you will have to implement the DataUploadCallback interface.