< Blogs
Elliott

Elliott

July 28, 2022

How-tos: ANT+ Devices

When people think about connections between "activity trackers", or wearables and devices, they usually think about Bluetooth or Bluetooth Low Energy. However, there exists another communication protocol that is actually very commonly used in the fitness world. This is the ANT protocol.

What is it

In its essence, ANT is just a communication method between two devices similar to Bluetooth Low Energy (BLE), except that ANT typically does one-way communication whereas BLE does two-way connections. In addition to this, ANT uses way less energy and can connect many devices at once whereas BLE is usually limited to only a couple of devices.

ANT+ on the other hand are device profiles that follow the ANT protocol and defines the type of information transferred by that profile. For example, there is a device profile for Heart Rate monitors which is specified to only broadcast Heart Rate data. There are also ones for bike speed sensors, bike cadence sensors, and more.

ANT+ Connections Basics

ANT+ device connections can be done if you follow the ANT protocol as shown by ANT's official page. Luckily, we can take this to a higher level and avoid transmitting and receiving bits by using the already given ANT+ SDK on Android (N.B this SDK would require you to install two additional plugins on your device). Trust me if you are not a big fan of hardware specifics, you might want to just download the SDK.

Once the SDK is installed, you can start searching and connecting to devices. We can use the following steps as a guide to how we can do this:

  • Search for device
  • Connect to the device and request permissions from the device
  • Subscribe to the data you want

Searching

Let us start with searching for a device. This can be done using MultiDeviceSearch class from the SDK

Assume we are only going to search for HEARTRATE supported devices here. We will then also need to implement a searchCallback and rssiCallback. These serve as callback methods for different events, such as when a device has been found, or when the search has started and stopped.

Perfect! We now can scan for any devices that support HEARTRATE updates. From here, we can directly try to connect to the device from onDeviceFound and try to read the device's heart rate values.

Connecting

Let us edit the onDeviceFound callback to try connect to the first device found (for convenience of course. In reality this should be handled differently, perhaps a ListAdapter showing all the new found devices and having a frontend to select which device to connect to)

The connection is done by the requestAccess function here. This function requires you to implement two other callbacks: pluginAccessResultReceiver and deviceStateChangeReceiver :

Thats it! You should now be connected (at least given that the pluginAccessResultReceiver receives a SUCCESS in the callback).

Subscribing

Now that we have connected, the last thing we need is to subscribe to the device's updates.

Let's try to subscribe to the HEARTRATE events from the device. From the onResultReceived callback function, we have a Plugin Communicator Class (PCC) object that is connected to the device. We can subscribe to the events from this class:

Thats it! You can now take the value from the onNewHeartRateData and display it or stream it to your backend for further processing.

Quick-Go

Terra has abstracted ALL of this implementation into a single SDK: TerraRTAndroid. The SDK not only subscribes to Heart Rate event devices as shown in this example, but it also provides:

  • Connecting to ANY ANT+ device imaginable
  • A frontend widget to select which device to connect to
  • A comprehensive selection of datatypes to subscribe to
  • The data is streamed straight to your backend through our WebSocket API
  • Seamlessly disconnect and unsubscribe from the devices and datatypes.

If you really aren't in the mood to implement all the steps highlighted in this blog, check out our SDK (installed in one line and only requires you to run two functions to start receiving data: startAntPlusScan and startRealtime.)

More Topics

All Blogs
Team Spotlight
Startup Spotlight
How To
Blog
Podcast
Product Updates
Wearables
See All >
CEO and Co-Founder of Bioniq - Vadim Fedotov

CEO and Co-Founder of Bioniq - Vadim Fedotov

In this podcast with Kyriakos the CEO of Terra, Vadim Fedotov a former professional athlete turned entrepreneur, shares his journey in founding Bioniq.

Terra APITerra API
December 10, 2024
5 Lessons for Standing Out at HLTH

5 Lessons for Standing Out at HLTH

5 lessons from team Terra API for making a lasting impact at HLTH: from engaging senses to building real touch points, here’s what we learned from the HLTH event.

VanessaVanessa
December 5, 2024
November '24 Updates by Terra

November '24 Updates by Terra

Terra’s Latest Updates: Zepp Metrics, Support Revamp, and Teams API Enhancements 🚀✨

Alex VenetidisAlex Venetidis
December 1, 2024
Strava Pulls the Plug on their API: What This Means for Developers

Strava Pulls the Plug on their API: What This Means for Developers

Strava discontinued their API service, changing the ecosystem of third-party apps that have relied on their platform. How can developers react to this?

Terra APITerra API
November 21, 2024
Alternatives to the latest changes in the Strava API

Alternatives to the latest changes in the Strava API

Strava just introduced big changes to their API program. These changes will basically kill off a lot of apps. Use Terra API instead to avoid this

Kyriakos EleftheriouKyriakos Eleftheriou
November 19, 2024
next ventures
pioneer fund
samsung next
y combinator
general catalyst

Cookie Preferences

Essential CookiesAlways On
Advertisement Cookies
Analytics Cookies

Crunch Time: Embrace the Cookie Monster Within!

We use cookies to enhance your browsing experience and analyse our traffic. By clicking “Accept All”, you consent to our use of cookies according to our Cookie Policy. You can change your mind any time by visiting out cookie policy.