Real-Time Data Streaming Using Terra SDK

Terra SDK is your gateway to a world of possibilities in health and wellness technology. In an era where data and technology are at the forefront of our lives, Terra SDK has become a powerful tool for developers. It simplifies health data integration, ensuring the utmost security and privacy while enabling real-time data streaming from wearable devices to applications. Join us as we explore the benefits and innovations that Terra SDK brings to the forefront of health and wellness app development.

What is Terra?

It provides APIs and a mobile SDK to connect your app to your user’s wearable. Terra provides a quick and simple way to connect your application to your users’ wearable data. Terra also works well with fitness applications.

Supported Wearables by Terra SDK: Terra supports connection to Bluetooth Low Energy and ANT+ devices.

Benefits of Using the Terra SDK

🔸 One API, Any Health Data: A one-time implementation facilitates the integration of devices and can be reused multiple times through the created API and SDK. These APIs or SDKs enable the retrieval of various types of health data.

🔸 SDK/API Created for Developers, By Developers:

  • Terra API and SDKs allow users to build great products and services in a fast and easy way.
  • As device integration is already done within the SDK, you need to write just a few lines of code to implement Terra.
  • Products provided by them are engineered and optimized in such a way that they fulfil the needs and desires of developers.
    • Faster to implement.
    • Multiple integrations.
    • Get started in less time with a few lines of code.

🔸 Trusted & Secure: It’s secured with end-to-end encryption, so your information (i.e. health-related data) is handled anonymously with end-to-end encryption.

🔸 Health Metrics: Terra provides health metrics, including heart rate, steps, sleep data, and more.

🔸 Everything is Given in One Kit: As everything is implemented and accessed using Terra’s API and SDK, It saves your time on implementing something that is already done.

Terra Integration

Health data for the users comes from different sources, such as Fitbit, Garmin, and Oura which are in different forms and developed using different technologies. Terra provides the resultant data in a structured manner, no matter the source.

It can be easily integrated with all the fitness and health wearable devices, sensors, and applications using a single API.

For more detailed information, you can visit the following link: Terra Integration

Real-Time Live Streaming

The Terra Streaming Protocol provides real-time streaming of wearable data. Terra provides a mobile SDK to stream health data directly to applications. It streams real-time data from the wearable to the application via BLE and ANT+ using the Terra SDK. Regardless of the sources, it streams data from the devices supporting Bluetooth Low Energy, ANT+, or from the phone itself.

Supported Devices for Real-Time Heart Rate Streaming: Heart rate monitors support devices such as Wahoo, Polar, Suunto, Garmin, and many others, or any devices that are equipped with BLE or ANT+ sensors, such as the WHOOP, Apple Watch, and many more.

Streaming Workflow

streaming workflow
Source: tryterra.co

As shown in the above streaming workflow, wearable devices are nothing but BLE-enabled devices that can stream data to the app and backend. Upon establishing a one-time connection between wearable devices and the app, it will start streaming data to the app and backend. You can start or stop streaming data at any time using the functions provided by the SDK once a connection has been established. The web socket here is responsible for the synchronization of data received locally in the app to the web server.

Discover Terra Integrations for Seamless Healthcare Automation

Streaming SDK Implementation

1. SDK Installation: The library is part of mavenCentral! Follow the steps to install,

  1. Open your project in Android Studio.
  2. Navigate to your project’s build.gradle file, located in the root directory of your project.
  3. Inside the dependencies section of the build.gradle file, add the following line of code, which will add the TerraAndroid SDK as a dependency to your project.

2. Obtain the Dev ID and the API Key: Head to the Terra dashboard and then Go to API > Customise, and you will get your API Key, Signing Secret, and Dev ID. They are used with the API used in Terra SDK, so keep them safe!

Terra Dashboard
Fig. Terra Dashboard

3. Usage: The package revolves mainly around a single class i.e. TerraRT

4. Initialize an instance of the class:

initialize an instance

Arguments:

  • BuildConfig.DEVID: Its developer ID is taken from the dashboard.
  • context: Context => The app context for which you call this function (usually from a class that extends from Activity types).
  • Reference ID: Static value.

5. Generate Auth Token: After initializing the class, the next step is to generate the auth token API, which needs a Dev ID and X-API key. We can get it from the try terra dashboard. You can refer to this document for details on implementing the auth token API.

6. Initialising Connections: After getting the auth token in the API response, you can initialize connections by passing the auth token as a parameter shown below,

initializing connections

Upon executing this initConnection function, all necessary permissions will be requested.

Arguments:

  • token => An authentication token that should be generated in your backend from the mobile SDK token endpoint.
  • callback => A function that is called when the initialisation is completed with a boolean which indicates if it’s successful or not.

7. Scanning Device: After establishing the connection to the device, you can now scan for devices including BLE and Wear OS (Bluetooth). It will show an in-built scan screen provided by the SDK. Scanning results will be displayed on that screen.

Scanning devices

Arguments:

  • connection: Connections => This argument takes a Connections enum, indicating the connection you wish to make. This includes BLE and Wear OS (Bluetooth) (Please check out our WearOS SDK for this!), etc. See the Connections Enum reference for a full list.
  • useCache parameter can be used if you wish to let the user simply connect to the previously connected device.

8. Data Streaming: You can now start streaming data after executing the startRealme function.

Data Streaming

Arguments:

  • connection: Connections => This argument takes a Connections enum, indicating the connection you wish to start realtime for
  • token: String => It’s an optional field. It’s needed for streaming User Token for authentication to Websocket API. This can be generated from the data Streaming User Token endpoint.
  • dataTypes: DataTypes => This argument takes a DataTypes enum indicating the datatype you wish to stream for.
coma

Conclusion

This article is helpful for developers who want to perform BLE integration and perform its different operations such as scanning, connecting devices to apps, and reading data from them. So this SDK will help you have implementations of several different kinds of devices that have BLE and support data streaming that can be implemented using a single SDK. So you don’t have to do multiple implementations for multiple devices; instead, can use a single SDK and use it for the implementation of multiple devices.

Keep Reading

Keep Reading

Struggling with EHR integration? Learn about next-gen solutions in our upcoming webinar on Mar 6, at 11 AM EST.

Register Now

Let's create something together!