Skip to content
CARP Docs
Ask AISystemLightDark
On this page

Custom backend

Send CARP measurements to a server you already run, by forwarding each measurement or with a data manager.

Copy MarkdownOpen inOpen in GitHubView as MarkdownOpen in Scira AIOpen in ChatGPTOpen in ClaudeOpen in Cursor

If you already store data elsewhere, such as a hospital system, a company cloud or a web API, CARP can send measurements there instead.

Forward each measurement

client.measurements (see the quickstart) emits every measurement as soon as it is collected. You can post each one to your server as JSON.

This is a sketch of the approach, not production code. You need a server address that accepts the data, and usually some form of authentication.

flutter pub add http
// At the top of lib/main.dart:
import 'dart:convert';
import 'package:http/http.dart' as http;

// In _startSensing(), after client.resume():
client.measurements.listen((measurement) {
  http.post(
    Uri.parse('https://my-server.example.com/data'),
    headers: {'Content-Type': 'application/json'},
    body: jsonEncode(measurement),
  );
});

Each request body is one measurement:

{
  "sensorStartTime": 1790603452877534,
  "data": {
    "__type": "dk.cachet.carp.stepevent",
    "steps": 4213
  }
}
FieldMeaning
sensorStartTimeWhen the data was measured, in microseconds since 1970 (Unix epoch).
data.__typeThe kind of data.

Data loss

This approach loses data whenever sending fails, for example when the phone is offline or the server is down. Keep the default on-phone database as a backup, or use a data manager.

Use a data manager

For a study, write a data manager: a class that CARP calls for every measurement. In it you can buffer data, retry when the network is back, and batch uploads. A data manager plugs into CARP exactly like the built-in on-device and CAWS options, so the protocol's data endpoint simply points to your server.

See Extending CAMS: adding a new data manager for a step-by-step guide.

Run your own CAWS

Alternatively, run your own instance of CAWS. It is open source, and includes study management and participant invitations. See CARP Web Services.

Quick links

Page · DocumentationCARP DocumentationPage · DocumentationIntroductionPage · DocumentationQuickstartPage · DocumentationTerminologyPage · DocumentationArchitecture