Online documentation:
Home
What Sensor Data?
Collecting Sensor Data
Formatting Sensor Data
Store/Transfer Data
Research
Contributing
Project Github Page
You can get a formatter by calling the getJSONFormatter() method in the DataFormatter class. This method's parameters are:
SensorUtils class.
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());
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);
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:
sensorType: is the string identifier for the sensor, as defined in the SensorUtils class.
senseStartTime: is the string-formatted time that sensing from this sensor began (measured on the device).
senseStartTimeMillis : is the time in milliseconds that sensing from this sensor began (measured on the device).
userid: is the string user-id that you have given the data manager.
deviceid: is string device-id that you have given the data manager.
You can refer to the sensors page to see sample JSON for each sensor.
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);