Using CAMS
Define a study protocol, deploy it, run sampling with the client manager and consume the collected measurements.
This page describes the runtime flow of CARP Mobile Sensing (CAMS). Complete the installation first.
CAMS can run fully local on the device, including protocol creation and deployment. The flow is:
- Define a study protocol with the triggers, tasks, devices and measures to collect.
- Deploy the protocol to a local or remote
DeploymentService, such asSmartphoneDeploymentService, to create a study deployment (optional). - Configure the client manager, then add and deploy the study.
- Resume or pause data sampling for all studies or for each study.
- Consume or save the collected measurements from the
measurementsstream of one or more studies.
Define a study protocol
In CAMS, sensing is configured in a SmartphoneStudyProtocol. Create one with the Dart API directly in your app:
This protocol collects steps, ambient light, and screen and battery events from the phone, and stores them in the local SQLite database. Data sampling starts after a delay of 10 seconds.
Local protocols
Use the SmartphoneStudyProtocol.local constructor for a local protocol that:
- only collects simple measures in the background
- only uses the phone as a device
- only has one participant
- stores data locally in the SQLite database
Related
- Domain model and Measure types describe protocols and measures in detail.
- Data transformation and privacy describes transformation formats and privacy schemas.
Deploy the protocol
This step is optional. A study protocol is deployed through a DeploymentService:
Configure the client manager
The client manager SmartPhoneClientManager handles the runtime management of studies. It is a singleton, so you can always access it with SmartPhoneClientManager().
The simplest configuration is:
configure() accepts these options:
| Option | Description |
|---|---|
registration | Unique device registration for this phone. |
deploymentService | Deployment backend. Default: the local SmartphoneDeploymentService. |
dataCollectorFactory | Custom collector factory. Default: the standard DeviceController. |
enableNotifications | Show task notifications. Default: true. |
enableBackgroundMode | Run sampling in the background. Default: true. Android only. |
backgroundNotificationTitle, backgroundNotificationText | Text for the Android background notification. |
askForPermissions | Request package permissions automatically. Default: true. |
Tip
Set askForPermissions: false when your app needs a custom permission flow or staged consent screens.
Add and deploy studies
To deploy a study on the client, get a study deployment from the deployment service, based on the protocol. Configure the client to use this deployment service, then add and deploy the study:
With the local SmartphoneDeploymentService, you can write this more compactly with addStudyFromProtocol:
The same flow as a single statement:
The client manager can handle multiple studies. Add each one to the client:
Control data sampling
Control data sampling with the resume and pause methods:
Calling resume() or pause() on the client manager resumes or pauses all studies added to the client. For fine-grained control, use the SmartphoneStudyController of each study:
Stop a study and dispose the client
stopStudy permanently stops a study. A stopped study cannot be started again. Call dispose to dispose of the client, typically in the Flutter dispose method.
Run a single local protocol
To run just one local protocol, configure, add, deploy and resume in one statement:
Consume measurements
All sampled data is available in the measurements stream, on both the client and each study controller:
measurements is a standard Dart Stream, so you can subscribe to, filter and map it as needed:
Next steps
- Store or upload measurements with a data manager.
- Involve the user in sampling with the app task model.
- Keep sampling running in the background: see Best practices.