Commit graph

121 commits

Author SHA1 Message Date
Samuel Lang
9aedbf3bbc Auto Time Sync script
This program automatically synchronizes the time on BTHome-compatible Bluetooth Low Energy (BLE) THB2 firmware flashed devices.
It continuously scans for devices that advertise the BTHome service UUID (0xFCD2) and ensures their
internal clocks are synchronized with the host computer's time.

This script could be executed by a scheduled cron job for instance
to rectify the time drift of the devices.

Key Features:
- Discovers BTHome devices using service UUID 0xFCD2
- Automatically connects and syncs time when drift exceeds 3 seconds
- Supports multiple devices with concurrent processing
- Implements retry mechanism for failed connections
- Prevents excessive reconnections with 60-second cooldown
- Includes timeout protection for unresponsive devices

Technical Implementation:
1. Device Discovery:
   - Uses BleakScanner with a detection callback
   - Filters devices by BTHome service UUID (0xFCD2)
   - Checks both service UUIDs and service data

2. Connection Process:
   - Establishes BLE connection with 30-second timeout
   - Discovers services and sets up notifications
   - Uses characteristic 0xFFF4 for time sync commands

3. Time Synchronization:
   - Reads current device time via command 0x33
   - Compares with system time accounting for timezone
   - Updates device time if difference exceeds 3 seconds
   - Uses command 0x23 to set new time value

4. Error Handling:
   - Implements connection retries (max 2 attempts)
   - Includes timeout protection for all BLE operations
   - Gracefully handles disconnections and exceptions

Usage:
Run the script directly to start the auto time sync service:
    python auto_time_sync.py

The program will continuously scan for and process BTHome devices, logging all operations
and any errors that occur. Use Ctrl+C to gracefully stop the service.
2025-01-25 17:54:25 +00:00
Victor
c3d63e24ab
https://github.com/pvvx/THB2/discussions/116#discussioncomment-11857072 2025-01-16 19:45:14 +03:00
pvvx
171c48307a update README.md 2025-01-15 09:15:46 +03:00
pvvx
fdd4c40b81 гз 2025-01-15 09:11:55 +03:00
Victor
11a1d51ed5
Update README.md 2025-01-15 09:08:37 +03:00
Victor
55f0e8ec37
Update README.md 2025-01-15 09:03:20 +03:00
pvvx
2ff2143add v2.0 beta7 2024-12-25 16:23:23 +03:00
pvvx
891880dac3 v2.0b6 add Buzzer 2024-12-13 18:19:29 +03:00
pvvx
145a725707 del v1.9 2024-12-12 07:36:09 +03:00
pvvx
b683630d0f v2.0 beta5 (fix erase flash in OTA BOOT, KEY2 size Flash) 2024-12-10 23:36:09 +03:00
pvvx
75504b6693 v2.0 beta4 2024-12-10 21:35:48 +03:00
pvvx
a818721a61 update README 2024-12-10 11:04:17 +03:00
Victor
0e768b37e2
Update README.md 2024-12-08 19:02:16 +03:00
Victor
9c987360f0
Update README.md 2024-12-08 18:56:40 +03:00
pvvx
7238ae7e11 v2.0 beta3 2024-12-08 18:53:10 +03:00
pvvx
b6b3ea746e update README 2024-12-07 01:00:17 +03:00
pvvx
7a4e9f6742 ver2.0 Beta2 2024-12-06 23:05:45 +03:00
pvvx
43a57ff194 update 2024-11-28 07:41:00 +03:00
pvvx
c404bc9cd2 update README.md 2024-11-23 22:43:47 +03:00
pvvx
70f608bff7 update README 2024-11-22 15:00:21 +03:00
pvvx
90b2eb964f v2.0(beta) - added CHT832x 2024-11-22 14:56:19 +03:00
pvvx
94e7764794 README.md tab gpio 2024-11-10 12:21:05 +03:00
pvvx
3d16327c7e update README-ru.md 2024-11-10 12:11:54 +03:00
pvvx
acb8c421c9 update README.md 2024-11-10 11:49:22 +03:00
pvvx
15bbcdacc6 v1.9 2024-11-06 10:47:33 +03:00
pvvx
cf80786703 update README 2024-08-18 04:53:27 +03:00
pvvx
1e8684f258 ver 1.8b 2024-08-18 04:49:56 +03:00
Victor
f9649f8437
Update README.md 2024-07-12 10:50:15 +03:00
Victor
6393ebfec0
Update README.md 2024-07-12 10:49:38 +03:00
Victor
4e588be37d
Update README.md 2024-07-01 19:32:52 +03:00
Victor
8cdf96ab75
Merge branch 'master' into master 2024-07-01 19:31:49 +03:00
Victor
fc15f3a0e3
Update README.md 2024-07-01 19:29:16 +03:00
Victor
c1c48a54c8
Update README.md 2024-07-01 19:02:32 +03:00
Victor
478e1a9e0a
Update README.md 2024-07-01 19:01:04 +03:00
Mlb
1e80645293
Cleaning README.md 2024-06-30 16:52:05 +02:00
Mlb
69acac038d
Update README.md 2024-06-30 15:58:35 +02:00
Mlb
4dfd3e4770
Finishing the translation of README.md 2024-06-30 15:50:58 +02:00
Mlb
b60449e417
Update README.md 2024-06-30 15:08:14 +02:00
Mlb
f614fd1cc6
Update README.md 2024-06-30 14:59:53 +02:00
Mlb
df80e3252e
Update README.md 2024-06-30 14:53:33 +02:00
Mlb
de2730f727
Starting the translation of README.md 2024-06-30 12:47:24 +02:00
Victor
e78807f638
Update README.md 2024-06-29 00:13:15 +03:00
Victor
30865f0e67
Update README.md 2024-06-29 00:07:08 +03:00
Victor
99bfd9fc62
Update README.md 2024-06-29 00:03:44 +03:00
Victor
b55aa6c859
Update README.md 2024-04-11 19:50:41 +03:00
pvvx
f8faf86b71 Merge branch 'master' of github.com:pvvx/THB2 2024-04-11 19:40:36 +03:00
pvvx
35b62a3e20 ver 1.7 2024-04-11 19:40:09 +03:00
Victor
522a6c1d5e
Update README.md 2024-04-02 19:45:47 +03:00
Victor
e57015cf30
Update README.md 2024-03-27 09:53:57 +03:00
Victor
af7c136b5e
Update README.md 2024-03-27 00:02:01 +03:00