-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_fix.py
More file actions
54 lines (44 loc) · 1.78 KB
/
Copy pathdebug_fix.py
File metadata and controls
54 lines (44 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import sys
# FIX: Set CoInitialize security model to MTA (Multi-Threaded Apartment)
# This MUST be done before importing 'bleak' or 'pythoncom'
try:
sys.coinit_flags = 0
except AttributeError:
pass
import asyncio
import logging
from bleak import BleakScanner, BleakClient
# Configure Logging
logging.basicConfig(level=logging.DEBUG)
TARGET_ADDRESS = "32:34:42:35:F1:00"
async def main():
print("----------------------------------------------------------------")
print(" BLUETOOTH ADVANCED DIAGNOSTIC")
print("----------------------------------------------------------------")
print("1. Please open Windows Settings -> Bluetooth & devices")
print("2. Keep that window OPEN and VISIBLE.")
print("3. Ensure your Ring is charged and close to the PC.")
print("----------------------------------------------------------------")
print("Scanning for 15 seconds (Passive + Active)...")
# 1. Broad Scan
devices = await BleakScanner.discover(timeout=15.0)
found = False
for d in devices:
name = d.name or "Unknown"
print(f" [Found] {d.address} | Name: {name} | RSSI: {d.rssi}")
if d.address == TARGET_ADDRESS:
found = True
print(" >>> TARGET FOUND IN SCAN! <<<")
if not found:
print("\n[Warn] Target not in scan list. Attempting direct blind connection anyway...\n")
# 2. Direct Connection Attempt
print(f"Connecting to {TARGET_ADDRESS}...")
try:
async with BleakClient(TARGET_ADDRESS, timeout=20.0) as client:
print(f" >>> CONNECTED! <<<")
print(f" Services: {client.services}")
await asyncio.sleep(5)
except Exception as e:
print(f" [Error] Direct connection failed: {e}")
if __name__ == "__main__":
asyncio.run(main())