0 purchases
terra flutter rt
terra_flutter_rt #
A new flutter plugin project.
Getting Started #
This project is a starting point for a Flutter
plug-in package,
a specialized package that includes platform-specific implementation code for
Android and/or iOS.
For help getting started with Flutter, view our
online documentation, which offers tutorials,
samples, guidance on mobile development, and a full API reference.
Using the package #
The Terra Real Time package offers the capability to stream data either in your app directly using a callback function, or to your server using websockets.
Import the package in your app file:
import 'package:terra_flutter_rt/terra_flutter_rt.dart';
import 'package:terra_flutter_rt/types.dart';
import 'package:terra_flutter_rt/ios_controller.dart';
copied to clipboard
The first line is for all the functionality. The types are for the different data types (connections, requested data types, and received data type). The iOS controller is for the iOS scanning controller UI.
Everytime your app opens, you need to initialise the library:
await TerraFlutterRt.init(devId, "reference_id");
copied to clipboard
The first time ever you want to use the package, you need to register the device with Terra using initConnection. You can generate an SDK token from here using your Terra dev credentatials:
await TerraFlutterRt.initConnection(sdktoken);
copied to clipboard
and then get the user id using getUserId
const userId = await TerraFlutterRt.getUserId();
copied to clipboard
The packages support streaming from the following wearable types:
enum Connection { ble, apple, wearOs, android, ant }
copied to clipboard
and supports streaming the following data types:
enum DataType {
heartRate,
ecg,
steps,
hrv,
calories,
location,
speed,
distance,
stepsCadence,
floorsClimbed,
gyroscope,
acceleration
}
copied to clipboard
An example using a connection and a set of data to be streamed:
const connection = Connection.ble;
const datatypes = [DataType.heartRate];
copied to clipboard
For BLE connections and ANT+, you can pull a scanning UI for the user to select a device:
if (connection == Connection.ble ||
connection == Connection.wearOs ||
connection == Connection.ant ||
connection == Connection.allDevices) {
await TerraFlutterRt.startDeviceScan(connection);
}
copied to clipboard
you can optionally cache the devices. If set to true, this options will not pull the scan screen if one of the cached devices is found:
await TerraFlutterRt.startDeviceScan(connection, useCache: true);
copied to clipboard
With the device and dataypes set, you can now start streaming. To stream locally in your app directly, you can pass a callback function that will get triggered with the data:
void dataCallback(Update data) {
print("Got data in app");
print(data.ts);
print(data.type.datatypeString);
print(data.val);
print(data.d);
}
// .......
await TerraFlutterRt.startRealtimeToApp(connection, datatypes, dataCallback);
copied to clipboard
Example payloads:
{"val":86,"type":"HEART_RATE","ts":"2022-10-24T09:15:25Z"}
{"d":[1.373291015625E-4,-3.96728515625E-4,-1.068115234375E-4],"ts":"2022-10-24T09:20:27.985Z","type":"GYROSCOPE"}
copied to clipboard
To stream to your server using Websockets, you need a websocket token generated from here:
await TerraFlutterRt.startRealtimeToServer(connection, datatypes, websockettoken);
copied to clipboard
Example payloads:
{"op":5,"d":{"ts":"2022-10-24T09:18:27.729Z","val":83.0},"uid":"66fbb25f-e1d2-44d1-bc4d-6b4844bd0928","seq":16073,"t":"HEART_RATE"}
{"op":5,"d":{"d":[0.0049285888671875,-3.662109375E-4,-2.899169921875E-4],"ts":"2022-10-24T09:19:06.328Z"},"uid":"66fbb25f-e1d2-44d1-bc4d-6b4844bd0928","seq":16088,"t":"GYROSCOPE"}
copied to clipboard
Finally, you can stop streaming and disconnect the device on command:
await TerraFlutterRt.stopRealtime(connection);
await TerraFlutterRt.disconnect(connection);
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.