Raspberry Pi 3 BLE scanning
<p>I am trying to implement the next code in a Raspberry Pi 3 to scan for BLE devices:</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;unistd.h&gt;
#include &lt;sys/socket.h&gt;
#include &lt;bluetooth/bluetooth.h&gt;
#include &lt;bluetooth/hci.h&gt;
#include &lt;bluetooth/hci_lib.h&gt;

int main(int argc, char **argv)
{
    inquiry_info *ii = NULL;
    int max_rsp, num_rsp;
    int dev_id, sock, len, flags;
    int i;
    char addr[19] = { 0 };
    char name[248] = { 0 };

    dev_id = hci_get_route(NULL);
    sock = hci_open_dev( dev_id );
    if (dev_id &lt; 0 || sock &lt; 0) {
        perror("opening socket");
        exit(1);
    }

    len  = 8;
    max_rsp = 255;
    flags = IREQ_CACHE_FLUSH;
    ii = (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info));

    num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &amp;ii, flags);
    if( num_rsp &lt; 0 ) perror("hci_inquiry");

    for (i = 0; i &lt; num_rsp; i++) {
        ba2str(&amp;(ii+i)-&gt;bdaddr, addr);
        memset(name, 0, sizeof(name));
        if (hci_read_remote_name(sock, &amp;(ii+i)-&gt;bdaddr, sizeof(name), 
            name, 0) &lt; 0)
        strcpy(name, "[unknown]");
        printf("%s  %s\n", addr, name);
    }

    free( ii );
    close( sock );
    return 0;
}
</code></pre>

<p>The problem is that <code>num_rsp</code> is equal to zero, that is, it is not finding any device. </p>

<p>However, if I use the command <code>$ sudo hcitool lescan</code>in the terminal, it finds all the devices available.</p>

<p>Can anyone point me in the right direction to troubleshoot this? Is there any other way to implement <code>hcitool lescan</code> as C++ code?</p>

<p>Thanks in advance.</p>