cph-cachet / carp.sensing-flutter

CARP Mobile Sensing for Flutter, including mobile sensing framework, data backend support, and the CARP mobile sensing app.
MIT License
80 stars 28 forks source link

Problems changing protocols #333

Closed sc00n closed 7 months ago

sc00n commented 1 year ago

Similarly to https://github.com/cph-cachet/carp.sensing-flutter/issues/292 I again try to change the protocol on the fly, while the app is running. Newly added sensors are indeed working, but removed sensors unfortunately also keep working.

I first stop everything going on:

await controller?.remove();
await controller?.stop();
await SmartPhoneClientManager().removeStudy(study!);

Then I just create the study again with new protocol newProtocol and start it:

  // Use the local, phone-based deployment service.
    deploymentService = SmartphoneDeploymentService();

    // Deploy this protocol using the on-phone deployment service.
    // Reuse the study deployment id, if this is stored on the phone.
    _status = await SmartphoneDeploymentService().createStudyDeployment(
      newProtocol,
      [],
      bloc.studyDeploymentId,
    );

    // Save the correct deployment id on the phone for later use.
    bloc.studyDeploymentId = _status?.studyDeploymentId;
    bloc.deviceRolename = _status?.primaryDeviceStatus?.device.roleName;

    // Configure the client manager with the deployment service selected above
    // (local or CAWS), add the study, and deploy it.
    await SmartPhoneClientManager().configure(
      deploymentService: deploymentService,
      askForPermissions: false,
    );

    study = await SmartPhoneClientManager().addStudy(
      bloc.studyDeploymentId!,
      bloc.deviceRolename!,
    );

    // SmartPhoneClientManager().addStudyProtocol(protocol);

    await controller?.tryDeployment(useCached: false);
    await controller?.configure();

    // Listen on the measurements stream and print them as json.
    SmartPhoneClientManager()
        .measurements
        .listen((measurement) => print(toJsonString(measurement)));

This was done in a new function in sensing.dart in the example app.

When I print the probes with print(runningProbes); from sensing_bloc.dart I get the correct probes that I added in the newProtocol. However, as I also print the sensor output using print(toJsonString(measurement)), I see that the old sensors are still running. Also the new sensors from newProtocol are working, but the old ones that were removed in newProtocol still generate data.

There is one special case: if the newProtocol has no sensors at all, this is correctly implemented and no sensors generate data.