Commit graph

266 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
85a8c14d3b
Update README-ru.md 2025-01-15 09:06:26 +03:00
Victor
55f0e8ec37
Update README.md 2025-01-15 09:03:20 +03:00
pvvx
f9cef81b71 end v2.0 beta 2024-12-28 16:45:27 +03:00
pvvx
14843139c7 fix LCD TH05F 2024-12-26 16:08:49 +03:00
pvvx
2ff2143add v2.0 beta7 2024-12-25 16:23:23 +03:00
pvvx
09f742e2fb update IDs 2024-12-16 10:26:53 +03:00
pvvx
db0f163136 change fw id KEY2 2024-12-16 10:21:34 +03:00
pvvx
891880dac3 v2.0b6 add Buzzer 2024-12-13 18:19:29 +03:00
pvvx
090a3feabd v2.0 beta6: max adv.interval 15 sec, default 5 sec. 2024-12-12 15:01:05 +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
c1298f09a6 fix comment 2024-12-10 22:00:08 +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
pvvx
94720a5ea9 fix settings 2024-12-08 19:47:13 +03:00
Victor
98c5811d15
Update README-ru.md 2024-12-08 19:02:52 +03:00
Victor
0e768b37e2
Update README.md 2024-12-08 19:02:16 +03:00
Victor
8b90d61070
Update README-ru.md 2024-12-08 18:57:38 +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
964f3eda14 Beta2 ver2.0 2024-12-06 23:09:23 +03:00
pvvx
7a4e9f6742 ver2.0 Beta2 2024-12-06 23:05:45 +03:00
pvvx
742e68b482 update v2.0b 2024-12-06 02:58:36 +03:00
pvvx
101b17a60a update README.md 2024-12-06 02:44:38 +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
ba0601e1db v1.9 2024-11-06 11:12:09 +03:00
pvvx
15bbcdacc6 v1.9 2024-11-06 10:47:33 +03:00
pvvx
bab7273250 https://github.com/pvvx/THB2/issues/1#issuecomment-2423661455 2024-10-19 11:07:50 +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
f6c04dc5d7
Create bin / README.md 2024-07-12 10:38:15 +03:00
Victor
4e766bf702
Update README-ru.md 2024-07-12 10:35:15 +03:00
Victor
6e755bfde2
Update README-ru.md 2024-07-12 10:23:53 +03:00
Victor
a2a3303887
Update README-ru.md 2024-07-12 10:17:32 +03:00
Victor
9a756684fc
Update README-ru.md 2024-07-12 10:13:24 +03:00
Victor
ba1a246903
Update README-ru.md 2024-07-12 10:12:13 +03:00