I am developing an app that requires real time sensor data streaming from a wearable. I am using an LG G watch and the accelerometer and gyroscope sensors.
The sensor data and system current time are packaged as an array of 4 bytes for each axis of each sensor X 32 samples (hence 4 X 3 X COUNT.
This data is then sent through the message api.
Main question: I have registered the sensors with fastest update rate (SENSOR_DELAY_FASTEST) and when I analyze the data samples I have captured with the mobile device, the time step is roughly 200ms per sample (roughly 5 HZ).
I am expecting much faster.
Am I limited by: 1) bluetooth 4.0 bandwith 2) LG G watch sensor (it's an Invensense and the bandwidth should be much higher)... or 3) the message API
Would DataApi allow me to stream data to the mobile device much faster?
Here is a section of my code:
static final int COUNT = 32;
static ByteBuffer AcceleratorBuffer = ByteBuffer.allocate((4 * 3 * COUNT) + (8 * 1 * COUNT));
static ByteBuffer GyroBuffer = ByteBuffer.allocate((4 * 3 * COUNT) + (8 * 1 * COUNT));
static int accelerator_cycle = 0;
static int gyro_cycle = 0;
static AcceleratorWearSensorListener mAcceleratorSensorEventListener = null;
static GyroWearSensorListener mGyroSensorEventListener = null;
static class GyroWearSensorListener implements SensorEventListener {
GoogleApiClient mGoogleApiClient;
public GyroWearSensorListener(GoogleApiClient mGoogleApiClient) {
this.mGoogleApiClient = mGoogleApiClient;
}
@Override
public void onSensorChanged(SensorEvent event) {
if (On) {
Float x = event.values[0];
Float y = event.values[1];
Float z = event.values[2];
Log.i(TAG, "Gyro x: " + x + " y: " + y + " z: " + z);
GyroBuffer.putFloat(x).putFloat(y).putFloat(z).putLong(System.currentTimeMillis()).array();
++gyro_cycle;
if (gyro_cycle % COUNT == 0) {
Wearable.NodeApi.getConnectedNodes(mGoogleApiClient)
.setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
@Override
public void onResult(NodeApi.GetConnectedNodesResult nodes) {
Log.i(TAG, "Nodes size : " + nodes.getNodes().size());
for (Node node : nodes.getNodes()) {
if (node != null && mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
Wearable.MessageApi.sendMessage(
mGoogleApiClient, node.getId(), GYROSCOPE_DATA_PACKET, GyroBuffer.array())
.setResultCallback(
new ResultCallback<MessageApi.SendMessageResult>() {
@Override
public void onResult(MessageApi.SendMessageResult sendMessageResult) {
if (!sendMessageResult.getStatus().isSuccess()) {
Log.e(TAG, "Failed to send message with status code: "
+ sendMessageResult.getStatus().getStatusCode());
} else {
Log.e(TAG, "send gyro data successfully ");
}
}
}
);
} else {
Log.e(TAG, "node null or client null or not connected. ");
}
}
}
});
GyroBuffer.clear();
gyro_cycle = 0;
}
}
}