A modern Node.js module for interacting with ANT+ USB sticks and sensors. It provides a user-friendly API for heart rate monitors, speed sensors, and more, supporting both Node.js USB and WebUSB (browser) for maximum flexibility in various environments.
ant-plus-next
is a versatile Node.js library designed for interacting with ANT+ USB sticks and sensors. The library supports both Node.js (via USB) and WebUSB (browser), making it easy to integrate with devices like heart rate monitors, speed sensors, and power meters, whether you're building a server-side application or a browser-based solution.
With multi-platform compatibility (Linux, Windows, macOS, and browser), ant-plus-next
allows seamless access to ANT+ sensor data, regardless of whether you're building a server-side application or an in-browser solution for data acquisition.
Before installing the module, ensure the following prerequisites are met:
Make sure libusb
is installed. You can install libusb
and other required packages using:
sudo apt-get install build-essential libudev-dev
Use Zadig to install the WinUSB driver for your USB device. Otherwise, you will get LIBUSB_ERROR_NOT_SUPPORTED
when attempting to open devices.
Ensure that Garmin Express is not running, as it will attach to the ANT+ stick and prevent this module from accessing it.
To use WebUSB in a browser, ensure the following conditions are met:
Install the module via npm:
npm install ant-plus-next
ant-plus
DeviceID
to DeviceId
attach
to attachSensor
in BaseSensor
, AntPlusBaseSensor
, AntPlusScanner
, AntPlusSensor
GarminStick2
and GarminStick3
from constructor(dbgLevel = 0)
to debugOptions: DebugOptions = {}
.hbData
to heartRateData
from Heart rate sensorIf you encounter any issues, please check the Usage or Examples. If the problem persists, feel free to open an issue.
Hereβs a quick guide to get you started with the ant-plus-next
module:
Create USB Stick Instance
import * as Ant from "ant-plus-next";
const stick = new Ant.GarminStick3();
Create and configure a sensor:
const heartRateSensor = new Ant.HeartRateSensor(stick);
Attach event listeners:
heartRateSensor.on("heartRateData", (data) => {
console.log(`Device Id: ${data.DeviceId}, Heart Rate: ${data.ComputedHeartRate}`);
});
Open the USB stick and start scanning:
stick.on("startup", () => {
heartRateSensor.attachSensor(0, 0);
});
const result = await stick.open();
if (!result) {
console.error("Stick not found!");
}
Create WebUSB Stick Instance
import * as Ant from "ant-plus-next";
const webUsbStick = new Ant.WebUsbStick();
Create and configure a sensor:
const heartRateSensor = new Ant.HeartRateSensor(webUsbStick);
Attach event listeners:
heartRateSensor.on("heartRateData", (data) => {
console.log(`Device Id: ${data.DeviceId}, Heart Rate: ${data.ComputedHeartRate}`);
});
Open the WebUSB stick and start scanning:
webUsbStick.on("startup", () => {
heartRateSensor.attachSensor(0, 0);
});
const result = await webUsbStick.open();
if (!result) {
console.error("WebUSB Stick not found!");
}
startup
event.attached
or detached
event of the previous sensor.attached
or detached
event of the previous sensor.For detailed API documentation, visit the TypeDoc-generated documentation.
Explore more examples in the examples folder.
import * as Ant from "ant-plus-next";
const stick = new Ant.GarminStick3();
const heartRateSensor = new Ant.HeartRateSensor(stick);
heartRateSensor.on("heartRateData", (data) => {
console.log(`Device Id: ${data.DeviceId}, Heart Rate: ${data.ComputedHeartRate}`);
});
stick.on("startup", () => {
heartRateSensor.attachSensor(0, 0);
});
const result = await stick.open();
if (!result) {
console.error("Stick not found!");
}
import * as Ant from "ant-plus-next";
const webUsbStick = new Ant.WebUsbStick();
const heartRateSensor = new Ant.HeartRateSensor(webUsbStick);
heartRateSensor.on("heartRateData", (data) => {
console.log(`Device Id: ${data.DeviceId}, Heart Rate: ${data.ComputedHeartRate}`);
});
webUsbStick.on("startup", () => {
heartRateSensor.attachSensor(0, 0);
});
const result = await webUsbStick.open();
if (!result) {
console.error("WebUSB Stick not found!");
}
Contributions are welcome! Please check out the CONTRIBUTING.md and CODE_OF_CONDUCT.md for details.
This project is licensed under the MIT License.
Parts of the code are based on the original project ant-plus by Alessandro Vergani (Β© 2015). The original project was also licensed under the MIT License.
Thanks to the original developers and all contributors!