Bluetooth Device Discovery Function

  • Share this:

Code introduction


The function uses the Bluetooth module from the PyBluez library to discover nearby Bluetooth devices. It returns a list containing device addresses and names.


Technology Stack : PyBluez, Bluetooth

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random
from pybluez import bluetooth

def discover_devices():
    # Discover devices around using Bluetooth
    nearby_devices = bluetooth.discover_devices(duration=5, lookup_names=True)
    return nearby_devices