fsmeraldi / bleakheart

An asynchronous BLE Heart Monitor library with support for additional data from Polar monitors (ECG, accelerometers, etc)
Mozilla Public License 2.0
10 stars 9 forks source link

30 second delay in ECG data #1

Closed Chris-Spooner999 closed 5 months ago

Chris-Spooner999 commented 7 months ago

Hi, I am working on some C++ software that gets the ECG data from the Polar H10. I often get a 30 second delay after sending the command to stream and before ECG data is streamed over Bluetooth LE. There is no delay for the RR intervals however - they start coming through immediately. I have just run your ecg_queue.py software and have seen that your software is experiencing the same problem as mine - there is a 30 second delay for ECG data. Do you experience this problem as well? If so, is this something that you have investigated? I'd be interested to hear your thoughts on the matter.

fsmeraldi commented 7 months ago

Hello Chris, yes I did experience the same problem quite predictably - in fact I thought it was a limitation of the sensor. However, upgrading Bleak to 0.21.1 seems to have solved it for me (on Linux) - ECG and RR now start streaming basically at the same time. I wonder if anything can be gleaned by looking at changes Bleak made between the two versions - if you are getting the same problem in C++, and the new Bleak fixed it for Python, I guess they must have changed the way they interface with the OS layer? If you do not mind me asking, what is your application?

Chris-Spooner999 commented 6 months ago

Hi fsmeraldi, I am working on an application that gets the ECG and RR intervals from the Polar H10 using the SimpleBLE C++ Bluetooth LE library and Qt for the GUI, It plots the data and shares the data with other applications using Lab Streaming Layer. At the moment it works on Windows 10 only.

I am running the latest version of Bleak on my Linux machine - 0.21.1 and yet I still experience the 30 second delay problem with Bleakheart. So, I am not sure about it being related to an OS layer problem as you suggested. There must be something else causing it. I wondered whether it is a Polar H10 firmware problem. I seem to have the latest firmware though, but that doesn't mean that there isn't a problem with the firmware.

Have you run Bleakheart on any OS other than Linux? I wasn't able to get it running on Windows 10 - looks like it will only run on Linux (and perhaps MacOS) because it is using OS specific code (UNIX select system calls) in the Python async IO code.

fsmeraldi commented 6 months ago

Hello Chris, that's an interesting project. I also have the latest version of the firmware AFAIK, however I had the delay problem before the latest firmware was released and still had it afterwards, until I updated Bleak. I quickly tested Bleakheart on MacOS, and it runs fine, again with the latest version of Bleak - with the previous version ECG would not work at all - if I remember, the request to start ECG notification would time out. It's weird that asyncIO is not portable. One thing I tried, but that should not make a difference if not in terms of speed, is replacing the normal asyncio scheduler with uvloop - I doubt that would solve it, but since it is very easy to do, it may be worth trying it?

fsmeraldi commented 5 months ago

Bleak 0.21.1 solves the issue on Linux; I updated the dependency in release 0.1.1. Closing this issue.