Closed sc00n closed 2 years ago
The following also doesn't work:
Measure loc =Measure(type: ContextSamplingPackage.GEOLOCATION)..overrideSamplingConfiguration = PeriodicSamplingConfiguration(
interval: const Duration(seconds: 2),
duration: const Duration(seconds: 1),
);
What did work for me was using
LocationService locationService = LocationService(interval: Duration(seconds: 10));
pedometer also kind of shoots with every step. DeviceSamplingPackage.DEVICE I still have to figure out. In general I like it more when I can just use an interval (e.g. every 10 seconds) to measure something. This is mainly because of the gaps and the app being killed. If I have no information I don't know if nothing happened or the app was just killed.
I think there is just in general something wrong with the interval trigger. Also the following doesnt work while it is one of the examples in the example app (I only changed the duration for testing purposes).
protocol.addTriggeredTask(
IntervalTrigger(period: Duration(seconds: 5)),
BackgroundTask()
..addMeasure(Measure(type: ContextSamplingPackage.WEATHER)),
weatherService);
When I use interval trigger it works for a few seconds and then it stops. For example when I have the following code in local_study_protocol_managaer.dart:
protocol.addTriggeredTask( IntervalTrigger(period: Duration(milliseconds: 300)), BackgroundTask() ..addMeasure(Measure(type: SensorSamplingPackage.PEDOMETER)), phone);
I get the following output:
So I have output for a few seconds, and then it completely stops.
The IntervalTrigger
is intended to be used when sampling a single piece of measure - the so-called "One Time" (OT)measure. This is in contrast to the measure which are "Event Based" (EB). In the overview of measures, you can see which measures are OT and EB.
Since the PEDOMETER
measure is a EB, it does not make sense to use an IntervalTrigger
- this measure collect a step count event each time "some" steps are detected by the phone (when this happens depends on the phone and its step counter hardware). Hence, a PEDOMETER
measure should be triggered always (ImmediateTrigger
) or - if you want it to happen with a interval - you can use a PeriodicTrigger which runs periodically with a fixed period.
However, it does not make sense to collect step count on such a short time window ( 300 milliseconds) -- the user will not be able to take any steps in such a short timeframe. So - I would make something like:
protocol.addTriggeredTask(
PeriodicTrigger(period: Duration(minutes: 30), duration: Duration(minutes: 10),
BackgroundTask()
..addMeasure(Measure(type: SensorSamplingPackage.PEDOMETER)),
phone);
which would collect step counts for 10 minutes every half hour.
The same holds for when I use the intervaltrigger with ContextSamplingPackage.LOCATION or DeviceSamplingPackage.DEVICE . The app is still open and I see no errors. I used the example app from GitHub.
I think the problem here is that the sampling time is extremely short - 300 miliseconds - the GPS will never be able to collect any location data in such a short time frame
pedometer also kind of shoots with every step
Yes - this is how this sensor works on most phones.
I think there is just in general something wrong with the interval trigger. Also the following doesnt work while it is one of the examples in the example app (I only changed the duration for testing purposes).
protocol.addTriggeredTask( IntervalTrigger(period: Duration(seconds: 5)), BackgroundTask() ..addMeasure(Measure(type: ContextSamplingPackage.WEATHER)), weatherService);
Note that in order to use the Open Weather web service, you need a API key. See the README file for documentation of this. You can also look at the example to see how a WeatherService
is created and added to the protocol.
Thank you for your replies!
I'll start with your last reply. The problem is that it works once (showing that the API is correctly connected) and then stops. I used exactly the code from the example, with a filled in API key:
// Define the online weather service and add it as a 'device'
WeatherService weatherService =
WeatherService(apiKey: '066c4ff8fe6a59b17da65a3f96544b80');
protocol.addConnectedDevice(weatherService);
// Add a background task that collects weather every 30 miutes.
protocol.addTriggeredTask(
IntervalTrigger(period: Duration(seconds: 5)),
BackgroundTask()
..addMeasure(Measure(type: ContextSamplingPackage.WEATHER)),
weatherService);
With location the following code doesn't work. It again works once (one output), and then stops.
LocationService locationService = LocationService();
protocol.addConnectedDevice(locationService);
// Add a background task that collects location on a regular basis
protocol.addTriggeredTask(
IntervalTrigger(period: Duration(seconds: 15)),
BackgroundTask()
..addMeasure(Measure(type: ContextSamplingPackage.LOCATION)),
locationService);
The following however does work (using geolocation and setting interval in location service):
LocationService locationService = LocationService(interval: Duration(seconds: 15));
protocol.addConnectedDevice(locationService);
// Add a background task that collects location on a regular basis
protocol.addTriggeredTask(
ImmediateTrigger(),
BackgroundTask()
..addMeasure(Measure(type: ContextSamplingPackage.LOCATION)),
locationService);
Showing that 15 seconds is not too fast to sample but that the IntervalTrigger somehow fails. So for location, it doesn't really matter if IntervalTrigger doesn't work as there is a work around. This can however not be used to the weather measure or others.
I also tried CONNECTIVITY and APP_USAGE (other OT). They all give one measurement and then stop.
Steps to reproduce:
LocationService locationService = LocationService();
protocol.addConnectedDevice(locationService);
// Add a background task that collects location on a regular basis
protocol.addTriggeredTask(
IntervalTrigger(period: Duration(seconds: 15)),
BackgroundTask()
..addMeasure(Measure(type: ContextSamplingPackage.LOCATION)),
locationService);
return protocol;
I then get the following output after a couple of minutes:
As you can see location is only measured once. As permission was not given in time, the location data is also not filled in. When I restart the app I again get one measurement, but now permission was given in time so it is filled in:
I have the same problem with other OT measurements, they all result in one measurement and then stop.
I reproduced this problem uses the steps above on a Xiaomi Mi 10T (Android 11) Lite and also found it only ran once. Additionally, I got a warning:
2022-11-16 13:04:45.242 8964-8994/dk.cachet.carp_mobile_sensing_app I/flutter: [CAMS INFO] Pausing BackgroundTaskExecutor
2022-11-16 13:04:45.243 8964-8994/dk.cachet.carp_mobile_sensing_app I/flutter: [CAMS INFO] Pausing LocationProbe
2022-11-16 13:04:47.285 8964-8994/dk.cachet.carp_mobile_sensing_app I/flutter: [CAMS INFO] Pausing LocationProbe
2022-11-16 13:04:47.285 8964-8994/dk.cachet.carp_mobile_sensing_app I/flutter: [CAMS WARNING] Trying to pause a LocationProbe in a state where this cannot be done - state: ExecutorState.paused
I also made sure all permissions were given and battery optimisation was disabled. I then restarted to app to start in a clean slate but the behaviour was the same. Pausing and then restarting sensing (by using the green button in the app) again produced a single measurement.
I've just found that the same problem applies for the PeriodicTriggerExecutor
... will fix it now.
Has been fixed now - released as version 0.40.5
When I use interval trigger it works for a few seconds and then it stops. For example when I have the following code in local_study_protocol_managaer.dart:
I get the following output:
Output
``` Performing hot restart... Restarted application in 1.058ms. I/flutter (16264): [CAMS INFO] Time zone set to Europe/Brussels I/flutter (16264): [CAMS INFO] Settings initialized I/flutter (16264): [CAMS INFO] SensingBLoC initialized I/flutter (16264): [CAMS INFO] Initializing Sensing - mode: DeploymentMode.LOCAL I/flutter (16264): =========================================================== I/flutter (16264): CARP Mobile Sensing (CAMS) - SmartPhoneClientManager I/flutter (16264): =========================================================== I/flutter (16264): deployment service : SmartphoneDeploymentService I/flutter (16264): device controller : DeviceController [6] I/flutter (16264): device ID : SP1A.210812.016 I/flutter (16264): available devices : (Smartphone, LocationService, AirQualityService, ..., PolarDevice, ESenseDevice) I/flutter (16264): =========================================================== I/flutter (16264): [CAMS INFO] Adding study to SmartPhoneClientManager - Study - studyDeploymentId: asdf222, deviceRoleName: masterphone I/flutter (16264): SmartphoneDeploymentController - Study deployment 'asdf222' successfully deployed. I/flutter (16264): [CAMS INFO] Saving deployment to file '/data/user/0/dk.cachet.carp_mobile_sensing_app/app_flutter/carp/deployments/asdf222/deployment.json'. I/flutter (16264): [CAMS INFO] Configuring SmartphoneDeploymentController I/flutter (16264): [CAMS INFO] Initializing device manager, type: dk.cachet.carp.protocols.domain.devices.Smartphone, descriptor.: Smartphone - roleName: masterphone, isMasterDevice: true I/flutter (16264): [CAMS DEBUG] SmartphoneDeviceManager - setting device status: DeviceStatus.initialized I/flutter (16264): [CAMS INFO] AppTaskController - Restoring task queue from file '/data/user/0/dk.cachet.carp_mobile_sensing_app/app_flutter/carp/tasks.json'. I/flutter (16264): [CAMS INFO] AwesomeNotificationController initialized. I/flutter (16264): [CAMS INFO] Asking for permission for all measure types. D/permissions_handler(16264): Bluetooth permission missing in manifest I/flutter (16264): [CAMS INFO] Permissions for Permission.location : PermissionStatus.granted I/flutter (16264): [CAMS INFO] Permissions for Permission.bluetoothScan : PermissionStatus.granted I/flutter (16264): [CAMS INFO] Permissions for Permission.locationAlways : PermissionStatus.granted I/flutter (16264): [CAMS INFO] Permissions for Permission.activity_recognition : PermissionStatus.granted I/flutter (16264): [CAMS INFO] Permissions for Permission.microphone : PermissionStatus.granted I/flutter (16264): [CAMS INFO] Permissions for Permission.camera : PermissionStatus.granted D/permissions_handler(16264): Bluetooth permission missing in manifest I/flutter (16264): [CAMS INFO] Permissions for Permission.bluetooth : PermissionStatus.denied I/flutter (16264): [CAMS INFO] Permissions for Permission.bluetoothConnect : PermissionStatus.granted I/flutter (16264): [CAMS INFO] Initializing SQLiteDataManager... I/flutter (16264): [CAMS DEBUG] SQLiteDataManager - SQLite DB created I/flutter (16264): [CAMS INFO] SQLite DB file path : /data/user/0/dk.cachet.carp_mobile_sensing_app/databases/carp-data-2022-11-12-10-11-27-934492Z.db I/flutter (16264): [CAMS INFO] SmartphoneDeviceManager - Trying to connect to device of type: dk.cachet.carp.protocols.domain.devices.Smartphone and id: SP1A.210812.016 I/flutter (16264): [CAMS DEBUG] SmartphoneDeviceManager - setting device status: DeviceStatus.connected I/flutter (16264): [CAMS INFO] SmartphoneDeviceManager - Trying to connect to device of type: dk.cachet.carp.protocols.domain.devices.Smartphone and id: SP1A.210812.016 I/flutter (16264): [CAMS DEBUG] SmartphoneDeviceManager - setting device status: DeviceStatus.connected I/flutter (16264): [CAMS INFO] SmartphoneDeviceManager - Trying to connect to device of type: dk.cachet.carp.protocols.domain.devices.Smartphone and id: SP1A.210812.016 I/flutter (16264): [CAMS DEBUG] SmartphoneDeviceManager - setting device status: DeviceStatus.connected I/flutter (16264): [CAMS INFO] SmartphoneDeviceManager - Trying to connect to device of type: dk.cachet.carp.protocols.domain.devices.Smartphone and id: SP1A.210812.016 I/flutter (16264): [CAMS DEBUG] SmartphoneDeviceManager - setting device status: DeviceStatus.connected I/flutter (16264): [CAMS INFO] SmartphoneDeviceManager - Trying to connect to device of type: dk.cachet.carp.protocols.domain.devices.Smartphone and id: SP1A.210812.016 I/flutter (16264): [CAMS DEBUG] SmartphoneDeviceManager - setting device status: DeviceStatus.connected I/flutter (16264): [CAMS INFO] SmartphoneDeviceManager - Trying to connect to device of type: dk.cachet.carp.protocols.domain.devices.Smartphone and id: SP1A.210812.016 I/flutter (16264): [CAMS DEBUG] SmartphoneDeviceManager - setting device status: DeviceStatus.connected I/flutter (16264): [CAMS INFO] Initializing StudyDeploymentExecutor - configuration: SmartphoneDeployment - studyDeploymentId: asdf222, device: masterphone, title: CAMS App - Sensing Coverage Study, responsible: Alex B. Christensen, deployment: SmartphoneDeployment - studyDeploymentId: asdf222, device: masterphone, title: CAMS App - Sensing Coverage Study, responsible: Alex B. Christensen I/flutter (16264): [CAMS INFO] Initializing TriggeredTaskExecutor - configuration: TriggeredTask - triggerId: 0, task: Task #5, targetDeviceRoleName: masterphone, deployment: SmartphoneDeployment - studyDeploymentId: asdf222, device : masterphone, title: CAMS App - Sensing Coverage Study, responsible: Alex B. Christensen I/flutter (16264): [CAMS INFO] Initializing IntervalTriggerExecutor - configuration: Instance of 'IntervalTrigger', deployment: SmartphoneDeployment - studyDeploymentId: asdf222, device: masterphone, title: CAMS App - Sensing Covera ge Study, responsible: Alex B. Christensen I/flutter (16264): [CAMS INFO] Initializing BackgroundTaskExecutor - configuration: BackgroundTask - name: Task #5, measures size: 1, deployment: SmartphoneDeployment - studyDeploymentId: asdf222, device: masterphone, title: CAMS Ap p - Sensing Coverage Study, responsible: Alex B. Christensen I/flutter (16264): [CAMS INFO] Initializing PedometerProbe - configuration: Measure - type: dk.cachet.carp.pedometer, deployment: SmartphoneDeployment - studyDeploymentId: asdf222, device: masterphone, title: CAMS App - Sensing Cove rage Study, responsible: Alex B. Christensen I/flutter (16264): =============================================================== I/flutter (16264): CARP Mobile Sensing (CAMS) - SmartphoneDeploymentController I/flutter (16264): =============================================================== I/flutter (16264): deployment id : asdf222 I/flutter (16264): deployed time : 2022-11-12 11:11:27.848311 I/flutter (16264): user id : 04dcd470-626a-11ed-99e1-097a86af6173 I/flutter (16264): platform : Android I/flutter (16264): device ID : SP1A.210812.016 I/flutter (16264): data manager : SQLiteDataManager I/flutter (16264): data endpoint : SQLiteDataEndPoint - type: SQLITE, dataFormat: dk.cachet.carp I/flutter (16264): status : Deployed I/flutter (16264): =============================================================== I/flutter (16264): [CAMS INFO] Starting data sampling ... I/flutter (16264): END OF STAAAAAAART I/flutter (16264): [CAMS INFO] Sensing initialized I/ViewRootImpl@f29f95e[MainActivity](16264): ViewPostIme pointer 0 I/ViewRootImpl@f29f95e[MainActivity](16264): ViewPostIme pointer 1 I/flutter (16264): [CAMS INFO] Resuming StudyDeploymentExecutor I/flutter (16264): [CAMS INFO] Resuming TriggeredTaskExecutor I/flutter (16264): [CAMS INFO] Resuming IntervalTriggerExecutor I/flutter (16264): [CAMS INFO] Resuming BackgroundTaskExecutor I/flutter (16264): [CAMS INFO] Resuming PedometerProbe D/SensorManager(16264): registerListener :: 191, step_counter Non-wakeup, 0, 0, I/flutter (16264): { I/flutter (16264): "carp_header": { I/flutter (16264): "study_id": "asdf222", I/flutter (16264): "device_role_name": "masterphone", I/flutter (16264): "trigger_id": "0", I/flutter (16264): "user_id": "04dcd470-626a-11ed-99e1-097a86af6173", I/flutter (16264): "start_time": "2022-11-12T10:11:30.474651Z", I/flutter (16264): "data_format": { I/flutter (16264): "namespace": "dk.cachet.carp", I/flutter (16264): "name": "pedometer" I/flutter (16264): } I/flutter (16264): }, I/flutter (16264): "carp_body": { I/flutter (16264): "id": "6097ac60-6272-11ed-a5c8-83045561948c", I/flutter (16264): "timestamp": "2022-11-12T10:11:30.470122Z", I/flutter (16264): "step_count": 33339 I/flutter (16264): } I/flutter (16264): } I/flutter (16264): [CAMS DEBUG] SQLiteDataManager - writing data point to SQLite - id: 1, type: dk.cachet.carp.pedometer I/flutter (16264): [CAMS INFO] Resuming BackgroundTaskExecutor I/flutter (16264): [CAMS INFO] Resuming PedometerProbe D/SensorManager(16264): unregisterListener D/SensorManager(16264): registerListener :: 191, step_counter Non-wakeup, 0, 0, I/flutter (16264): { I/flutter (16264): "carp_header": { I/flutter (16264): "study_id": "asdf222", I/flutter (16264): "device_role_name": "masterphone", I/flutter (16264): "trigger_id": "0", I/flutter (16264): "user_id": "04dcd470-626a-11ed-99e1-097a86af6173", I/flutter (16264): "start_time": "2022-11-12T10:11:31.470726Z", I/flutter (16264): "data_format": { I/flutter (16264): "namespace": "dk.cachet.carp", I/flutter (16264): "name": "pedometer" I/flutter (16264): } I/flutter (16264): }, I/flutter (16264): "carp_body": { I/flutter (16264): "id": "613042e0-6272-11ed-b646-ad59d42c6d61", I/flutter (16264): "timestamp": "2022-11-12T10:11:31.470129Z", I/flutter (16264): "step_count": 33339 I/flutter (16264): } I/flutter (16264): } I/flutter (16264): [CAMS DEBUG] SQLiteDataManager - writing data point to SQLite - id: 2, type: dk.cachet.carp.pedometer I/flutter (16264): [CAMS INFO] Resuming BackgroundTaskExecutor I/flutter (16264): [CAMS INFO] Resuming PedometerProbe D/SensorManager(16264): unregisterListener D/SensorManager(16264): registerListener :: 191, step_counter Non-wakeup, 0, 0, I/flutter (16264): { I/flutter (16264): "user_id": "04dcd470-626a-11ed-99e1-097a86af6173", I/flutter (16264): "start_time": "2022-11-12T10:11:32.467803Z", I/flutter (16264): "data_format": { I/flutter (16264): "namespace": "dk.cachet.carp", I/flutter (16264): "name": "pedometer" I/flutter (16264): } I/flutter (16264): }, I/flutter (16264): "carp_body": { I/flutter (16264): "id": "61c86430-6272-11ed-b223-1b4b39d8795f", I/flutter (16264): "timestamp": "2022-11-12T10:11:32.467102Z", I/flutter (16264): "step_count": 33339 I/flutter (16264): } I/flutter (16264): } I/flutter (16264): [CAMS DEBUG] SQLiteDataManager - writing data point to SQLite - id: 3, type: dk.cachet.carp.pedometer I/flutter (16264): [CAMS INFO] Resuming BackgroundTaskExecutor I/flutter (16264): [CAMS INFO] Resuming PedometerProbe D/SensorManager(16264): unregisterListener I/flutter (16264): [CAMS INFO] Pausing BackgroundTaskExecutor I/flutter (16264): [CAMS INFO] Pausing PedometerProbe D/SensorManager(16264): registerListener :: 191, step_counter Non-wakeup, 0, 0, D/SensorManager(16264): unregisterListener I/flutter (16264): [CAMS INFO] Pausing BackgroundTaskExecutor I/flutter (16264): [CAMS WARNING] Trying to pause a BackgroundTaskExecutor in a state where this cannot be done - state: ExecutorState.paused I/flutter (16264): [CAMS INFO] Pausing BackgroundTaskExecutor I/flutter (16264): [CAMS WARNING] Trying to pause a BackgroundTaskExecutor in a state where this cannot be done - state: ExecutorState.paused I/flutter (16264): [CAMS INFO] Pausing BackgroundTaskExecutor I/flutter (16264): [CAMS WARNING] Trying to pause a BackgroundTaskExecutor in a state where this cannot be done - state: ExecutorState.paused ```
So I have output for a few seconds, and then it completely stops. The same holds for when I use the intervaltrigger with ContextSamplingPackage.LOCATION or DeviceSamplingPackage.DEVICE . The app is still open and I see no errors. I used the example app from GitHub.