I am experiencing inconsistencies in sensor readings taken on my smartphone app using Edge Impulse APIs. Specifically, a 30-second reading appears to be shortened randomly on Edge Impulse, which affects the reliability of the data collected. I suspect this issue might be related to sampling rates.
Our project involves using smartphone sensors to collect and process data for human activity recognition. We rely on consistent data uploads to Edge Impulse for machine learning model training and inference.
Steps Taken:
-
Implemented sensor data collection in the Android app using
SensorManager
. -
Set the sensor sampling rate with
mSensorManager.registerListener(sensorEventListener, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL)
. -
Uploaded the sensor readings to Edge Impulse using the provided APIs:
private void sendToEdgeImpulse(List<float[]> accelerometerData) {
JSONObject jsonData = formatRealTimeData(accelerometerData);
OkHttpClient client = new OkHttpClient();ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { bos.write(jsonData.toString().getBytes("UTF-8")); } catch (IOException e) { throw new RuntimeException(e); } RequestBody body = RequestBody.create(bos.toByteArray(), MediaType.parse("application/json")); if (body != null) { Log.d("EdgeImpulse", "RequestBody created successfully"); } else { Log.e("EdgeImpulse", "Failed to create RequestBody"); } Request request = new Request.Builder() .url("https://ingestion.edgeimpulse.com/api/training/data") .addHeader("x-api-key", "ei_...") .addHeader("x-label", activityType) // Send the chosen activity as label .addHeader("Content-Type", "application/json") .addHeader("X-File-Name", "real_time_data.json") .post(body) .build(); client.newCall(request).enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { runOnUiThread(() -> txtProgress.setText("Upload failed")); Log.d("EdgeImpulse", "Upload failed: " + e.getMessage()); } @Override public void onResponse(Call call, Response response) throws IOException { if (!response.isSuccessful()) { runOnUiThread(() -> txtProgress.setText("Upload failed")); Log.d("EdgeImpulse", "Upload failed with response code: " + response.code()); throw new IOException("Unexpected code " + response); } runOnUiThread(() -> { txtProgress.setText("Data uploaded successfully"); }); } });
}
Expected Outcome:
I expected the sensor readings taken over a longer period to be accurately reflected on Edge Impulse without random truncation or loss of data.
Actual Outcome:
The sensor readings appear to be randomly shortened on Edge Impulse, leading to data inconsistencies and challenges in analysis.
Reproducibility:
- Always
I am also seeking guidance on the sampling rates for the sensors used and how to ensure that they align with Edge Impulse’s requirements. Any relevant documentation or support regarding sending data through APIs instead of QR code scanning would also be appreciated.