-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfilter_bluetoothctl.py
More file actions
51 lines (41 loc) · 1.25 KB
/
filter_bluetoothctl.py
File metadata and controls
51 lines (41 loc) · 1.25 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
"""Find info for a bluetooth device with bluetoothctl"""
import subprocess
import time
"""
MACs:
80:E1:27:9D:53:6E - Flipper Inolin
24:95:2F:AB:2O:CD - Pixel Buds
DC:E5:5B:2B:65:9D - Pixel
"""
def get_bluetooth_info():
# Run the bluetoothctl info command
result = subprocess.run(['bluetoothctl', 'info', '24:95:2F:AB:2O:CD'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True)
return result.stdout
def extract_rssi(info):
# Find the line that contains 'RSSI:'
for line in info.splitlines():
if "RSSI:" in line:
return line
return None
def main():
while True:
try:
info = get_bluetooth_info()
#print(info)
if "not available" in info and "DeviceSet" not in info:
print("Not available")
break
rssi_line = extract_rssi(info)
if rssi_line:
print(rssi_line)
else:
print("Device not available.")
except Exception as e:
print(f"An error occurred: {e}")
# Wait for 1 second before the next iteration
time.sleep(1)
if __name__ == "__main__":
main()