0

Below is the modified code from the internet i'm executing on raspberrypi 4 to discover bluetooth devices

import bluetooth

print("Discovering bluetooth enabled devices ...")
nearby_devices = bluetooth.discover_devices(lookup_names = True,lookup_class = True)

num_devices = len(nearby_devices)
print("Number of discovered devices: " + str(num_devices))

for addr, name , device_class in nearby_devices:
        print("device MAC address : ",addr)
        print("device name : ",name)
        print("device Class : ", device_class)

but it doesn't discover the bluetooth devices, any pointers please

pi@raspberrypi:~/server $ python3 bluetuth.py
Discovering bluetooth enabled devices ...
Number of discovered devices: 0

Does the code need minimum execution time to allow raspberrypi time to discover new bluetooth devices?

bluetooth status on the raspberrypi terminal:

pi@raspberrypi:/usr/share/doc/bluez $ sudo systemctl status bluetooth
● bluetooth.service - Bluetooth service
     Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-08-14 05:17:13 BST; 19h ago
       Docs: man:bluetoothd(8)
   Main PID: 851 (bluetoothd)
     Status: "Running"
      Tasks: 1 (limit: 4915)
        CPU: 279ms
     CGroup: /system.slice/bluetooth.service
             └─851 /usr/libexec/bluetooth/bluetoothd

Aug 14 05:17:13 raspberrypi systemd[1]: Starting Bluetooth service...
Aug 14 05:17:13 raspberrypi bluetoothd[851]: Bluetooth daemon 5.55
Aug 14 05:17:13 raspberrypi systemd[1]: Started Bluetooth service.
Aug 14 05:17:13 raspberrypi bluetoothd[851]: Starting SDP server
Aug 14 05:17:13 raspberrypi bluetoothd[851]: Bluetooth management interface 1.21 initialized
Aug 14 05:17:13 raspberrypi bluetoothd[851]: profiles/sap/server.c:sap_server_register() Sap driver initialization failed.
Aug 14 05:17:13 raspberrypi bluetoothd[851]: sap-server: Operation not permitted (1)
Aug 14 05:17:13 raspberrypi bluetoothd[851]: Endpoint registered: sender=:1.25 path=/MediaEndpoint/A2DPSink/sbc
Aug 14 05:17:13 raspberrypi bluetoothd[851]: Endpoint registered: sender=:1.25 path=/MediaEndpoint/A2DPSource/sbc
Aug 14 05:17:13 raspberrypi bluetoothd[851]: Failed to set privacy: Rejected (0x0b)

bluetooth version:

pi@raspberrypi:~/server $ bluetoothd --version
5.55
pi@raspberrypi:~/server $ bluetoothctl --version
bluetoothctl: 5.55
SuperStormer
  • 4,997
  • 5
  • 25
  • 35
msang
  • 1
  • 1
  • yes i'm using pybluez – msang Aug 14 '22 at 23:59
  • I've added the `pybluez` tag, since that was not clear from your question and it is likely relevant to the answer. – Grismar Aug 15 '22 at 00:08
  • 1
    If you do `bluetoothctl scan on` on the command line does that find any devices? The pybluez project says "This project is not under active development". Is there a particular reason you are using pybluez? – ukBaz Aug 15 '22 at 05:45
  • Thannks @ukBaz, I tried above command, it appears to be working pi@raspberrypi:~ $ bluetoothctl scan on Discovery started [NEW] Device B1:94:D9:29:CF:53 POC1 [CHG] Device B1:94:D9:29:CF:53 RSSI: -33 [DEL] Device B1:94:D9:29:CF:53 POC1 – msang Aug 15 '22 at 11:53

0 Answers0