Created
February 17, 2020 14:34
-
-
Save tilman/01b69f55c53e62eb25c11cb797479260 to your computer and use it in GitHub Desktop.
This file contains 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 python3 | |
"""PyBluez simple example asyncronous-inquiry.py | |
Demonstration of how to do asynchronous device discovery by subclassing | |
the DeviceDiscoverer class | |
Linux only (5/5/2006) | |
Author: Albert Huang <albert@csail.mit.edu> | |
$Id: asynchronous-inquiry.py 405 2006-05-06 00:39:50Z albert $ | |
""" | |
import select | |
import bluetooth | |
class MyDiscoverer(bluetooth.DeviceDiscoverer): | |
def pre_inquiry(self): | |
self.done = False | |
def device_discovered(self, address, device_class, rssi, name): | |
# print("{} - {}".format(address, name)) | |
# get some information out of the device class and display it. | |
# voodoo magic specified at: | |
# https://www.bluetooth.org/foundry/assignnumb/document/baseband | |
major_classes = ("Miscellaneous", | |
"Computer", | |
"Phone", | |
"LAN/Network Access Point", | |
"Audio/Video", | |
"Peripheral", | |
"Imaging") | |
major_class = (device_class >> 8) & 0xf | |
print("{}, {}, {}, {}".format(address, name, major_classes[major_class], rssi)) | |
def inquiry_complete(self): | |
self.done = True | |
d = MyDiscoverer() | |
d.find_devices(lookup_names=True) | |
readfiles = [d, ] | |
while True: | |
rfds = select.select(readfiles, [], [])[0] | |
if d in rfds: | |
d.process_event() | |
if d.done: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment