bluetooth device inquiry - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: bluetooth device inquiry (/thread-28724.html) |
bluetooth device inquiry - anne - Aug-01-2020 Two "inquiry " - scan for nearby bluetooth devices and two different results. Where is the logical error in the first usage of function bluetooth.discover_devices ? inquiry is basins BlueZ function and it takes time , which the first code does not monitors. Is that it ? I am asking for second opinion. CODE import bluetooth print("scanning for near-by bluetooth devices....") target_name = "My Phone" target_address = None nearby_devices = bluetooth.discover_devices() for bdaddr in nearby_devices: if target_name == bluetooth.lookup_name( bdaddr ): target_address = bdaddr break if target_address is not None: print ("found target bluetooth device with address "), target_address else: print ("could not find target bluetooth device nearby") import bluetooth print("Performing inquiry...") nearby_devices = bluetooth.discover_devices(duration=8, lookup_names=True, flush_cache=True, lookup_class=False) print("Found {} devices".format(len(nearby_devices))) for addr, name in nearby_devices: try: print(" {} - {}".format(addr, name)) except UnicodeEncodeError: print(" {} - {}".format(addr, name.encode("utf-8", "replace")))Output Quote:scanning for near-by bluetooth devices.... |