Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- from bleak import BleakClient
- DEVICE_ADDRESS = "CE:51:8C:f0:BC:DB"
- WRITE_CHAR_UUID = "1086fff1-3343-4817-8bb2-b32206336ce8"
- NOTIFY_CHAR_UUID = "1086fff2-3343-4817-8bb2-b32206336ce8"
- CELSIUS = "20010c2d"
- FAHREN = "20010f30"
- HANDSHAKE_COMMANDS = [
- bytes.fromhex("01098a7a13b73ed68b67c2a0"),
- bytes.fromhex("410041"),
- bytes.fromhex("28040a2d8c6e5d"),
- bytes.fromhex("20010f30"), # Initializes device in fahrenheit, change f30 to c2d for Celsius
- bytes.fromhex("23060200ffffffff27"),
- bytes.fromhex("23060400ffffffff29")
- ]
- def notification_handler(sender, data):
- print("Notification from {sender}: {data.hex()}")
- hex_data = data.hex()
- probe1 = hex_data[14:18]
- probe2 = hex_data[22:26]
- def decimal_conversion(probe):
- if probe != 'ffff':
- return float(probe[:-1] + '.' + probe[-1])
- else:
- return probe
- print(f"Probe1 Temps: {decimal_conversion(probe1)}, Probe2 Temps: {decimal_conversion(probe2)}")
- async def change_mode():
- async with BleakClient(DEVICE_ADDRESS) as client:
- print(f"Connecting to {DEVICE_ADDRESS}...")
- await client.write_gatt_char(WRITE_CHAR_UUID, FAHREN)
- print("Mode Changed.")
- async def main():
- async with BleakClient(DEVICE_ADDRESS) as client:
- print("Connected to device")
- for i, cmd in enumerate(HANDSHAKE_COMMANDS, 1):
- print(f"Sending handshake {i}: {cmd.hex()}")
- await client.write_gatt_char(WRITE_CHAR_UUID, cmd)
- await asyncio.sleep(0.4) # Slight delay between writes
- print("Subscribing to notifications...")
- await client.start_notify(NOTIFY_CHAR_UUID, notification_handler)
- print("Listening for notifications. Press Ctrl+C to stop.")
- try:
- while True:
- await asyncio.sleep(1)
- except KeyboardInterrupt:
- print("Stopping...")
- await client.stop_notify(NOTIFY_CHAR_UUID)
- asyncio.run(main())
- asyncio.run(change_mode())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement