bluetooth lowenergy - How to get the body composition measurement from a smart scale using python - Stack Overflow

I have a Fit2live weigh scale unfortunately their app is not working in my country. So, I decided to cr

I have a Fit2live weigh scale unfortunately their app is not working in my country. So, I decided to create my own using python (just for my personal use). I was able to connect to the scale (it uses Chipsea BLE CST34M97) and pull the actual weight in the scale but having difficulty in get other metrics (see details below). Can someone help me get the other measurement correctly?

import asyncio
from bleak import BleakClient

async def read_characteristic(address, characteristic_uuid):
    async with BleakClient(address) as client:

        def callback(sender, data):
            print(f"Notification from {sender}: {data}")
            # Decoding the body composition measurement based on the correct sequence
            weight = int.from_bytes(data[11:13], byteorder='little') / 10
            bmi = int(data[2])   # Byte 2,
            fat_percentage = int.from_bytes(data[2:4],byteorder='little')*1.25#int(data[3]) / 10  # Byte 3, scaled by 10
            visceral_fat = int.from_bytes(data[4:6],byteorder='little')#int(data[4])  # Byte 4 (Visceral fat level)
            muscle_mass = int.from_bytes(data[6:7], byteorder='little') / 10  # Bytes 5-6, scaled by 10
            bone_mass = int.from_bytes(data[7:9], byteorder='little') / 10  # Bytes 7-9, scaled by 10
            bmr = int.from_bytes(data[9:11], byteorder='little')/2  # Bytes 9-11 (BMR in kcal)
            body_water = int.from_bytes(data[11:13], byteorder='little') / 10  # Bytes 11-13, scaled by 10

            print("Body Composition Measurement:")
            print(f"Weight: {weight:.2f} kg")
            print(f"BMI: {bmi:.1f}")
            print(f"Fat Percentage: {fat_percentage:.1f}%")
            print(f"Visceral Fat: {visceral_fat}")
            print(f"Muscle Mass: {muscle_mass:.2f} kg")
            print(f"Bone Mass: {bone_mass:.2f} kg")
            print(f"BMR: {bmr} kcal")
            print(f"Body Water: {body_water:.1f}%")


        await client.start_notify(characteristic_uuid, callback)
        await asyncio.sleep(5) 
        await client.stop_notify(characteristic_uuid)

        

address = "C0:00:00:00:7D:45" 
characteristic_uuid = "00002a9c-0000-1000-8000-00805f9b34fb" 

asyncio.run(read_characteristic(address, characteristic_uuid))

Result Notification from 00002a9c-0000-1000-8000-00805f9b34fb (Handle: 30): Body Composition Measurement: bytearray(b'\x06\x03\x15\x00\x11\x01\x01\x00\x00\x80\x13\xd6\x02\x00\x00\x04\x00\x00\x00\x00')

Body Composition Measurement:

Weight: 72.60 kg (correct)

BMI: 21.0 (Not sure)

Fat Percentage: 26.2% (not sure)

Visceral Fat: 273 (not sure)

Muscle Mass: 0.10 kg (incorrect)

Bone Mass: 0.00 kg (incorrect)

BMR: 2496.0 kcal (not sure)

Body Water: 72.6% (incorrect)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744202862a4562965.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信