I'm trying to better understand C (and bluetooth) using a Raspberry Pi 3 b+ as the testing grounds. I started by writing a C program that uses BlueZ to scan for bluetooth devices (script pretty common and can be found here).

This scan always returns 0 devices. Double checked the Bluetooth GUI and when I click "Add Device" it shows a dozen or so Bluetooth devices (despite my program showing none). Thinking that this was caused by C inexperience, I used the hcitools CLI. Both scan, inq and lescan return no devices.

Any idea why this is the case? Is the hcitools (and BlueZ) messed up?

I've checked the status of the service, output here:

�� bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2019-03-16 19:03:01 EDT; 4s ago
     Docs: man:bluetoothd(8)
 Main PID: 31792 (bluetoothd)
   Status: "Running"
   CGroup: /system.slice/bluetooth.service
           ������31792 /usr/lib/bluetooth/bluetoothd

Mar 16 19:03:01 raspberrypi systemd[1]: Starting Bluetooth service...
Mar 16 19:03:01 raspberrypi bluetoothd[31792]: Bluetooth daemon 5.43
Mar 16 19:03:01 raspberrypi systemd[1]: Started Bluetooth service.
Mar 16 19:03:01 raspberrypi bluetoothd[31792]: Starting SDP server
Mar 16 19:03:01 raspberrypi bluetoothd[31792]: Bluetooth management interface 1.14 initialized
Mar 16 19:03:01 raspberrypi bluetoothd[31792]: Failed to obtain handles for "Service Changed" characteristic
Mar 16 19:03:01 raspberrypi bluetoothd[31792]: Sap driver initialization failed.
Mar 16 19:03:01 raspberrypi bluetoothd[31792]: sap-server: Operation not permitted (1)
Mar 16 19:03:01 raspberrypi bluetoothd[31792]: Endpoint registered: sender=:1.36 path=/A2DP/SBC/Source/1

I've also run hciconfig -a, output here:

hci0:   Type: Primary  Bus: UART
    BD Address: B8:27:EB:E1:9F:82  ACL MTU: 1021:8  SCO MTU: 64:1
    RX bytes:3323949 acl:0 sco:0 events:96931 errors:0
    TX bytes:6567 acl:0 sco:0 commands:143 errors:0
    Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
    Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
    Link policy: RSWITCH SNIFF 
    Link mode: SLAVE ACCEPT 
    Name: 'raspberrypi'
    Class: 0x480000
    Service Classes: Capturing, Telephony
    Device Class: Miscellaneous, 
    HCI Version: 4.2 (0x8)  Revision: 0xfc
    LMP Version: 4.2 (0x8)  Subversion: 0x6119
    Manufacturer: Broadcom Corporation (15)

Side note: When I try to set le scan parameters, I get an error that the operation is not permitted (even when running w/ sudo).

  • perhaps the Bluetooth GUI has permissions that your program does not have
    – jsotola
    Mar 17 '19 at 5:39
  • Which version of BlueZ are you using? You can find this using 'hcitool version'. Also, if bluetoothctl is available, try running and then issuing 'scan on' to see if the result is different. Mar 18 '19 at 6:41
  • I believe I found the issue. The GUI (a) has perms that my program does not have - required running with sudo and (b) picks up BLE devices without any indication that devices are using BLE vs standard and (c) does some form of caching such that standard devices found at time t are still shown at t+n. TLDR: BlueZ doesn't get BLE devices by default. GUI does show BLE devices. Leading to surface-level discrepancy. Mar 21 '19 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.