Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Scanning for devices with python-ant

RankRank

Total Posts: 42

Joined 2020-01-26

PM

Hi,

I'm currently going through the blog of Johannes Bader, who described how to read out live Heart Rate Date via Bluetooth ( https://johannesbader.ch/blog/track-your-heartrate-on-raspberry-pi-with-ant/ ). See the corresponding underlying pyton library ant.core http://pydoc.net/ant/0.1.0/ant.core.node/

I was able to make it work on my raspberry pi and I want to extend the script concerning two functionalities
1) Search for device with HRM data and list the corresponding device-numbers
2) Connect to 8 selected devices and receiving the HRM data and logging it into a file with the following columns "device_number", "time", "heart frequency"

So now to the solution of the two points:
1) I know that I have to retrieve the device_number (?which is part of the ChannelID) but I don't know how this could be done (how to get in background or continous scanning mode and so on).
2) Should be easy as I would only need to add additional channels. But I haven't found any examples in python (or even in C) which would demonstrate this

I would be happy if anyone could help me to find a solution in python (or just post an example in C).

Thanks!      
RankRankRankRank

Total Posts: 370

Joined 2012-06-27

PM

From the "Channel Search" application note:
"The Enable Extended Messages (0x66) command
can be used to allow the master’s channel ID to be
passed from the slave’s ANT layer to host, along
with the data message that was received. Should
the slave device want to establish communication
with that master, the host application can then use
the received channel ID to open and establish
another channel with that specific device. "

Ian      

Signature

Ian Haigh

RankRank

Total Posts: 42

Joined 2020-01-26

PM

Hi Ian,

Thanks, I saw this document. So, I have to set up the Background Scanning Channel as described in figure 5-2 on page 7. What does "Enable Extended Messages" mean in the figure (filler byte "0", Enable 1 compared to 0x66 on page 6)?
Do you have any example for this in any programming language?

Best
Alexander      
RankRankRankRank

Total Posts: 370

Joined 2012-06-27

PM

Extended messages are detailed further in "ANT Message Protocol and Usage" in section 7.1.1.

How they are enabled varies depending on device. For an nRF52 SOC it is a call to sd_ant_lib_config_set, and for the network processor implementations and USB sticks it is sending the 0x66 (or similar 0x6E) command to the radio.

The library you are using may have abstracted this away and you will have to consult the documentation for the library.

The USB libraries we publish would use ANT_RxExtMesgsEnable.

Ian      

Signature

Ian Haigh

Rank

Total Posts: 2

Joined 2019-10-15

PM

I don't know if this is what you want because I barely know what I am doing myself, but I happened across this when searching to see if anyone expanded on python-ant examples: https://github.com/asantacreuTwoNav/python-ant/blob/develop/demos/ant.core/10-scan.py      
RankRank

Total Posts: 42

Joined 2020-01-26

PM

Aquakitty - 31 January 2020 02:13 PM
I don't know if this is what you want because I barely know what I am doing myself, but I happened across this when searching to see if anyone expanded on python-ant examples: https://github.com/asantacreuTwoNav/python-ant/blob/develop/demos/ant.core/10-scan.py


Thanks a lot for this. The last fork I copied, didn't include this example. I will definitely check this out and keep you updated.      
RankRank

Total Posts: 42

Joined 2020-01-26

PM

Hi,
I tried the code from the github you provided, but unfortunately I was not able to make it run as I always received errors.

I tried to go back to the code provided by clone https://github.com/baderj/python-ant.git and incorporate all missing functions and functionalities (Extended Message and so on). But even after adapting the script of https://gist.github.com/c41d2bbe0aeded3506cf.git , I still ran into problem.

Were you able to make it work?      
Rank

Total Posts: 2

Joined 2019-02-21

PM

Hi Alex,

If you are considering using ant or ant+ under python, I suggest you take a look at another python project, openant ( https://github.com/Tigge/openant ).

I just explored almost every python ant library, and it turns out that this "openant" is the most solid, it works without any tweak on Mac OS and Linux, and it supports Python3 very well, which is really important in a time of 2020.

Other implementations are either out-dated or have problems here and there, It's just impossible to just get them to run, especially on Mac OS, but the openant it's like black magic...

BTW, because I have to make it work with TX, which is not originally implemented in this lib, so I have dived into its code, and it's really solid.

So if you are just trying to receive data from other Ant+ device, like a HR sensor, the openant is ready out of the box, just check the examples.

Wish you good luck, if you still have trouble, you can reply here, I have been to where you are now, so it's OK, you just need to dive into the right library... (or implement one yourself)
     
RankRank

Total Posts: 42

Joined 2020-01-26

PM

Hi lin.xc

I'm not 100% sure to which extent openant provides more than pyant. Python3 is definitely one point (still have to check if pyant is easily moveable to Python3), but besides that, other functionalities still have to be implemented from scratch (similar as to pyant).

Do you have any examples (besides the ones in github), how you used openant?

Best      
RankRank

Total Posts: 42

Joined 2020-01-26

PM

Hi lin.xc,

Finally python3 compatibility is more important than I thought. As I'm struggling to move python-ant to python3, I took a deeper look into open-ant. Have you figured out how to do a scan for devices with open-ant? I saw that the message code for extended messages is well set as a constant in easy/messages but there is no function to enable this on the channel.

Best      
RankRank

Total Posts: 42

Joined 2020-01-26

PM

lin.xc - 20 April 2020 04:41 AM
Hi Alex,

...


Thanks again lin.xc for pointing out openant. I forked the package and was able to extend it by the functionalities "enable extended messages" and "background scanning". You can find my changes under https://github.com/pirower/openant/ (I even added an additionnal example under scan.py)
     
Rank

Total Posts: 4

Joined 2020-05-22

PM

AlexDer - 26 May 2020 03:14 PM
lin.xc - 20 April 2020 04:41 AM
Hi Alex,

...


Thanks again lin.xc for pointing out openant. I forked the package and was able to extend it by the functionalities "enable extended messages" and "background scanning". You can find my changes under https://github.com/pirower/openant/ (I even added an additionnal example under scan.py)

Hi,
I've tryed to use your example heart rate monitor and thows a exception:
usb.core.USBError [Errno 32]

Do you know why?

Thanks      
RankRank

Total Posts: 42

Joined 2020-01-26

PM

I set up the usb dongle as descriped in https://johannesbader.ch/blog/track-your-heartrate-on-raspberry-pi-with-ant/      
Rank

Total Posts: 4

Joined 2020-05-22

PM

AlexDer - 10 June 2020 04:17 AM
I set up the usb dongle as descriped in https://johannesbader.ch/blog/track-your-heartrate-on-raspberry-pi-with-ant/

Thanks for your response, but I did it and the error continuous      
RankRank

Total Posts: 42

Joined 2020-01-26

PM

Did you manage to run the example from johannesbader succesfully?      
Rank

Total Posts: 4

Joined 2020-05-22

PM

AlexDer - 10 June 2020 05:15 AM
Did you manage to run the example from johannesbader succesfully?

I tryed with this example but didn`t work. Maybe is my ant+ usb stick