Skip to content

Instantly share code, notes, and snippets.

@scoates
Last active November 15, 2021 14:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scoates/840f2d30e25d6b5e6daa2c3251f5af39 to your computer and use it in GitHub Desktop.
Save scoates/840f2d30e25d6b5e6daa2c3251f5af39 to your computer and use it in GitHub Desktop.
Bluetooth Scale in Python (Sinocare CK-793, ETEKCITY, likely others built on the same chipset)
root@raspberrypi:~# python3 scale.py XX:RE:DA:CT:ED:XX
Connected.
152g
444g
688g
726g
783g
853g
978g
1753g
1814g
1880g
2124g
2451g
2565g
2595g
2334g
2360g
173g
0g
0g
0g
^C
root@raspberrypi:~#
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)
@scoates
Copy link
Author

scoates commented Apr 9, 2021

Thanks to @hertzg for the info in https://github.com/hertzg/metekcity

@hertzg
Copy link

hertzg commented Apr 14, 2021

@scoates You are very welcome :)

As an improvement you can also use the settled flag, which is set by the scale when the item weight has been stable.
With this you could show only the final weight or avoid weight spam after you have let go of the item.

https://github.com/hertzg/metekcity/tree/master/packages/esn00-packet#data-packet-weight-measurement-0xe0

@scoates
Copy link
Author

scoates commented Apr 14, 2021

Hi! Yep! My use case (which I didn't make clear) is that I'd like to use this scale for continuous measurement. The demo above is me putting my finger on the scale and increasing it over time. It also doesn't account for the sign. (-:

@hertzg
Copy link

hertzg commented Apr 14, 2021

Yeah great job! Just happy that you found it useful. Cheers!

@kublaios
Copy link

@scoates Am I right to assume that you will use the scale for profiling something? Like coffee, perhaps? I am looking for a Bluetooth scale that I can listen to preferably on the mobile side so that I can make a profiler app, but the code above is all Greek to me :) Do you know if this is possible for Sinocare CK-793 scale?

@scoates
Copy link
Author

scoates commented Nov 15, 2021

I actually switched my plans to use a custom piece built around a load cell and hx711, but it sounds to me like this would work for you, yeah. I used a ETEKCITY scale, but the Sinocare one should work, yep. Probably can't help too much with the basic coding, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment