-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
31 lines (24 loc) · 846 Bytes
/
main.py
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
'''
Created on Mar 2020
Agung Pambudi <[email protected]>
Example, I have a problem with bluetooth when the program runs after adapter.start(),
sometimes the status changes from UP RUNNING to DOWN INIT RUNNING,
then stuck or freezes in that status.
'''
import pygatt
def checkDevice():
try:
adapter = pygatt.GATTToolBackend(hci_device='hci0') # Check hciconfig on terminal
adapter.start()
for discover in adapter.scan(run_as_root=True, timeout=5):
if discover['name'] == '<bluetooth name>':
device = adapter.connect(discover['address'])
print('Connected with device')
device.disconnect()
except:
print('Something went wrong with the bluetooth, waiting for bluetooth firmware to reset until status is UP RUNNING again')
checkDevice()
finally:
adapter.stop()
if __name__ == '__main__':
checkDevice()