You can download this code by clicking the button below.
This code is now available for download.
This function scans for nearby Bluetooth devices and returns a list of device names and addresses.
Technology Stack : PyBluez, Bluetooth scanning, device discovery
Code Type : The type of code
Code Difficulty : Intermediate
import random
import bluetooth
def scan_for_devices():
"""
Scan for Bluetooth devices and return a list of device names and addresses.
"""
nearby_devices = bluetooth.discover_devices(duration=10, lookup_names=True)
device_list = []
for addr, name in nearby_devices:
device_list.append({"name": name, "address": addr})
return device_list