userx14 / omblepy

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

Documentation #2

Closed bonnybabukachappilly closed 1 year ago

bonnybabukachappilly commented 2 years ago

Can you tell me how you find which UUIDs for different functions and bytes code to write for a particular action?

userx14 commented 1 year ago

Ok, have I understood it right that:

maybe you can try to alter the protection-level for the pairing in this line. Maybe protection level 1 will work, it is possible that this device has some different pairing requirements, at least thats what I found on bleaks github when searching for error 19 when pairing.

As a first attempt you can try if pairing works. Because this device is not very simmilar to the currently supported devices, it will likeley require some reverse engineering.

You can record all in- and outgoing bluetooth communication of Android phones, the relevant search term would be "btsnoop_hci.log". Some newer android devices make it more difficult to access the logged data though. The recorded captured data can then be inspected with Wireshark to analyze the sent packets.

It is possible that I can find out some address offsets for this device aswell, but currently I do not have that much time available, probably I will check on the weekend.

Toei79 commented 1 year ago

same i gonna check weekend , but yea just read and reread to familiarize with this. i have old android phones. idk if that helps and one note .

ok change protection level with what numbers? i see a 2 there, replace with 0 and maybe try 1 ?

change to 1 and not worked. what numbers its possible try

Toei79 commented 1 year ago

ok i tried this i read here you say

''I always expected that there is a normal bluetooth connection mode, like there is with the hem-7322t, where you short press the blutooth button, and it goes into a mode where the little square directely appears and not the P''

both devices have that instead a p , with short press i get like a small o? then i tried run script, with 2 and 1 on both none works.

Ubuntu 22.04.2 LTS

userx14 commented 1 year ago

change to 1 and not worked.

Yeah changing this to 1 was what I hoped could fix the problem. I'm not really sure on what can cause the normal bluetooth pairing to fail.

ok i tried this i read here you say

''I always expected that there is a normal bluetooth connection mode, like there is with the hem-7322t, where you short press the blutooth button, and it goes into a mode where the little square directely appears and not the P''

both devices have that instead a p , with short press i get like a small o? then i tried run script, with 2 and 1 on both none works.

Ubuntu 22.04.2 LTS

Your omron devices should be in pairing mode "blinking P / longpress" when you run omblepy with the -p option. For normal data readout without the -p flag, it should be in the "little square / shortpress" mode. It is possible that this is a newer model and the pairing mode is different. Have you tested pairing with windows?

For your hem-7530t I have put my best guess for the addresses in this branch, but no guarantees. For the internal structure of the records I'm not so sure so I commented this part. If you can get the bytes of the records printed and have the data to compare to we might be able to deduce where which value is stored.

Toei79 commented 1 year ago

all models i have, comes with both type of pairing mode short and long i tried short press then without the -p still get error.

i tried but not worked. image

i checked on windows image

userx14 commented 1 year ago

What bluetooth adapter are you currently using? I think some of the newer pairing features are only supported with later bluetooth versions (if I read this correctely BT LE Secure connections were added with Bluetooth 4.2 ) and it could be possible that omron relies on that.

Things you could test: Does pairing work with the windows os dialog? Does the pairing work on Android (it has a more reliable bluetooth stack in my experience)? If pairing on android works there is an app called nRF Connect, that can be used to manually read / write bluetooth characteristics and manually do some of the transmissions.

Toei79 commented 1 year ago

its very old i guess i get it like 7 years ago idk if its bluetooth 4.2

06-25-2023 (214452) its this one kinovo brand.

https://www.amazon.com/Kinivo-USB-Bluetooth-4-0-Compatible/dp/B007Q45EF4/ref=sr_1_1_sspa?crid=5VZFI1XF065A&keywords=kinivo+bluetooth+adapter&qid=1688157068&sprefix=kinovo+blue%2Caps%2C105&sr=8-1-spons&sp_csd=d2lkZ2V0TmFtZT1zcF9hdGY&psc=1

its ok get a 5.0? one with latest stuff?

userx14 commented 1 year ago

its very old i guess i get it like 7 years ago idk if its bluetooth 4.2

06-25-2023 (214452) its this one kinovo brand.

https://www.amazon.com/Kinivo-USB-Bluetooth-4-0-Compatible/dp/B007Q45EF4/ref=sr_1_1_sspa?crid=5VZFI1XF065A&keywords=kinivo+bluetooth+adapter&qid=1688157068&sprefix=kinovo+blue%2Caps%2C105&sr=8-1-spons&sp_csd=d2lkZ2V0TmFtZT1zcF9hdGY&psc=1

its ok get a 5.0? one with latest stuff?

I would first try if pairing with android works before buying something new. I think most phones use quiet new bluetooth versions. If the pairing works using the android settings bluetooth menu and you can see bluetooth characteristics with nRF connect, it is probably related to the bluetooth version, or it could be a bug with the bluetooth library (bleak) I'm using.

I think your stick uses a Broadcom BCM20702, which only supports up to bluetooth 4.0 .

Did you test pairing just using the windows os dialog without omblepy using this bt stick?

Toei79 commented 1 year ago

oh what that means connect bt stick to android phone?

i have this stick and the other one that i bought , only one working its this one, i able to succesfully paring on windows and linux with this bt stick, one of my three omron devices.

userx14 commented 1 year ago

oh what that means connect bt stick to android phone?

i have this stick and the other one that i bought , only one working its this one, i able to succesfully paring on windows and linux with this bt stick, one of my three omron devices.

No, just use the bluetooth built into your phone. I was hoping the hardware in the phone supports the newer bluetooth standard, just to test if it makes a difference for the devices that do not workin with your stick.

Toei79 commented 1 year ago

oh what that means connect bt stick to android phone? i have this stick and the other one that i bought , only one working its this one, i able to succesfully paring on windows and linux with this bt stick, one of my three omron devices.

No, just use the bluetooth built into your phone. I was hoping the hardware in the phone supports the newer bluetooth standard, just to test if it makes a difference for the devices that do not workin with your stick.

i dont get it , i mean, phone connects successfully with omron device with all three

or its connect phone with bluetooh usb device?

userx14 commented 1 year ago

The idea was to use the Android Os Pairing dialog on a second phone which does not have the omron app installed and was not the last phone paired to the device. This would create a simmilar scenario to a pc trying to pair, just that most phones have hardware supporting more recent bluetooth versions. If pairing with the phone works it is most likeley just the bluetooth version of your usb adapter causing the probem. If it does not work, onron likeley accesses some bluetooth attributes before pairing, but this is kind of unlikely.

Anyway I think the most likeley cause is just the too low bluetooth version of your usb adapter. So if you can test on windows device with a chipset / usb dongle with more recent bluetooth version, just try if it works 😃 .

Toei79 commented 1 year ago

The idea was to use the Android Os Pairing dialog on a second phone which does not have the omron app installed and was not the last phone paired to the device. This would create a simmilar scenario to a pc trying to pair, just that most phones have hardware supporting more recent bluetooth versions. If pairing with the phone works it is most likeley just the bluetooth version of your usb adapter causing the probem. If it does not work, onron likeley accesses some bluetooth attributes before pairing, but this is kind of unlikely.

Anyway I think the most likeley cause is just the too low bluetooth version of your usb adapter. So if you can test on windows device with a chipset / usb dongle with more recent bluetooth version, just try if it works 😃 .

i tried with a tablet that never connected

gfgfdgsdfgdfgdf

and both devices connected

on tablet

but on omron devices keep blinking P

userx14 commented 1 year ago

both devices connected

Ok, so I would say it is most likely that the reason the pairing fails on windows is your usb dobgle's missing support for newer bluetooth features (4.2).

but on omron devices keep blinking P

The continued blinking of the P on the screen is normal, one needs to write a pairing key to some bluetooth characteristics for it to stop, which is what omblepy would do after the pairing succeeded.

Toei79 commented 1 year ago

both devices connected

Ok, so I would say it is most likely that the reason the pairing fails on windows is your usb dobgle's missing support for newer bluetooth features (4.2).

but on omron devices keep blinking P

The continued blinking of the P on the screen is normal, one needs to write a pairing key to some bluetooth characteristics for it to stop, which is what omblepy would do after the pairing succeeded.

ok what usb dongle you recommend? latest its one 5.0 or 5.1? that one works

userx14 commented 1 year ago

Dongles with 5.0 or 5.1 should both work. Preferrably one which does work out of the box on windows without installing special drivers.

Toei79 commented 1 year ago

i guess i try get one on ebay , but i only see 5.0 so far.

Toei79 commented 1 year ago

i get one from amazon 5.3 , it comes thursday , i update after i try

Toei79 commented 1 year ago

im trying use tablet , but idk how do it

i install it pydroid 3 , termius , i get omblepy file on the tablet but idk how run it.

userx14 commented 1 year ago

im trying use tablet , but idk how do it

i install it pydroid 3 , termius , i get omblepy file on the tablet but idk how run it.

It is really complicated getting the bluetooth library I used to work on Android. It would involve building an app with python4android and Kivy. Better safe your time and wait for the usb dongle.

Toei79 commented 1 year ago

im trying use tablet , but idk how do it i install it pydroid 3 , termius , i get omblepy file on the tablet but idk how run it.

It is really complicated getting the bluetooth library I used to work on Android. It would involve building an app with python4android and Kivy. Better safe your time and wait for the usb dongle.

i have high hopes on it hahah

i get i tried like a hour, asked here to that , i let it, thanks man, i wait until dongle comes.

Toei79 commented 1 year ago

if i do this working, all json files can be on same folder or i need different omblepy folders for each device?

it can run on crontab or it needs do paring process every time, whatever its fine i mean one time in month or something.

userx14 commented 1 year ago

if i do this working, all json files can be on same folder or i need different omblepy folders for each device?

it can run on crontab or it needs do paring process every time, whatever its fine i mean one time in month or something.

Currently it reads the records from the device and does these things:

The json file is intended to be directely imported into ubpm after each run and is not for permanent storage as it gets overwritten with every data readout.

To be honest, I have not really thought about the use with multiple devices, it depends if you want to keep the results of the devices seperate or merge them into one file. The choise probably depends on if the devices are used by the same person or not. Is your plan to merge the data or keep it seperate?

Depending on what you want to do here, you could modify the saveUBPMJson function to save to a different folder depending on the deviceName: https://github.com/userx14/omblepy/blob/3b49c009f0579487660e534aba98d4602b291d60/omblepy.py#L383C2-L383C2

Toei79 commented 1 year ago

i guess need use separate my step dad check continuosly and use this can be a good upgrade. i will check that

Toei79 commented 1 year ago

i get a dongle 5.3

image

running 7530t i get this error, using 71xx one works connect with -p but get error with data. this one its the one with ekg.

checking other one.

the other its working i get data fine

question ,

python3 ./omblepy.py -p -d HEM-7155t

this need be used every time for connect

then after

python3 ./omblepy.py -d HEM-7155t to get the data?

idk too much running just this way works fine. and both press the P On device

Toei79 commented 1 year ago

with debug py ./omblepy.py -p -d HEM-7530t --loggerDebug

image

image

userx14 commented 1 year ago

Nice, looks like the pairing is working now.

this need be used every time for connect then after python3 ./omblepy.py -d HEM-7155t to get the data?

The -p option writes an unlock key into to omron device. If you only use omblepy you in theory only have to do this one single time. But as soon as you execute the pairing procedure with the omron app on Android / IOS it will get overwritten and you need to run it once again.

The error you see when trying to read out data is a programming made by me. I will try to fix it later this day.

userx14 commented 1 year ago

I hope it is fixed now, please try out the most recent version of: https://github.com/userx14/omblepy/tree/hem-7530t-testing

Toei79 commented 1 year ago

it connects but when its for data get some error and big big list when use --loggerdebug

image

image image image image image image

userx14 commented 1 year ago

it connects but when its for data get some error and big big list when use --loggerdebug

Thanks for the screenshots, that looks very promising. The error just occurs because I did't not know how to parse the records yet. Therefore the csv writer will break because it gets no valid records to write.

Here are the raw bytes of the records:

5864115f0420103f00800001df20
5965165c13101b6400800002ab54
5765165a13101c84008000038d72
575e164413171ed00080000454ab
586d164a13281dca0080000533cc
5a62164c133712c4008000063bc4
4b51166493b1190352800007b04f
596e1658190919e9008000081ee1
5b63164e19691147008000097a85

encoded data offsets:
##sys+25 ?
  ##dia ?
    ##year+2000
      ##day, hour?
                    ####seq offset

Since I now have the raw data of the measurements would it possible for you to tell me the data the omron displays for these nine measurments (year, month, sys pressure, dia pressure, ...) to find out which byte stores what data?

I suspect I already see the year at the third byte, so if this is right the years for the first record should be 2017 and 2022 for the other eight ones.

Toei79 commented 1 year ago

i dont use this one too much , i checked on omron app and i get this

july 11/22 124/91 ekg normal bpm 76 june 08/22 135/89 ekg unclassified bpm 85

april 29/22 Ekg possible Atrial Flibrillation 110 bpm april 29/22 Ekg possible atrial flibillation 108 bpm april 29/22 106/75 april 25/22 123/90 april 25/22 123/90 egk normal 76 bpm april 25/22 134/88 ekg normal 78 bpm april 24/22 119/87 ekg normal 68 bpm april 24/22 126/87 ekg normal 91 bpm april 24/22 126/89 april 24/22 ekg normal 92 bpm april 24/22 ekg normal 91 bpm

Toei79 commented 1 year ago

question ubpm can read ekg? im guessing not its other app for it, i feel this just very new on pc. i mean nature reverser thing.

userx14 commented 1 year ago

Hi, I think I got the blood pressure readings figured out. If the mapping is correct this should be the values from the bluetooth transfer:

{'dia': 88, 'sys': 125, 'bpm': 95,  'mov': 0, 'ihb': 0, 'datetime': datetime.datetime(2017, 1,  1,  0,  0, 59)}
{'dia': 89, 'sys': 126, 'bpm': 92,  'mov': 0, 'ihb': 0, 'datetime': datetime.datetime(2022, 4, 24, 16, 45, 36)}
{'dia': 87, 'sys': 126, 'bpm': 90,  'mov': 0, 'ihb': 0, 'datetime': datetime.datetime(2022, 4, 24, 16, 50,  4)}
{'dia': 87, 'sys': 119, 'bpm': 68,  'mov': 0, 'ihb': 0, 'datetime': datetime.datetime(2022, 4, 24, 23, 59, 16)}
{'dia': 88, 'sys': 134, 'bpm': 74,  'mov': 0, 'ihb': 0, 'datetime': datetime.datetime(2022, 4, 25,  8, 55, 10)}
{'dia': 90, 'sys': 123, 'bpm': 76,  'mov': 0, 'ihb': 0, 'datetime': datetime.datetime(2022, 4, 25, 23, 11,  4)}
{'dia': 75, 'sys': 106, 'bpm': 100, 'mov': 1, 'ihb': 0, 'datetime': datetime.datetime(2022, 4, 29, 17, 36,  3)}
{'dia': 89, 'sys': 135, 'bpm': 88,  'mov': 0, 'ihb': 0, 'datetime': datetime.datetime(2022, 6,  8,  9, 39, 41)}
{'dia': 91, 'sys': 124, 'bpm': 78,  'mov': 0, 'ihb': 0, 'datetime': datetime.datetime(2022, 6, 11,  9,  5,  7)}

If these are correct, the version in the testing branch should now also read the blood pressure records.

ubpm can read ekg?

No, I don't think so. I'm unaware of any open source application that can read out that ekg curve. Also I'm wondering how omron managed the ekg data transfer. It kind of looks like they use a different method compared to the blood pressure readout, since in the demo video they show it transfering a live graph. This should not be possible with the way the blood pressure recordings are transfered, so they likely use different bluetooth attributes, etc. . If you need this functionality, there is not realy a way around logging the bluetooth transmissions via btsnoop_hci.log on android and analyzing the results with wireshark.

What is the status of the other devices currently?

Toei79 commented 1 year ago

its fine understand.

yea those are successfully connected nice

im going to try this update and let you know

Toei79 commented 1 year ago

image working!

Toei79 commented 1 year ago

i little lost what need replace to save multiple ones devices readings?

idk its useful i able to get other device BP786N i get really cheap by coincidence .

userx14 commented 1 year ago

i little lost what need replace to save multiple ones devices readings?

I'm not sure if the code here works, since I currently have no device to test with. Please let me know if this is what you want. I think otherwise you can also do the thing you initially proposed and just create multiple folders with the respository and create the device separation that way.

idk its useful i able to get other device BP786N i get really cheap by coincidence.

BP786N / hem-7321 is very likely internally the same device as hem-7322, which is supported already.

userx14 commented 1 year ago

I will close this issue now. If you want additional info / support for the multi-device solution, we should discuss this in a new issue.