Sensors data loss

Hello.
I am working with MetaMotionR devices. I have two devices connected to an android application recording data. In a recent test data from one device was not being recorded for a long period of time while the second one was working fine. I have been recording data from 10:47 AM to 6:40 PM. Data from one device was not being recorded from 5:17 PM to 5:54 PM. You can see the gap in the attached chart. I have run 5 more tests using different devices and phones and have faced the same problem in all of them, some loss intervals were even longer, in some cases data was not being recorded for hours until the end of test.
I handle unexpected disconnects using MetaWearBoard::onUnexpectedDisconnect method trying to reconnect in my application as you can see in the following code snippet. However, it does not work in some cases.
Can you please give me some advice on how do I handle such situations?

Code:

    public void addNewDevice(BluetoothDevice btDevice) {
        final DeviceState newDeviceState = new DeviceState(serviceBinder.getMetaWearBoard(btDevice));
        connectedDevices.add(newDeviceState);
        newDeviceState.getMetaWearBoard()
                .onUnexpectedDisconnect(status -> getActivity().runOnUiThread(() -> {
                    connectedDevices.remove(newDeviceState);
                    addNewDevice(btDevice);
                }));
        newDeviceState.connect();
    }

Device 1 (data lost):

Device 2 (ok):

Another test. 97 minutes of data was lost in the middle of the test and then the data stopped being recorded for more than 3 hours until the end of the test.

Comments

    • Does the same issue happen if you collect data with the MetaBase app?
    • Are you streaming or logging data?
    • You'll have to provide more code than just that snippet.
  • I stream data.

    Today I have tested MetaBase app. I have been recording for approximately 3.5 hours on 3 phones. Two phones worked fine. On the third one the data has stopped being recorded approximately 1 hour after the test start. After the end of test I have successfully restarted the stream manually.

    Here's more code (the connect() method from the snipped I posted before):

    void connect() {
            metaWearBoard.connectAsync()
                    .continueWithTask(
                            task -> {
                                if (task.isCancelled() || !task.isFaulted()) {
                                    Log.i(deviceMac, "Connection task is cancelled");
                                    return task;
                                } else {
                                    Log.i(deviceMac, "Attempt to reconnect");
                                    return reconnect(metaWearBoard);
                                }
                            }
                    ).continueWith(
                            task -> {
                                final Settings boardSettings = metaWearBoard.getModule(Settings.class);
                                if (null != boardSettings) {
                                    boardSettings.editBleConnParams()
                                            .maxConnectionInterval(11.25f)
                                            .commit();
                                    settingsCapture.set(boardSettings);
                                    return boardSettings.battery().addRouteAsync(
                                            source -> source.stream(chargeHandler));
                                    } else return null;
                            }
                    ).continueWith(
                            task -> {
                                final Accelerometer accelerometer = metaWearBoard.getModule(Accelerometer.class);
                                if (null != accelerometer) {
                                    accelerometer.configure()
                                            .odr(ACC_FREQ)
                                            .range(ACC_RANGE)
                                            .commit();
                                    accelCapture.set(accelerometer);
                                    Log.i(deviceMac, ": accelerometer configured");
                                    return accelerometer.packedAcceleration().addRouteAsync(
                                            source -> source.stream(accelerationHandler));
                                } else return null;
                            }
                    ).continueWith(
                            task -> {
                                final GyroBmi160 gyroBmi160 = metaWearBoard.getModule(GyroBmi160.class);
    
                                if (null != gyroBmi160) {
                                    gyroBmi160.configure()
                                            .odr(GyroBmi160.OutputDataRate.ODR_50_HZ)
                                            .range(GyroBmi160.Range.FSR_2000)
                                            .commit();
                                    gyroBmi160Capture.set(gyroBmi160);
    
                                    Log.i(deviceMac, ": gyroscope configured");
    
                                    return gyroBmi160.packedAngularVelocity().addRouteAsync(
                                            source -> source.stream(gyroscopeHandler));
                                } else return null;
                            }
                    ).continueWith(
                            task -> {
                                final BarometerBosch barometerBosch = metaWearBoard.getModule(BarometerBosch.class);
    
                                if (null != barometerBosch) {
                                    barometerBosch.configure()
                                            .filterCoeff(BarometerBosch.FilterCoeff.AVG_16)
                                            .pressureOversampling(BarometerBosch.OversamplingMode.ULTRA_HIGH)
                                            .standbyTime(0.5f)
                                            .commit();
                                    barometerCapture.set(barometerBosch);
    
                                    Log.i(deviceMac, ": barometer configured");
    
                                    return barometerBosch.altitude().addRouteAsync(
                                            source -> source.stream(barometerHandler));
                                } else return null;
                            }
                    ).continueWith(
                            task -> {
                                Log.i(deviceMac, ": device connected");
                                isConnected = true;
                                return task;
                            });
        }
    
        private static Task<Void> reconnect(final MetaWearBoard board) {
            return board.connectAsync().continueWithTask(task -> task.isFaulted() ? reconnect(board) : task);
        }
    
  • Your issue probably has to do with the Android app life cycle. Long term data streaming should be moved to a background service.

  • Hey !
    I had the same issue. Did you manage to fix it?

This discussion has been closed.