简体   繁体   English

替代BlueZ?

[英]Alternative to BlueZ?

I've been trying to get BlueZ working on my Ubuntu desktop for a good portion of the day. 我一直试图让BlueZ在我的Ubuntu桌面上正常工作的大部分时间。 It just won't work. 只是行不通。 I can pair my devices successfully to my computer via the system dialogue, but the BlueZ scan never finds anything. 我可以通过系统对话框将设备成功配对到计算机,但是BlueZ扫描从未找到任何东西。 Is there an alternative to BlueZ? 有BlueZ的替代品吗? Is there a way to manipulate a bluetooth device without BlueZ if the device is already paired? 如果设备已经配对,是否可以在没有BlueZ的情况下操作蓝牙设备?

For good measure, this is the code I've been running ( http://people.csail.mit.edu/albert/bluez-intro/c404.html#simplescan.c ): 好的,这是我一直在运行的代码( http://people.csail.mit.edu/albert/bluez-intro/c404.html#simplescan.c ):

 #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;
 }

I'm using the same code. 我正在使用相同的代码。 I went into my phone settings and toggled the setting that allows my phone to be visible to other devices. 我进入了手机设置,然后切换了允许我的手机在其他设备上显示的设置。 Then run the program again and it shows up in the list. 然后再次运行该程序,它会显示在列表中。 Hope this helps to at least verify the code is working. 希望这至少有助于验证代码是否正常。

try using bluetooth-internal library. 尝试使用蓝牙内部库。 used by btmgmt. 由btmgmt使用。 It is more structured than hcixxx tools direct hci_xx ioctls. 它比hcixxx工具直接的hci_xx ioctls更具结构化。

Just open the src/btmhmt.c and search for scan (or connect or whatever you want). 只需打开src / btmhmt.c并搜索扫描(或连接或任何您想要的内容)。

Although in both cases licensing issue will exists. 尽管在两种情况下都会存在许可问题。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM