Online documentation:
Home
What Sensor Data?
Collecting Sensor Data
Formatting Sensor Data
Store/Transfer Data
Research
Contributing
Project Github Page
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:
AbstractStoreOnlyLogger
, which will only store any captured data.
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 {
}
All of the constructors for the logger types require you to specify a storage type. This can be one of:
DataStorageConfig.STORAGE_TYPE_DB
to store the data in a local SQLite database.
DataStorageConfig.STORAGE_TYPE_FILES
to store the data in the file system; your app must have the permission to write to the external storage.
You configure your data logger by implementing the methods you inherit from your abstract logger type. All loggers, regardless of their type, must implement:
shouldPrintLogMessages()
: whether the library should print Log.d messages, for debug purposes.
getUniqueUserId()
: a String that identifies this user.
getDeviceId()
: a String that identifies this device.
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:
getPostKey()
: a String that will be used as a key when transmitting the data to the server.
getPostParameters()
: a map of key-value pairs that contain any additional data that should be sent when transmitting data; e.g., an API key.
getDataPostURL()
: a String of the URL that you are sending data to.
getSuccessfulPostResponse()
: the String that the server will reply with when it has successfully received some data.
And the loggers that store data also require:
getStorageName()
: the name for the file system directory that will hold your 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);
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.