Last active
January 5, 2023 22:50
-
-
Save Langerz82/c62ec95847d8d1f3bf34eae88232d2b9 to your computer and use it in GitHub Desktop.
EE-bluetooth-agent-test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import time | |
from bluetool import Bluetooth | |
if __name__ == "__main__": | |
bt = Bluetooth() | |
print('Scanning for available devices for 60 seconds, please wait...') | |
bt.start_scanning(60) | |
time.sleep(10) | |
print('Getting pairable devices, please wait...') | |
devices = bt.get_devices_to_pair() | |
for device in devices: | |
mac = device['mac_address'].decode('utf-8') | |
name = device['name'].decode('utf-8') | |
icon = bt.get_device_property(mac,'Icon') | |
if not icon or (icon and icon == 'input-gaming'): | |
print('Found MAC: {}\tName: {}'.format(mac,name)) | |
print('Found controller {} Name: {}'.format(mac,name)) | |
if bt.get_device_property(mac,'Trusted') != 1: | |
print('Trusting {}, quick pause') | |
bt.trust(mac) | |
time.sleep(5) | |
if bt.get_device_property(mac,'Trusted') == 1: | |
print('Trusted {}, then pairing...'.format(name)) | |
if bt.get_device_property(mac,'Paired') != 1: | |
print('Pairing {}, quick pause') | |
bt.pair(mac) | |
time.sleep(5) | |
if bt.get_device_property(mac,'Paired') == 1: | |
print('Paired {}, then connecting...'.format(name)) | |
if bt.get_device_property(mac,'Connected') != 1: | |
print('Connecting {}, quick pause') | |
bt.connect(mac) | |
time.sleep(2) | |
if bt.get_device_property(mac,'Connected') == 1: | |
print('Connected {}, exiting...'.format(name)) | |
else: | |
print('Connect Error {}, exiting...'.format(name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment