Tigge / openant

ANT and ANT-FS Python Library
MIT License
174 stars 80 forks source link

Connecting to a specific device #35

Open luke-harris opened 6 years ago

luke-harris commented 6 years ago

Hi. I'm trying to make your heart rate example always connect to a specific device. I know that I'm supposed to be able to do this by setting the device number. I've added some code to the hr.py example to get the device number of my device.

Added code: m = node.request_message(Message.ID.RESPONSE_CHANNEL_ID) print("channel id:" + repr(m))

Output: channel id:(0, 81, array('B', [28, 152, 120, 17]))

The ant documentation says that this channel response should return: [ channel number, device number, device type id, transmission type]

However, when I change channel.set_id(0, 120, 0) to channel.set_id(152, 120, 0), I am unable to connect to my device. What am I missing here?

clyra commented 5 years ago

Hi,

I Have a similar issue, but I went the other way around :-). I do have my device number (got from my garmin gps sensor page). I was calling set_id the wrong way (0, 120, ) so I thank you for show me the right way :-). Now, it's my turn... As I understand the device number is a 2 byte number (1-65535). From your array I would guess that your device number is made from the two first bytes of the array (28, 152), which should translate to 7320 or 38940 (ant+ uses little endian so the byte order is reversed).

2l47 commented 8 months ago

If anyone else runs into this, you can now get the device number via device.device_id once on_found has been called, e.g. define device above and then print it in on_found. It's also just the digits at the end of the string representation of the device, as seen in the heart rate example. openant.devices.heart_rate.HeartRate(device_id=XXX) can then be manually set in the future to only connect to that device, no need to mess with the node/channel stuff. Setting to 0 uses any device.