Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Bluetooth LE?

by cavac (Prior)
on Aug 05, 2025 at 08:37 UTC ( [id://11165961]=perlquestion: print w/replies, xml ) Need Help??

cavac has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to connect to a Bluetooth LE (low energy) device, specifically the MXTP-100 printer (that extremely cheap thermal printer with the cat ears). I tried Net::Bluetooth, but that doesn't seem to support Low Energy devices.

I can connect and print just fine to an old Epson bluetooth printer (not LE), but newer LE devices don't seem to work with Net::Bluetooth.

To be honest, i have absolutely no idea what i'm doing. Does anyone have any suggestions?

EDIT: Ooops, sorry, forgot to include my test code:

use Net::Bluetooth; use strict; use warnings; use Time::HiRes qw(sleep); use Data::Dumper; #my $printer_addr='00:01:90:AE:B5:9C'; # Epson my $printer_addr='68:08:09:14:B7:4F'; # MXTP-100 #### Could retry here instead of exiting. die "BT GPS not found." unless(defined($printer_addr)); #### Search for the serial service (0x1101) on my printer my @sdp_array = sdp_search($printer_addr, "1101", ""); die "No service records found" unless(@sdp_array); + my $port = 0; #### Loop through all the service records. #### foreach service record .... print Dumper(@sdp_array); foreach my $rec_ref (@sdp_array) { #### Get the RFCOMM port number for the service. if(exists($rec_ref->{RFCOMM})) { $port = $rec_ref->{RFCOMM}; last; } } die "No RFCOMM record found." unless($port > 0); print "BT Serial port found $printer_addr $port \n"; my $obj = Net::Bluetooth->newsocket("RFCOMM"); die "socket error: $!\n" unless(defined($obj)); die "connect error: $!\n" if($obj->connect($printer_addr, $port) != 0) +; #### Create a Perl filehandle for reading and writing. *SERVER = $obj->perlfh(); SERVER->autoflush(1); my @lines = <DATA>; foreach my $line (@lines) { #print $line; #print SERVER $line; SERVER->write($line); #sleep(0.1); } for(1..8) { SERVER->write("\n"); } __DATA__ This was a triumph. I'm making a note here: huge success. It's hard to overstate My satisfaction.

(I just hacked one of the examples, so code quality is low. Also please ignore the mentioning of GPS, i just didn't bother to update all variable names and comments)

PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP
Also check out my sisters artwork and my weekly webcomics

Replies are listed 'Best First'.
Re: Bluetooth LE?
by Corion (Patriarch) on Aug 05, 2025 at 09:02 UTC

    My main realization was that Bluetooth LE is mostly different from "normal" ("basic rate", BR) Bluetooth.

    Normal Bluetooth is mostly exposed to the OS as a socket/serial connection, with all the protocol around it, and you can mostly use any of the serial TTY modules like SerialPort.

    Bluetooth LE puts a lot more work on the "master", by doing away with the "connection" model and expects the main machine to poll/poke addresses on the BLE device instead to transfer data.

    In my investigations, I did not find readymade Perl modules, but in theory using DBus directly to talk to Bluetooth could work (if your OS uses DBus).

    BLE terminology, topology

    BLE primer

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11165961]
Approved by Discipulus
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2025-12-09 07:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (88 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.