userx14 / omblepy

Cli tool to read records from omron blood-pressure bluetooth-low-energy measurement instruments
41 stars 11 forks source link

Inquiry about Using gatttool for Omron Blood Pressure Monitor Data Retrieval #28

Open mangocitizenkane opened 1 month ago

mangocitizenkane commented 1 month ago

Hello,

I came across your script on GitHub for connecting to and retrieving data from Omron blood pressure monitors using Bluetooth Low Energy (BLE). It's incredibly well-written and thorough, and I appreciate you sharing it with the community.

I'm currently working on a similar project and was wondering if you could provide some guidance on using gatttool for connecting to the blood pressure monitor and retrieving data. Specifically, I would like to understand the following:

How to initiate a connection to the Omron device using gatttool.

  1. The specific commands and procedures for pairing with the device.
  2. How to read data from the device once connected.
  3. I noticed that your script uses the bleak library for these operations, but I'm interested in understanding how the same could be achieved using gatttool. Any examples or step-by-step instructions you could provide would be immensely helpful.

Thank you in advance for your time and assistance. I look forward to your response.

Best regards, Abdullah

userx14 commented 1 month ago

Hi Abdullah,

thanks for the kind words, can you go a bit more into details what you want to do in your project? What kind of programming/scripting language do you plan to use, or do you just want to use gattool for testing? I have not used gatttool extensively, but there exists a short introduction here: https://cxiao.net/posts/2015-12-13-gatttool/

Trying to answer your questions: You start up the omron in pairing mode (blinking P), then pair and connect using bluetooth. Then you write a sequence of bytes to the characteristic b305b680.... First to enable key programming mode, then programm a new 16 byte key. This is done in the function writeNewUnlockKey().

Then the omron needs to be restarted in normal mode, and a bluetooth pairing and connection must be reestablished. Then you write the key you programmed previously to the the characteristic b305b680... to unlock the data access. To give a brief overview of the steps for reading the data:

  1. unlockWithUnlockKey() - writing the previously programmed unlock key, requiered to access any data from the device.
  2. startTransmission() - just some fixed code that must be sent before doing eeprom reads
  3. _readBlockEeprom() - the addresses you need to read from depend on your specific device. This is the part that is loaded from the device specific driver (userStartAdressesList and recordByteSize). The reading is a bit complicated, because multiple characteristics are used to transfer more bytes simultaneously and have to be combined by you.
  4. Now you need to analze the data from the previous step. This is also very device dependent.
  5. endTransmission() - fixed code to shutdown the omron device

For some second reference implementation, you can also take a look at the code from the ubpm project, which uses QT.

but I'm interested in understanding how the same could be achieved using gatttool

I'm not sure if gatttool is such a good choice, it feels more like an interactive command line tool, to do a simple read of bluetooth characteristics. As far as I know, it is also deprecated by the bluez team. Is there a specific reason why you don't want to use a library or access the bluez backend directely?

If you really want to do it though, you will need some external code that calls gatttool repeatedly with the --char-write and --listen flags and than analyzes the data.

Regards, Benjamin