ES Libraries Documentation

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

Formatting Sensor Data

1. Start with the Data Formatter

You can get a formatter by calling the getJSONFormatter() method in the DataFormatter class. This method's parameters are:

For example, to get a formatter for accelerometer data:

AccelerometerFormatter f = (AccelerometerFormatter) DataFormatter.getJSONFormatter(context, SensorUtils.SENSOR_TYPE_ACCELEROMETER);

You can also use the getSensorType() method in a SensorData object.

SensorData d = sm.getDataFromSensor(SensorUtils.SENSOR_TYPE_ACCELEROMETER);
JSONFormatter f = DataFormatter.getJSONFormatter(context, d.getSensorType());

2. Convert Sensor Data to a JSON String

To convert your SensorData object to a JSON string, use the toString() method. The following example builds on the above to format the accelerometer data:

String s = f.toString(d);

a. JSON Data Contents

All JSON formatted data includes the following keys:

{
	"sensorType": "string",
	"senseStartTime":"HH:mm:ss:SSS dd MM yyyy Z z",
	"senseStartTimeMillis":0,
	"userid":"string",
	"deviceid":"string",
}

Where:

You can refer to the sensors page to see sample JSON for each sensor.

3. Convert a JSON String to Sensor Data

To convert a JSON string back to a SensorData object, use the toSensorData() method. The following example builds on the above to format the accelerometer data:

AccelerometerData d2 = (AccelerometerData) f.toSensorData(s);