This library sends various sensor data to the mHealth Lab server for real-time visualization. This is primarily intended for analyzing on-body sensor data with the goal of improving mobile health.
To start using the MHL Client in your project, add the following dependency to your build.gradle file:
compile 'edu.umass.cs.MHLClient:mhlclient:1.0.4'Initialize a MobileIOClient as follows:
MobileIOClient client = new MobileIOClient(IP_ADDRESS, PORT, userId);You can optionally handle connection and connection failed events using a ConnectionStateHandler object:
client.setConnectionStateHandler(new ConnectionStateHandler {
@Override
public void onConnected(){ ... }
public void onConnectionFailed() { ... }
});Then request a connection using the .connect() method:
client.connect();Sensor readings can be sent using the .sendSensorReading(...) method:
client.sendSensorReading(new AccelerometerReading(userId, DeviceType.MOBILE_ANDROID, timestamp_in_milliseconds, event.values));Available device types are defined in the DeviceType enum. You can define custom sensing modalities by subclassing the SensorReading class as AccelerometerReading does.
If you expect to receive messages back from the server, you can register a MessageReceiver using the client.setMessageReceiver(MessageReceiver) method as follows.
client.setMessageReceiver(new MessageReceiver() {
@Override
public void onMessageReceived(String json) {
//handle message
}
});The received String is by convention a JSON string, which can be parsed into a JSON object for accessing its content.