loghorn / ant-plus Goto Github PK
View Code? Open in Web Editor NEWA node module for ANT+
License: MIT License
A node module for ANT+
License: MIT License
When I call is_present( ), the stick seems to close... or otherwise put the object in a bad state such that write( ) fails and throws and exception.
if (!this.stick.is_present()) { .. }
I've verified open()
returns true before calling is_present()
, and then after calling is_present()
I verified open()
returns false.
See ./src/ant.ts
file.
Hi! I'm having trouble running the samples for this library. I can only assume it's something weird with my setup, yet this issue occurs both on my linux PC and my raspberry pi.
When I run sample.js
on my PC, I get this ugly crash:
node[4071]: ../src/node_api.cc:1149:napi_status napi_release_threadsafe_function(napi_threadsafe_function, napi_threadsafe_function_release_mode): Assertion `(func) != nullptr' failed.
1: 0xa03520 node::Abort() [node]
2: 0xa0359e [node]
3: 0x9d706a [node]
4: 0x7f90bda8ba28 Device::Close(Napi::CallbackInfo const&) [/home/chris/git/ant-plus/node_modules/usb/prebuilds/linux-x64/node.napi.glibc.node]
5: 0x7f90bda947ca Napi::InstanceWrap<Device>::InstanceMethodCallbackWrapper(napi_env__*, napi_callback_info__*) [/home/chris/git/ant-plus/node_modules/usb/prebuilds/linux-x64/node.napi.glibc.node]
6: 0x9b8c8f [node]
7: 0xbe359b [node]
8: 0xbe4b46 [node]
9: 0xbe51c6 v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node]
10: 0x13ff159 [node]
[1] 4071 abort (core dumped) node sample/sample.js
To be totally honest, I've no idea what's happening here. Any pointers would be welcome.
Curiously, on my PC, this only occurs after the first time I plug in the ANT+ dongle. If I unplug and replug it, the script works as expected. However, I get a very similar crash on my raspberry pi, and replugging the dongle does not seem to make a difference here. This is the exact crash I get on the Pi:
node[6930]: ../src/node_api.cc:1275:napi_status napi_release_threadsafe_function(napi_threadsafe_function, napi_threadsafe_function_release_mode): Assertion `(func) != nullptr' failed.
Aborted
Looks like it's the same issue.
I have tried various node versions (14, 17) and multiple ant+ dongles. The same issue is also present on my laptop which is similarly set up to my desktop. I feel crazy that I'm having this issue on 3 computers yet I'm struggling to find any evidence of similar problems! Any pointers big or small would be hugely appreciated. Let me know if I can provide more info too!
Hello. Please tell us what devices can be supported by your program? Is it possible to use an ant+ to usb device from the brands THINKRIDER, Magene, Cycplus, Coospo? Tell me which of them will work with your software?
In the Windows system, the ant. js file -- open() method cannot retrieve information about the inserted USB device.
Hi,
why this message of error?
thanks
ant-plus\build\ant.js:614
throw 'scanning unsupported';
^
scanning unsupported
Hello, I would like to know how many sensors would it be able to connect simultaneously? Usually with a USB dongle is 8, but I wonder if it could reach this limit or even overcome it. Thanks
Hi,
I am having problems with numbers from this. Any idea what could cause this?
I get maybe 5-10 events with numbers that looks reasonable. Then suddenly I get events like this:
SpeedCadenceSensorState {
DeviceID: 7434,
CadenceEventTime: 65362,
CumulativeCadenceRevolutionCount: 1279,
SpeedEventTime: 0,
CumulativeSpeedRevolutionCount: 13222,
CalculatedDistance: 28321.523999999998,
CalculatedCadence: 7630.816999805938,
CalculatedSpeed: 446.5095314313867 }
// Some milliseconds later:
SpeedCadenceSensorState {
DeviceID: 7434,
CadenceEventTime: 56336,
CumulativeCadenceRevolutionCount: 65535,
SpeedEventTime: 585,
CumulativeSpeedRevolutionCount: 0,
CalculatedDistance: 112056.58799999999,
CalculatedCadence: 69861.7703061405,
CalculatedSpeed: 196146.9164307692 }
The revolution count is maxed out, and thus the calculated distance and speed is all over the place. Then the next packets all have the same cumulativecadencerevolutioncount, but CumulativeSpeedRevolutionCount is going up and down in numbers. But seems like a much higher number of revolutions than the wheel is actually spinning.
Bug in ant-plus.js that is missing this line in the module.exports = { } block:
Messages: Ant.Messages,
After I added that line to the other exports, the error disappeared and the stick initialized fine.
pi@raspberrypi:~/ant-cycling-power $ sudo node test.js
/home/pi/ant-cycling-power/power-meter.js:15
stick.write(Ant.Messages.assignChannel(channel, 'transmit'));
^
**TypeError: Cannot read property 'assignChannel' of undefined**
at GarminStick2.<anonymous> (/home/pi/ant-cycling-power/power-meter.js:15:30)
at emitOne (events.js:116:13)
at GarminStick2.emit (events.js:211:7)
at GarminStick2.USBDriver.read (/home/pi/.nvm/versions/node/v8.11.1/lib/node_modules/ant-plus/build/ant.js:527:18)
at InEndpoint.<anonymous> (/home/pi/.nvm/versions/node/v8.11.1/lib/node_modules/ant-plus/build/ant.js:374:23)
at emitOne (events.js:116:13)
at InEndpoint.emit (events.js:211:7)
at Transfer.transferDone (/home/pi/.nvm/versions/node/v8.11.1/lib/node_modules/ant-plus/node_modules/usb/usb.js:328:9)
Watch: Garmin vívomove Style
Usb:
Name: CYCPLUS USB ANT STICK U1 (AliExpress)
Manufacturer: Chengdu Chendian Intelligent Technology Co., Ltd. (text from the box)
USB ID: 0FCF 1008
I have used "zadig-2.7.exe" to install WinUSB (v6.1.7600.16385)
Environment:
Node: 16.17.0
Ant-Plus: 0.1.24
Windows 10
Code:
ar Ant = require("ant-plus");
var stick = new Ant.GarminStick2(); //GarminStick3 => Stick not found!
var sensor = new Ant.HeartRateSensor(stick);
sensor.on("hbData", function (data) {
console.log(data.DeviceID, data.ComputedHeartRate);
});
stick.on("startup", function () {
sensor.scan();
});
if (!stick.open()) {
console.log("Stick not found!");
}
Output:
FATAL ERROR: Error::Error napi_create_reference
1: 00007FF63958B1EF v8::internal::CodeObjectRegistry::~CodeObjectRegistry+123599
2: 00007FF639518BA6 v8::internal::MicrotaskQueue::GetMicrotasksScopeDepth+65206
3: 00007FF639519C7D node::OnFatalError+301
4: 00007FF639519259 v8::internal::MicrotaskQueue::GetMicrotasksScopeDepth+66921
5: 00007FF6395472EC napi_fatal_error+156
6: 00007FF8D6771887
7: 00007FF8D67717BE
8: 00007FF8D6781C80
9: 00007FF8D6782E44
10: 00007FF8D67724F8
11: 00007FF639545562 node_module_register+5458
12: 00007FF639544FE1 node_module_register+4049
13: 00007FF6395E8D0B uv_async_send+331
14: 00007FF6395E849C uv_loop_init+1292
15: 00007FF6395E863A uv_run+202
16: 00007FF6395B7725 node::SpinEventLoop+325
17: 00007FF6394D1FE1 cppgc::internal::NormalPageSpace::linear_allocation_buffer+51729
18: 00007FF63954CA3A node::Start+202
19: 00007FF6393786DC RC4_options+347612
20: 00007FF63A3CE3F8 v8::internal::compiler::RepresentationChanger::Uint32OverflowOperatorFor+14520
21: 00007FF9060E7034 BaseThreadInitThunk+20
22: 00007FF9064626A1 RtlUserThreadStart+33
Can I resolve this or is my USB just incompatible and I need to buy the official one?
Thanks
This is a great library, was very easy to get started with after trying the python equivalent for raspberry pi.
After initially running just fine though and a few restarts, I then got the following error:
LIBUSB_ERROR_BUSY
pi@raspberrypi:~/ant-plus/sample $ node cadence-sensor.js
/home/pi/ant-plus/node_modules/usb/usb.js:168
this.device.__claimInterface(this.id)
^
Error: LIBUSB_ERROR_BUSY
at Error (native)
at Interface.claim (/home/pi/ant-plus/node_modules/usb/usb.js:168:14)
at GarminStick2.USBDriver.open (/home/pi/ant-plus/build/ant.js:287:20)
at Object.<anonymous> (/home/pi/ant-plus/sample/cadence-sensor.js:41:12)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
Any idea how I can ensure whatever is claiming it is detached from the interface?
I don't understand what happens if you attach a sensor (attach(0, 0)) with 0 as device's id to connect to the first device found, but no device is found.
How can I know when I can try to attach again? Is there a timeout or an event to catch?
Thanks,
Hello, I wonder what is the proper way to use multiple sensors at the same time. I'm trying to attach 8 hr sensors and right now I'm getting: " MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 read listeners added. Use emitter.setMaxListeners() to increase limit" even with just two of them, so I think I'm not attaching them well. I have that warning until I increase the limit to 1000, and that doesn't seem right.
stick0.on("startup", function() { console.log("startup stick"); console.log("Max channels:", stick0.maxChannels); // will output 8 hrSensor0.attach(0, 0); hrSensor1.attach(1, 0); ...
I'm just attaching the sensors on the stick startup using DeviceID=0 for all of them because I want to be able to attach to any hr sensors, not only the ones I know. I wonder if I could scan the DeviceID before attaching it.
I know I should follow your instructions. So I'd like to know which is the best way to do it:
never attach a sensor before receiveing the startup event
never attach a new sensor before receiving the attached or detached event of the previous sensor
never detach a sensor before receiving the attached or detached event of the previous sensor
Do I have to attach the sensors recursively then? (I did and that seems to make the limit warning disappear) Should I detach every sensor just after it's attached to reattach it again with its real DeviceID?
The lib gives also an exit error if I ever try to attach o detach a sensor that is already attached o detached. Any way to prevent that beyond making sure of not doing that?
This is the best nodejs ANT+ lib I've found. Thank you for your great work.
var Ant = require('ant-plus');
var stick = new Ant.GarminStick2();
var sensor = new Ant.HeartRateSensor(stick);
if (!stick.open()) {
console.log('Stick not found!');
}
Returns:
/home/pi/.node-red/node_modules/usb/usb.js:48
this.__close()
^
Error: Can't close device with a pending request
at Device.usb.Device.close (/home/pi/.node-red/node_modules/usb/usb.js:48:7)
at GarminStick2.USBDriver.open (/home/pi/.node-red/node_modules/ant-plus/build/ant.js:352:29)
at Object. (/home/pi/.node-red/test.js:15:12)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47
I tried following the docs after installing my ANT+ stick via Zadig.
I tried to call sensor.scan()
as descripted in the README.
But i kept running into this error:
FATAL ERROR: Error::Error napi_create_reference
I had a look, and it looks like you have to create a HeartRateScanner
if you want to scan for devices.
A HeartRateSensor
, if you want to attach a device.
This is not clear in the README.
(please correct me if i am wrong)
I'm programming a Electron app.
I did attached HeartRateSensor on channel 0 and SpeedCadenceSensor on channel 1.
However, I've received only heart rate data in spite of SpeedCadenceSensor did attached.
But, if I replace the channel, I can receive heart rate data instead of speed data.
I need your help.
OS: macOS 10.13.2 Beta
USB stick: GarminStick2
initSensors() {
const stick = new Ant.GarminStick2();
const heartRateSensor = new HRS.HeartRateSensor(stick);
const speedCadenceSensor = new SC.SpeedCadenceSensor(stick);
speedCadenceSensor.setWheelCircumference(2.12);
var dev_id = 0;
heartRateSensor.on("hbdata", function(data) {
// will call
console.log(
"heartRateSensor: ",
data.DeviceID,
data.ComputedHeartRate,
data
);
if (data.DeviceID !== 0 && dev_id === 0) {
dev_id = data.DeviceID;
console.log("detaching...");
heartRateSensor.detach();
heartRateSensor.once("detached", function() {
heartRateSensor.attach(0, dev_id);
});
}
});
heartRateSensor.on("attached", function() {
// will call twice
console.log("heartRateSensor attached");
});
heartRateSensor.on("detached", function() {
console.log("heartRateSensor detached");
});
speedCadenceSensor.on("speedData", function(data) {
// will not call
console.log("speedCadenceSensor: ", data.DeviceID, data);
});
speedCadenceSensor.on("attached", function() {
// will not call
console.log("speedCadenceSensor attached");
});
speedCadenceSensor.on("detached", function() {
console.log("speedCadenceSensor detached");
});
stick.on("startup", function() {
console.log("startup");
console.log("Max channels:", stick.maxChannels); // will output 8
heartRateSensor.attach(0, 0); // I will not receive heart rate data, if it will change channel 0 to 1
speedCadenceSensor.attach(1, 0); // I will receive speed data, if it will change channel 1 to 0
console.log(stick.attachedSensors); // will output [HeartRateSensor, SpeedCadenceSensor]
});
}
Hello
After an app using the ant plus module is running for a few days (detecting heart rate sensors) -
the app occasionally get stuck and the following error is thrown - 'SYNC missing'.
I found that error in the 'ant.ts' file:
if (data.readUInt8(0) !== 0xA4) { throw 'SYNC missing'; }
My app is running on Raspberry Pi 4.
The only solution is to restart the hardware. Restarting the nodejs instance won't help.
I'd like to know what's the reason the module gets stuck and what can I do in order to solve it.
Thank you
Hey
I am pretty new to ANT+, and trying to use SimulANT+
app to simulate sensors on GarminStick3.
(will have real sensors to test soon, but i am trying to pre-test via SimulANT+
)
The issue is that the ANT+ stick is not visible to the SimuANT+
app if i install it as WinUSB (libusb)
.
If i install the stick with WinUSB (libusb)
, i recieve the startup
event fine in ant-plus, but it does not show in the device list of the SimuANT+
app.
If i install it as libusb-win32
, it shows up in SimulANT+
, but i no longer recieve any startup
event on the stick in ant-plus.
I do not get any Stick not found!
message either, even tho i have the check
if (!stick.open()) {
console.log('Stick not found!');
}
Anyone else tried this ?
Is it a known limitation that SimulANT+
needs a different driver than ant-plus ?
Hi,
(Thanks for this project, it is so great ! It's working perfectly with my Favero Assioma power pedals)
i wasn't able to received any data with my Garmin Speed sensor.
Then i read the documentation (D00001163_-_ANT+Device_Profile-_Bicycle_Speed_and_Cadence_2.1.pdf) and realised that the period of the speedSensor is different that the one for Speed+Cadence.
By changing the period to 8188 i'm getting the datas.
(maybe your speed-sensors.js was created after copying speed-cadence-sensors.js
Regards
The version of WinUSB / Zadig pointed to by the Readme.md is a n old version on SourceForge. The correct version to use is the one on the Zadig website https://zadig.akeo.ie/
With the version in the Readme, I could not get the lib to work on Win 10. The updated version works correctly.
在windows系统中,ant.js文件--open()方法里面,获取不到插入的usb设备信息。
pi@raspberrypi:~/ant-plus/sample $ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 008: ID 0e8f:2517 GreenAsia Inc.
Bus 001 Device 004: ID 1a86:e5e3 QinHeng Electronics
Bus 001 Device 009: ID 0fcf:1008 Dynastream Innovations, Inc. ANTUSB2 Stick
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
$ ls /dev/ttyUSB0
/dev/ttyUSB0
When I attempt to run my program I get the error:
ANT+ USB stick not found!
/home/pi/ant-plus/build/ant.js:522
this.outEp.transfer(data, function (error) {
^
TypeError: Cannot read property 'transfer' of undefined
at GarminStick3.USBDriver.write (/home/pi/ant-plus/build/ant.js:522:20)
at StrideSpeedDistance.broadcast (/home/pi/ant-plus/sample/strideSpeedDistance/strideSpeedDistance.js:65:16)
at a (/home/pi/ant-plus/sample/strideSpeedDistance/start.js:93:9)
at Object. (/home/pi/ant-plus/sample/strideSpeedDistance/start.js:98:1)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47
any help will be greatly appreciated.
MIke
Hi,
Are there any plans to implement the Fitness Equipment Controls (FE-C) device profile?
See section 2) of https://www.thisisant.com/developer/ant-plus/device-profiles/#525_tab
Thanks!
Hello .
I'm need the data of RR intervals.
It's possible retrieve these data?
I am getting stick not found but I can see the device using lsusb...
Bus 001 Device 007: ID 0fcf:1008 Dynastream Innovations, Inc. ANTUSB2 Stick.
Are there any options I might need to add to calls that might help?
Hello
I am able to receive the HR data from multiple devices using only 1 sensor initialized.
In every beat I receive hbData simultaneously from all devices and store the data according to the given serial number.
I never call the attach method and actually don't understand why I need it all, or what's the meaning of attaching the sensor to a channel.
Can anyone help me figure this out?
Thanks!
I'm trying to connect to my Di2 system on my bike and see when the hood-buttons are pressed but Iv'e heard they use a pretty custom profile
Is there a way to just connect to all/any Ant+ devices and spit out any raw data that may come from them?
Hi there! I want to know if there is a way to run this on a Mac? I saw that windows and linux versions uses different kind of usb connectors. Do you know how to do it in a Mac?
Hi,
I have managed to get reading from my power meter. The output data is pretty frequent. May I know what is the time interval between each data and can I change that interval? If so, how? Thank you.
Feature request/ proposal
I am looking at getting this working with the WebUSB api which:
- Is available in Chrome 61 for Android, Chrome OS, Linux, macOS and Windows.
- Has a port for Node.js also exists - https://github.com/thegecko/webusb
we could there for have a cross platform ant plus driver, which would work through node or a recent enough chrome browser. We should even be able to drop back to node usb module for compatibility.
What do you think?
Hi
I hope this message finds you well. I am using the ant-plus library to capture heart rate data from a Polar Verity Sense sensor. While I can successfully log the heart rate data, I am having trouble extracting the RSSI (Received Signal Strength Indicator) value.
Could you please provide guidance on how to correctly obtain the RSSI value with this sensor?
Thank you for your assistance.
Best regards,
Nuri
The event speedData is not emitted when using SpeedSensor but is emitted when using SpeedScanner.
Device is "verified" as attached via the attached event when using SpeedSensor
Hi everybody,
I am starting to play with this nice package, I have searched in examples and code and dont find the way to scan after been attached a sensor.
Let say I have many devices but only one stick: hr sensor and fitness sensor, scan for fitness and select one to attach it, after I would like to scan for hr devices but.. message error is returned mentioning "cant attach".
Is there any way to cover this use case?
Should I deatach fitness, save it´s ID, scan for HR and when select HR sensor and attach it, attach also fitness sensor in another channel?
Kind regards and thanks in advance
I'd like to capture data from a Garmin GSC-10 speed/cadence sensor I've got attached to my bike.
It looks like this is a different type of device than either the heart rate monitor or the stride/speed/distance sensors currently in the repository. How would one go about adding this sensor type? Is there a website for ANT+ sensor specs I could reference, perhaps?
I do not get any data, I did open zwift which tells me my heartrate, so the dongle is doing its thing. I'm using OS X.
Will there be that support? or how do I develop it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.