< 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 Founder of Prenuvo - Andrew Lacy

CEO and Founder of Prenuvo - Andrew Lacy

In this podcast with Kyriakos the CEO of Terra, Andrew Lacy shares his journey with Prenuvo which began from a personal health crisis.

Terra APITerra API
August 28, 2024
MedHacks: Using Wearables To Predict Heart Attacks

MedHacks: Using Wearables To Predict Heart Attacks

A few weeks ago we met Vishal, a recent engineering graduate who wanted to use Terra API as part of his MedHacks hackathon project, Cardio Clarity.

Gursukh SembiGursukh Sembi
August 19, 2024
July 2024 updates

July 2024 updates

Teams API adds Kinexon integration & new webhooks. Terra Health Scores now include Respiratory & Stress metrics. Eight Sleep integration returns with enhanced data.

Alex VenetidisAlex Venetidis
August 2, 2024
Vice President of Teamworks - Sean Harrington

Vice President of Teamworks - Sean Harrington

In this podcast with Kyriakos the CEO of Terra, Sean Harrington shares his journey from founding NoteMeal to becoming the VP of Teamworks.

Terra APITerra API
August 2, 2024
Chief Digital Product Officer of Les Mills - Amber Taylor

Chief Digital Product Officer of Les Mills - Amber Taylor

In this podcast with Kyriakos the CEO of Terra, Amber Taylor shares her journey from childhood running to her leadership role at Nike and navigating cultural differences.

Terra APITerra API
August 2, 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.