0

I am running some well-known C++ sample code on Raspberry Pi 3 (running as a client on the latest Raspbian version) for communication with BLE devices (running as servers) from VS2017 C++ for Linux project in debug mode. My project compiles without errors and even warnings. I use the BlueZ library's HCI finctions. Please advise me why the call to the BlueZ hci_le_set_scan_parameters() function fails (returns -1). From

Here is the link to the original C++ code I use without any changes:https://github.com/carsonmcdonald/bluez-experiments/blob/master/experiments/scantest.c

Thank you in advance.

Paul Tomov
  • 79
  • 1
  • 5
  • Obviously hci_le_set_scan_parameters() function requires root or elevated privileges. From command line sudo gatttool commands worked fine. The possible solutions like this one (https://stackoverflow.com/questions/34723861/calling-a-c-function-with-root-privileges-without-executing-the-whole-program?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa) to temporarily set up root privileges in the C++ code before calling the HCI function did not work. – Paul Tomov Apr 11 '18 at 19:20

1 Answers1

1

Besides requiring elevated privileges, there's also the possibility that your bluetooth controller is in an odd state. There are two ways to fix it:

  • Just wait
  • Use bluetoothctl

Run bluetoothctl as root (sudo bluetoothctl), then execute the following commands

  • agent on
  • default-agent
  • scan on
  • scan off
  • agent off
  • exit

That should be enough to kick your controller and get the HCI functions working again. But remember, you most likely have to have elevated privileges to execute those commands.

jeff
  • 572
  • 5
  • 9