CARP Data Backend

pub package style: effective dart github stars MIT License

This package integrates the CARP Mobile Sensing Framework with the CARP web service backend. It support downloading a study configuration and uploading collected data.

For Flutter plugins for other CARP products, see CARP Mobile Sensing in Flutter.

Using the Plugin

Add carp_backend as a dependency in your pubspec.yaml file and import the library along with the carp_mobile_sensing library.

import 'package:carp_mobile_sensing/carp_mobile_sensing.dart';
import 'package:carp_backend/carp_backend.dart';

Downloading a study configuration from CARP

Getting a study configuration from CARP is done using a CarpStudyManager. But in order to authenticate to CARP and get the available studies for the user, we make use of the carp_webservices API.

To get a study, you basically go through the following steps:

  1. Create and configure a CarpApp that points to the correct CARP web service.
  2. Authenticate to the CARP web service
  3. Get the list of study invitations for the authenticated user.
  4. Get a specific study via a CarpStudyManager

The following code illustrates how this is done:

  final String uri = "";

  // configure an app that points to the CARP web service
  CarpApp app = CarpApp(
    name: 'any_display_friendly_name_is_fine',
    uri: Uri.parse(uri),
    oauth: OAuthEndPoint(
      clientID: 'the_client_id',
      clientSecret: 'the_client_secret',

  // authenticate at CARP
  await CarpService()
      .authenticate(username: 'the_username', password: 'the_password');

  // get the invitations to studies from CARP for this user
  List<ActiveParticipationInvitation> invitations =
      await CarpService().invitations();

  // use the first (i.e. latest) invitation
  String studyDeploymentId = invitations[0].studyDeploymentId;

  // create a study manager, and initialize it
  CarpStudyManager manager = CarpStudyManager();
  await manager.initialize();

  // get the study from CARP
  Study study = await manager.getStudy(studyDeploymentId);
  print('study: $study');

Uploading of data to CARP

Upload of sensing data to the CARP web service can be done in four different ways:

  • as individual CARP data points
  • as a batch upload of a file with multiple CARP data points
  • as a CARP object in a collection
  • as a file to the CARP file store

Using the library takes three steps.

1. Register the Data Manager

First you should register the data manager in the DataManagerRegistry.

  DataManagerRegistry().register(DataEndPointType.CARP, CarpDataManager());

2. Create a CARP Data Endpoint

Create a CarpDataEndPoint that specify which method to use for uploading data, and the details. Upload methods are defined in the CarpUploadMethod class.

For example, a CarpDataEndPoint that upload data points directly looks like this:

  CarpDataEndPoint cdep = CarpDataEndPoint(CarpUploadMethod.DATA_POINT,
      name: 'CARP Staging Server',
      uri: '',
      clientId: 'carp',
      clientSecret: 'a_secret',
      email: '',
      password: 'password');

A CarpDataEndPoint that uploads data as zipped files and keeps the file on the phone, looks like this:

  CarpDataEndPoint cdep = CarpDataEndPoint(CarpUploadMethod.FILE,
      name: 'CARP Staging Server',
      uri: '',
      clientId: 'carp',
      clientSecret: 'a_secret',
      email: '',
      password: 'password',
      bufferSize: 500 * 1000,
      zip: true);

And a CarpDataEndPoint that batch uploads data points in a json file (which is deleted when uploaded) looks like this:

  CarpDataEndPoint cdep = CarpDataEndPoint(
    name: 'CARP Staging Server',
    uri: '',
    clientId: 'carp',
    clientSecret: 'a_secret',
    email: '',
    password: 'password',
    bufferSize: 500 * 1000,
    deleteWhenUploaded: true,

3. Assign the CARP Data Endpoint to your Study

To use the CARP Data Endpoint in you study, assign it to the study.

  Study study = new Study(
    id: '1234',
    userId: '',
    name: 'Test study #1234',
  study.dataEndPoint = cdep;

Features and bugs

Please file feature requests and bug reports at the issue tracker.


This software is copyright (c) Copenhagen Center for Health Technology (CACHET) at the Technical University of Denmark (DTU). This software is made available 'as-is' in a MIT license.