내가 BLE 장치를 검색하는 라즈베리 파이 3에서 다음 코드를 구현하기 위해 노력하고 있습니다 : 그것은 아니다,라즈베리 파이 3 BLE 스캔
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
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 < 0 || sock < 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, &ii, flags);
if(num_rsp < 0) perror("hci_inquiry");
for (i = 0; i < num_rsp; i++) {
ba2str(&(ii+i)->bdaddr, addr);
memset(name, 0, sizeof(name));
if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name),
name, 0) < 0)
strcpy(name, "[unknown]");
printf("%s %s\n", addr, name);
}
free(ii);
close(sock);
return 0;
}
문제는 num_rsp
이 0 일이라는 것이다 모든 장치를 찾는 것.
그러나 터미널에서 $ sudo hcitool lescan
명령을 사용하면 사용 가능한 모든 장치가 검색됩니다.
누구나 올바른 방향으로이 문제를 해결할 수 있습니까? 다른 방법으로 hcitool lescan
을 C++ 코드로 구현할 수 있습니까?
미리 감사드립니다.
이 봐 [답변] (http://stackoverflow.com/questions/30386577/c-c-ble-read-write-example-with-bluez) – bluepinto