Net :: Bluetooth无法发现设备

时间:2018-09-04 19:28:22

标签: linux perl bluetooth-lowenergy

我尝试连接到LegoBoostPerl下的Debian 4.9.110-3+deb9u4。这是一种低功耗蓝牙(BLE)设备。我可以使用gatttoolhci*实用程序来发现并连接到它,但是我对Perl不走运。我尝试了以下代码:

use Net::Bluetooth;
use Data::Dumper;

print "Get remote devices...\n";
my $rDevice = get_remote_devices();
print Dumper $rDevice;

my $addr = "00:16:53:A5:3E:50";
print "SDP search...\n";
my @spd = sdp_search($addr, "", ""); # LegoBoost
print Dumper \@spd;

返回undef[undef]。我什至试过了,但是没有运气。

我也尝试连接到该设备:

print "Connect to device...\n";
my $obj = Net::Bluetooth->newsocket("RFCOMM");
defined($obj) or die "socket error $!\n";
print "Socket got ", Dumper $obj;
system 'lsof', '-p', $$;

my $port = 14;
if($obj->connect($addr, $port) != 0) { die "connect error: $!\n";}
print "Connected...\n";
sleep 5;

#### create a Perl filehandle for reading and writing
my $fd = $obj->perlfh();
print Dumper $fd;
close $fd or die;

输出:

Connect to device...
Socket got $VAR1 = bless( {
                 'PROTO' => 'RFCOMM',
                 'SOCK_FD' => 4
               }, 'Net::Bluetooth' );
connect error: Host is down

任何想法都值得赞赏!

提前谢谢!

1 个答案:

答案 0 :(得分:1)

看来Net::Bluetooth适用于普通的蓝牙设备,而不适用于BLE。我阅读了Perl软件包Net-Bluetooth-0.41的源代码。模块的get_remote_devices子在Bluetooth.c中定义为C函数。它首先调用hci_get_route(在libbluetooth.so中),然后调用hci_inquiry,后者查询蓝牙设备,但不查询BLE设备。 :(