Use your own server
Already have somewhere to store data, like a hospital system, a company cloud or a simple web API? CARP can send measurements there instead.
The simple way: forward each measurement
Section titled “The simple way: forward each measurement”Remember client.measurements from the tutorial app? It hands
you every measurement the moment it’s collected. You can send each one to your
server’s web address as JSON (a common text format for data).
This is a sketch to show the idea, not production code. You need a server address that accepts the data, and usually some kind of login.
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, like this:
{ "sensorStartTime": 1790603452877534, "data": { "__type": "dk.cachet.carp.stepevent", "steps": 4213 }}sensorStartTime is when it was measured (microseconds since 1970), and __type
says what kind of data it is.
The proper way: a data manager
Section titled “The proper way: a data manager”For a real study, write a small data manager. It’s a class CARP calls for every measurement, so you can buffer data, retry when the network is back, and batch uploads. It plugs into CARP exactly like the built-in phone and CAWS options, so the protocol simply says “send data to my server”.
This is covered step by step in Extending CAMS → Adding a new data manager.