FFFF GitHub - LookHin/blood-pressure-omron · GitHub
[go: up one dir, main page]

Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

Repository files navigation

blood-pressure-omron (OMRON HEM-7141T1)

Image

0. Install library

# apt-get update
# apt-get install -y bluez* pkg-config libbluetooth-dev libglib2.0-dev
# apt-get install -y libboost-thread-dev libboost-python-dev python3-capstone

# pip3 install requests
# pip3 install bleak
# pip3 install asyncio

1. discover.py

# nano discover.py
import sys
import asyncio
import time

from typing import Sequence
from bleak import BleakScanner
from bleak.backends.device import BLEDevice

async def findBluetoothDevice():
    devices: Sequence[BLEDevice] = await BleakScanner.discover(timeout=1)

    print("** Date Time: ", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), "**\n")

    for device in devices:
        print(device)

    print("--------------------------------------------------\n")

print("If you want to exit, you can press Ctrl + C.\n")

while True:
    try:
        loop = asyncio.get_event_loop()
        loop.run_until_complete(findBluetoothDevice())
    except KeyboardInterrupt:
        print("\nExit\n")
        sys.exit(0)
    except Exception as e:
        print("Exception Message:", str(e))
        time.sleep(1)

2. Find device address

# python3 discover.py

Image

3. device-info.py

# nano device-info.py
import sys
import asyncio
import time

from typing import Sequence
from bleak import BleakClient, BleakScanner
from bleak.backends.device import BLEDevice

GLUCOSE_DEVICE_ADDRESS = "CD:XX:XX:XX:XX:65" # Change to your device address

async def getDeviceInfo(address):
  print("Connect To: ", address, "\t\t", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))

  async with BleakClient(address) as client:
    services = client.services

    for service in services:
      print(services)
      print("\nService: ", service.handle, service.uuid, service.description)

      characteristics = service.ch
8000
aracteristics

      for char in characteristics:
        print("\tCharacteristic: ", char.handle, char.uuid, char.description, char.properties)

        descriptors = char.descriptors

        for desc in descriptors:
          print("\t\tDescriptor: ", desc)

    print("--------------------------------------------------\n")

async def findBluetoothDevice():
    devices: Sequence[BLEDevice] = await BleakScanner.discover(timeout=1)

    for device in devices:
        if device.address == GLUCOSE_DEVICE_ADDRESS:
            await getDeviceInfo(device.address)

print("If you want to exit, you can press Ctrl + C.\n")

while True:
    try:
        loop = asyncio.get_event_loop()
        loop.run_until_complete(findBluetoothDevice())
    except KeyboardInterrupt:
        print("\nExit\n")
        sys.exit(0)
    except Exception as e:
        print("Exception Message:", str(e))
        time.sleep(1)

4. Get device info

# python3 device-info.py

Image

5. Pairing

# bluetoothctl
[bluetooth]# scan on
[bluetooth]# trust CD:XX:XX:XX:XX:65
[bluetooth]# pair CD:XX:XX:XX:XX:65

Image

6. Find command from wireshark

  • Get bluetooth log (btsnoop_hci.log) from Android device See infomation
  • Open btsnoop_hci.log

Image

7. blood-pressure-monitor-omron.py

# nano blood-pressure-monitor-omron.py
import sys
import asyncio
import struct
import requests
import time

from typing import Sequence
from bleak import BleakClient, BleakScanner
from bleak.backends.device import BLEDevice
from datetime import datetime
from requests.structures import CaseInsensitiveDict

BLOOD_PRESSURE_DEVICE_ADDRESS = "CD:XX:XX:XX:XX:65" # Change to your device address
BLOOD_PRESSURE_MEASUREMENT_UUID = "49123040-aee8-11e1-a74d-0002a5d5c51b" # Blood pressure measurement UUID
BLOOD_PRESSURE_WRITE_COMMAND_UUID = "db5b55e0-aee7-11e1-965e-0002a5d5c51b"

def byteArrayBitsToInt(bytesArray, firstValidBitIdx, lastvalidBitIdx):
        deviceEndianess = "little"

        bigInt = int.from_bytes(bytesArray, deviceEndianess)
        numValidBits = (lastvalidBitIdx-firstValidBitIdx) + 1
        shiftedBits = (bigInt>>(len(bytesArray) * 8 - (lastvalidBitIdx + 1)))
        bitmask = (2**(numValidBits)-1)
        return shiftedBits & bitmask

def bloodPressureMeasurement(handle, data):
    unpackData = [dt[0] for dt in struct.iter_unpack("<B", data)]
    hexData = [hex(dt) for dt in unpackData]

    # Blood Pressure
    if(len(unpackData) == 22):

        byteArrayData = bytearray(unpackData)

        print("Int:", unpackData)
        print("Hex:", hexData)
        print("byteArray:", byteArrayData)

        year = byteArrayBitsToInt(byteArrayData, 98, 103) + 2000
        month = byteArrayBitsToInt(byteArrayData, 82, 85)
        day = byteArrayBitsToInt(byteArrayData, 86, 90)
        hour = byteArrayBitsToInt(byteArrayData, 91, 95)
        minute = byteArrayBitsToInt(byteArrayData, 68, 73)
        second = min(byteArrayBitsToInt(byteArrayData, 74, 79), 59)

        sys = byteArrayBitsToInt(byteArrayData, 120, 127) + 25
        dia = byteArrayBitsToInt(byteArrayData, 112, 119)
        bpm = byteArrayBitsToInt(byteArrayData, 104, 111)

        dataDateTime = datetime(year, month, day, hour, minute, second).strftime("%Y-%m-%d %H:%M:%S")

        currentTimestamp = time.time()
        deviceTimestamp = time.mktime(datetime(year, month, day, hour, minute, second).timetuple())

        if currentTimestamp - deviceTimestamp < 20:
            print("DateTime:", dataDateTime)
            print("Systolic: ", sys, "mmHg")
            print("Diastolic: ", dia, "mmHg")
            print("Pulse: ", bpm, "bpm")


async def receiveNotification():
    print("Connect To: ", BLOOD_PRESSURE_DEVICE_ADDRESS, "\t\t", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))

    async with BleakClient(BLOOD_PRESSURE_DEVICE_ADDRESS) as client:

        await client.start_notify(BLOOD_PRESSURE_MEASUREMENT_UUID, bloodPressureMeasurement)

        # command from wireshark
        await client.write_gatt_char(BLOOD_PRESSURE_WRITE_COMMAND_UUID,  bytearray.fromhex("0100"), response=True)
        await client.write_gatt_char(BLOOD_PRESSURE_WRITE_COMMAND_UUID,  bytearray.fromhex("11fdf0fd3b000000000000000000000000000000"), response=True)
        await client.write_gatt_char(BLOOD_PRESSURE_WRITE_COMMAND_UUID,  bytearray.fromhex("0800000000100018"), response=True)
        await client.write_gatt_char(BLOOD_PRESSURE_WRITE_COMMAND_UUID,  bytearray.fromhex("08010002602c0047"), response=True)
        await client.write_gatt_char(BLOOD_PRESSURE_WRITE_COMMAND_UUID,  bytearray.fromhex("080100028c18009f"), response=True)
        await client.write_gatt_char(BLOOD_PRESSURE_WRITE_COMMAND_UUID,  bytearray.fromhex("080100039e0e009a"), response=True)

        await asyncio.sleep(5.0)
        await client.stop_notify(BLOOD_PRESSURE_MEASUREMENT_UUID)

        if client.is_connected:
            await client.disconnect()

async def findBluetoothDevice():
    devices: Sequence[BLEDevice] = await BleakScanner.discover(timeout=1)

    for device in devices:
        if device.address == BLOOD_PRESSURE_DEVICE_ADDRESS:
            await receiveNotification()

print("If you want to exit, you can press Ctrl + C.\n")

while True:
    try:
        loop = asyncio.get_event_loop()
        loop.run_until_complete(findBluetoothDevice())
    except KeyboardInterrupt:
        print("\nExit\n")
        sys.exit(0)
    except Exception as e:
        print("Exception Message:", str(e))
        time.sleep(1)

8. Run

# python3 blood-pressure-monitor-omron.py

Image Image

About Us

Name : Khwanchai Kaewyos (LookHin)

Email : khwanchai@gmail.com

Website

https://www.onlyme.dev

https://www.facebook.com/LookHin

License

MIT License

Copyright (c) 2025 Khwanchai Kaewyos

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0