python ชั่งน้ำหนัก
Bluetooth Scale in Python (Sinocare CK-793, ETEKCITY, likely others built on the same chipset)
https://github.com/hertzg/metekcity#etekcity-smart-nutrition-scale
https://github.com/oliexdev/openScale
import asyncio
import sys
from bleak import BleakClient
import bleak.exc
address = sys.argv[1]
char_uuid = "0000fff4-0000-1000-8000-00805f9b34fb"
first_connect = True
def callback(sender: int, data: bytearray):
grams = int.from_bytes(data[3:5], byteorder="little")
print(f"{grams}g")
async def run(address):
async with BleakClient(address) as client:
global first_connect
if first_connect:
print("Connected.")
first_connect = False
notify = await client.start_notify(char_uuid, callback)
loop = asyncio.get_event_loop()
while(True):
try:
loop.run_until_complete(run(address))
except bleak.exc.BleakDBusError:
pass
except KeyboardInterrupt:
print()
sys.exit(0)