The distance between the yuwell meter and computer must be within 5 meters.
# 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
# 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)
# python3 discover.py
# nano blood-glucose-yuwell.py
import sys
import asyncio
import struct
import requests
import time
import platform
from typing import Sequence
from bleak import BleakClient, BleakScanner
from bleak.backends.device import BLEDevice
from datetime import datetime
from requests.structures import CaseInsensitiveDict
GLUCOSE_DEVICE_ADDRESS = "D0:03:XX:XX:1A:A9" # Change to your device address
GLUCOSE_MEASUREMENT_UUID = "00002a18-0000-1000-8000-00805f9b34fb" # Glucose measurement UUID
def glucoseMeasurement(handle, data):
unpackData = [dt[0] for dt in struct.iter_unpack("<B", data)]
hexData = [hex(dt) for dt in unpackData]
print("hexData : ", hexData)
deviceDateTime = "{:04d}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}".format(int(((unpackData[4] & 0xFF) << 8) | unpackData[3]), int(unpackData[5]), int(unpackData[6]), int(unpackData[7]), int(unpackData[8]), int(unpackData[9]))
currentDateTime = datetime.strptime(deviceDateTime, "%Y-%m-%d %H:%M:%S")
glucoseMm = (unpackData[10] / 10.0)
glucoseMg = "{:.1f}".format((unpackData[10] / 10.0) * 18)
print("Date Time: ", str(currentDateTime.strftime("%Y-%m-%d %H:%M:%S")), "\t\tGlucose: ", glucoseMm, "mmol/L , ", glucoseMg, "mg/dL")
async def receiveNotification():
print("Connect To: ", GLUCOSE_DEVICE_ADDRESS, "\t\t", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
async with BleakClient(GLUCOSE_DEVICE_ADDRESS) as client:
await client.start_notify(GLUCOSE_MEASUREMENT_UUID, glucoseMeasurement)
await asyncio.sleep(5.0)
await client.stop_notify(GLUCOSE_MEASUREMENT_UUID)
async def findBluetoothDevice():
devices: Sequence[BLEDevice] = await BleakScanner.discover(timeout=1)
for device in devices:
if device.address == GLUCOSE_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)
# python3 blood-glucose-yuwell.py
Name : Khwanchai Kaewyos (LookHin)
Email : [email protected]
https://www.facebook.com/LookHin
MIT License
Copyright (c) 2023 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.