Perl bluetooth communications
I had a couple of notes on using Net::Bluetooth from a raspberry pi to talk to a Bluetooth serial port because I couldn’t get the example code given with Net::Bluetooth to work.
The following will connect to a mac address and send and receive data from it (in this particular example, a ESP32):
#!/usr/bin/perluse Net::Bluetooth;
use Data::Dumper;
use IO::Handle;
my $obj = Net::Bluetooth->newsocket(“RFCOMM”);$addr = ‘C4:4F:33:58:B6:FB’;
$port = 1;if($obj->connect($addr, $port) != 0) {
die “connect error: $!\n”;
}my $fh = $obj->perlfh();
$fh->autoflush(1);sleep(1);
print “sending \n”;
print $fh “V\n”;
print “receiving\n”;$buf = readline($fh);
print “Fetchhost: $buf\n”;