Bluetooth Device Scanner Function

  • Share this:

Code introduction


This function uses the bluetooth module from the PyBluez library to scan for nearby Bluetooth devices and returns a list containing the device names and addresses.


Technology Stack : PyBluez, bluetooth module

Code Type : Function

Code Difficulty : Intermediate


                
                    
def scan_for_devices():
    import bluetooth
    nearby_devices = bluetooth.discover_devices(duration=5, lookup_names=True)
    return nearby_devices