Draft: Add Bluetooth SPP/RFCOMM driver - #427
Conversation
Includes BlueZ for device discovery and an SPP (serial port profile) layer on top for devices such as the Orgbro X1. Fixes: michaelrsweet#421 Assisted-by: DeepSeek:v4-pro
|
One reconnect issue turned up while testing with an RP425. An initial open/write/close succeeded, but an immediate reopen could fail with The tested patch:
I deliberately limited this to one retry. During testing, repeated rapid reconnect attempts left the RP425 unresponsive over Bluetooth until it was power-cycled. After restarting the printer:
The supporting test changes also keep the pure Bluetooth address and URI tests active when BlueZ/D-Bus support is unavailable. The broader local test run reaches an unrelated Avahi @johnbeard your scrappy prototype code is pretty close IMO to getting all the basics working. Printing a single page worked without any changes, but more than one failed until I did the clean up in the suggested changes. This also adds a simple retry mechanism which is probably worth having. The replacement review contains ten smaller, non-overlapping suggestions. They form one patch and should be applied as a batch. Linux CI follow-upThis file is unchanged in the MR, so GitHub cannot attach an inline suggestion to it. diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -21 +21 @@ jobs:
- run: sudo apt-get install -y avahi-daemon cppcheck libavahi-client-dev libjpeg-dev libpam-dev libpng-dev libssl-dev libusb-1.0-0-dev zlib1g-dev
+ run: sudo apt-get install -y avahi-daemon cppcheck libavahi-client-dev libbluetooth-dev libdbus-1-dev libjpeg-dev libpam-dev libpng-dev libssl-dev libusb-1.0-0-dev zlib1g-dev
@@ -35 +35 @@ jobs:
- run: ./configure --enable-debug --enable-debug-printfs --enable-maintainer --with-sanitizer=address
+ run: ./configure --enable-bluetooth --enable-debug --enable-debug-printfs --enable-maintainer --enable-sanitizer |
|
Per @michaelrsweet instructions I did use GPT 5.6-sol in High mode to review my changes and to help write the summary but all the debug, initial coding and tests were by hand. The printer I tested with for this round was a Rongta RP425 running v1.11 firmware. |
emolitor
left a comment
There was a problem hiding this comment.
These ten replacement suggestions form one tested patch and should be applied as a batch. The Linux CI follow-up is included in the existing conversation comment because that file is unchanged in this MR.
|
(Updated) So some quick feedback:
|
Co-authored-by: Eric Molitor <534583+emolitor@users.noreply.github.com>
Thank you very much - I'm sure it's pretty obvious that I basically only got as far as printing one label at a time! To be frank there's something specifically about socket syscall loops that gives me an instant headache, so I'm very grateful for any help! I also applied the CI fixes as a separate commit as suggested. |
Thank you very much for the feedback. I'm really pleased I'm not completely off-piste here! I'll be really interested to know about performance specifics. Not being super familiar with this code (or BT in general, TBH) I don't really know where I'd look, so it's interesting to me.
And:
So that looks promising, except that 1452 = 0x5AC seem to be: But then none of the BT devices I have paired seem to agree with https://bitbucket.org/bluetooth-SIG/public/src/main/assigned_numbers/company_identifiers/company_identifiers.yaml so maybe that's the wrong mapping to use. But I think because this is in the cache that we can get the VID/PID (even if they might not be the expected company...?) without having to actively connect and query the service. |
|
I have some time this week to work a bit more on this @johnbeard or @michaelrsweet, anything in particular you want me to dig into? I was going to look at testing this a bit more and taking a look at how hard it would be to add BLE / GATT / L11 support for some of the cheap BLE printers I have. |
|
Hi @emolitor sorry it took a while to get back to you. Something has "come up" in real life so I might not be able to engage too much with this in the next handful of weeks. Basically what I'm not least happy with is the matching system. There's not a lot of stuff to match on: looks like we get to see, for the Orgbro X1 at least:
Assuming these are stable, perhaps an IEEE string like Other than that, I don't really have anything else to dig into at the moment. I'm more than happy for you to take this branch and run with it if you have time and printers to dig in deeper right now. I will try to remain available for testing/etc too, but I can't promise too much I'm afraid, and I don't want to bog down your progress! |
|
Work got intense over the past few weeks so only now just coming back to this. :) |

Includes BlueZ for device discovery and an SPP (serial port profile) layer on top for devices such as the Orgbro X1.
Fixes: #421
This does work and I can print from an Orgbro X1 Bluetooth printer with a driver registration like:
This is a draft PR because I'm still working on tidying it up more and especially thinking about the matching method. For now, I've made a dangerous-feeling change around here just to get it working.
But @emolitor said they had time this weekend to mess with their printers, so here it is :-D. But I don't expect any review of it as I have just squashed several weeks worth of messy refactors, dead ends, and so on into a big blobby commit. (Of course I also won't mind if someone just takes it and beats it into shape, or makes any comments!)
I've also only tried it on Linux and don't have any other OSs I can try.
Other questions that occur at this point:
Full disclosure: I have used Deepseek v4 Pro to help with this, but it's not just vibe-coded!