From 392a6c6abbe5d9267f7a9c6c55fd098d94f00281 Mon Sep 17 00:00:00 2001 From: Arslaan Pathan Date: Sun, 29 Mar 2026 15:02:58 +1300 Subject: Improve syncTime BLE and others --- FereFit_BLE_test.py | 26 -------------------------- FereFit_syncTime_BLE.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 26 deletions(-) delete mode 100644 FereFit_BLE_test.py create mode 100644 FereFit_syncTime_BLE.py diff --git a/FereFit_BLE_test.py b/FereFit_BLE_test.py deleted file mode 100644 index 59efac0..0000000 --- a/FereFit_BLE_test.py +++ /dev/null @@ -1,26 +0,0 @@ -import asyncio -from bleak import BleakScanner, BleakClient -import time, calendar - -async def sync(device_name: str): - print(f"Scanning for {device_name}...") - device = await BleakScanner.find_device_by_name(device_name, timeout=10) - if not device: - print("Watch not found!") - return - print(f"Found at {device.address}") - try: - async with BleakClient(device) as client: - ts = int(time.time()) - offset = calendar.timegm(time.localtime()) - calendar.timegm(time.gmtime()) - packet = bytes([0x01]) + ts.to_bytes(4,'big') + offset.to_bytes(4,'big') + bytes([0,0,0]) - await client.write_gatt_char("6E40FC20-B5A3-F393-E0A9-E50E24DCCA9E", packet) - print(f"Time synced! ts={ts} offset={offset}") - except Exception as e: - print(f"Failed: {e}") - -if __name__ == "__main__": - watch_name = input("Enter watch name shown in BLE discovery (default: Watch ULTRA): ") - if watch_name == "": - watch_name = "Watch ULTRA" - asyncio.run(sync(watch_name)) diff --git a/FereFit_syncTime_BLE.py b/FereFit_syncTime_BLE.py new file mode 100644 index 0000000..0076127 --- /dev/null +++ b/FereFit_syncTime_BLE.py @@ -0,0 +1,33 @@ +import asyncio +import sys +try: + from bleak import BleakScanner, BleakClient +except ModuleNotFoundError: + print("Error importing bleak, are you sure you installed it?") + print("Try running the following command: \"pip3 install bleak\"") + print("If that fails, try this: \"pip3 install bleak --break-system-packages\"") + sys.exit(1) +import time, calendar + +async def sync(device_name: str): + print(f"Scanning for {device_name}...") + device = await BleakScanner.find_device_by_name(device_name, timeout=10) + if not device: + print("Watch not found!") + return + print(f"Found at {device.address}") + try: + async with BleakClient(device) as client: + ts = int(time.time()) + offset = calendar.timegm(time.localtime()) - calendar.timegm(time.gmtime()) + packet = bytes([0x01]) + ts.to_bytes(4,'big') + offset.to_bytes(4,'big') + bytes([0,0,0]) + await client.write_gatt_char("6E40FC20-B5A3-F393-E0A9-E50E24DCCA9E", packet) + print(f"Time synced! ts={ts} offset={offset}") + except Exception as e: + print(f"Failed: {e}") + +if __name__ == "__main__": + watch_name = input("Enter watch name shown in BLE discovery (default: Watch ULTRA): ") + if watch_name == "": + watch_name = "Watch ULTRA" + asyncio.run(sync(watch_name)) -- cgit v1.2.3