For the complete documentation index, see llms.txt. This page is also available as Markdown.

Flutter

Once you've started receiving data from a device into your app, you can start sending this data to Terra's websocket server.

Prerequisite

Before following the steps below, make sure you've followed the guide to stream data from a wearable device to your app

Streaming to Terra's Server

You'll have previously set up a local stream using startRealtimeToApp. To send data to Terra's server instead, use startRealtimeToServer with a streaming token:

import 'package:terra_flutter_rt/terra_flutter_rt.dart';
import 'package:terra_flutter_rt/types.dart';

Future<void> startServerStreaming() async {
  // 1. Get the Terra user ID
  final userId = await TerraFlutterRt.getUserId();
  if (userId == null) return;

  // 2. Get a streaming token from your backend
  final token = await fetchStreamingTokenFromBackend(userId);

  // 3. Start streaming to Terra's server
  await TerraFlutterRt.startRealtimeToServer(
    Connection.ble,
    [DataType.heartRate, DataType.steps],
    token,
  );
}

Flutter has separate functions for local vs server streaming:

  • startRealtimeToApp — streams to a local callback only (no server)

  • startRealtimeToServer — streams to Terra's websocket server only (no local callback)

To receive data both locally and on your server, call startRealtimeToApp for the local callback and have your backend consume from the Terra websocket.

Your backend should generate the streaming token by calling:

Stream - Generate user token

post

Generates a single-use token for a user (producer) connection. The id identifies the user the token is scoped to — a v6 connection id or a v5 compatibility user UUID — and must belong to the authenticating developer.

Authorizations
x-api-keystringRequired

Your API key for authentication

dev-idstringRequired

Your developer ID for authentication and tracking

Query parameters
idstringRequired

The id of the user to generate a token for.

Responses
200

Token generated.

application/json
tokenstringRequired

Single-use token to present in the IDENTIFY frame.

Example: OTYwNWFi5ZWQMTAxMjg0Y2Qw.gzrPzZcS3Gy8QDOxbiPRwu30PTB3VxW0eE
post/auth/user
POST /auth/user?id=text HTTP/1.1
Host: ws.tryterra.co
x-api-key: YOUR_API_KEY
dev-id: YOUR_API_KEY
Accept: */*
{
  "token": "OTYwNWFi5ZWQMTAxMjg0Y2Qw.gzrPzZcS3Gy8QDOxbiPRwu30PTB3VxW0eE"
}

Last updated

Was this helpful?