Repository navigation
Add a Bambu Lab Printer widget that reads printers over MQTT - #23
Open
masonjmiller wants to merge 5 commits into
Open
masonjmiller wants to merge 5 commits into
masonjmiller wants to merge 5 commits into
Conversation
Bambu Lab printers are the 3D printers most likely to sit on a desk next to an Edge, and a print runs for hours: what's left, what's printing, which spool is feeding and how the first layer looks are things worth a glance. Every Bambu printer runs an MQTT broker on port 8883 for its slicer and publishes its status there about once a second. The widget connects with the user "bblp" and the printer's LAN access code, subscribes to its report topic and asks once for the full status; P1 and A1 printers then send only what changed, which BambuJSON merges in, so the picture stays whole. The serial number the topics are named after comes from the printer's TLS certificate, so the address and access code from the printer's network screen are all anyone types in. The code goes to the Keychain, not the layout file. The widget only reads. Nothing is sent that would move or heat the printer, so it works with Bambu's standard LAN access and needs neither Developer Mode nor a Bambu account. MQTT.swift is just enough of MQTT 3.1.1 for this: CONNECT, SUBSCRIBE, one PUBLISH, keep-alive pings. EdgeControl takes no third-party dependencies, and the protocol is small. P1 and A1 cameras stream JPEGs over TLS on port 6000, about one a second; the widget shows them beside the print once it is five columns wide, only while it is on screen and the displays are awake. X1 and H2 cameras stream RTSP, which AVFoundation can't play, so they show no camera. The tile shows the job, progress, time left and the clock time it will finish, layers, nozzle and bed temperatures, each AMS spool in its color with a ring on the one printing, and any HMS alert in the code the printer's own screen uses. A printer that drops off keeps its last status, marked offline, and is tried again with backoff; a wrong access code waits for a new one. The tests read a recorded P1S report, with identifiers replaced. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The camera shows what's on the bed; the slicer's drawing of the plate shows what it will be. A Picture setting picks one: Camera, Model or None. Bambu printers serve their files over FTPS on port 990 with the same user and access code as MQTT, and the job's .3mf carries the slicer's picture of each plate. The printers don't support starting a download partway, but Bambu Studio and OrcaSlicer write the pictures first and the G-code last, so ThreeMFPreviewReader reads the ZIP's entries as they arrive and hangs up as soon as it has the picture of the plate being printed, named by the plate's own JSON or G-code entry. That is about 100 KB, a couple of seconds, for a project of any size, once per job. The model is drawn faint where it hasn't printed and solid up to the current layer. Dark filament is lifted to grey on a faint plate, or a black print would disappear into a dark dashboard. A tile at least 0.7 times as tall as it is wide stacks: the job across the top, the picture filling the middle, progress, temperatures and spools across the bottom. Wider tiles keep the picture beside the details. The widget's padding is a little larger than usual, since its text runs the width and height of the tile; with a widget gap of 0 that padding is all that keeps it off the tile's edge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bambu printers don't use Bonjour, and their own announcements go to a UDP port Bambu Studio keeps for itself; taking it would break Bambu Studio's discovery. But every Bambu printer answers TLS on its MQTT port with a certificate from Bambu's authority whose common name is its serial number, and the serial names the model. BambuDiscovery tries the port on every address of this Mac's networks, narrowed to 256 addresses each, then finishes the handshake only on the few that answered, since a P1 busy printing can take a couple of seconds over it. No access code is sent and nothing is asked of the printer. A home network takes two to four seconds. Find Printers in the widget's settings lists what it finds, and choosing one fills in the address, leaving only the access code to type. The search runs only when asked, with one exception: the widget now keeps the printer's serial number, and a printer that stops answering at its address is looked for once, at most every five minutes, in case the router gave it a new one. Found elsewhere, its access code moves with it and the widget saves the new address. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On a monitor shelf at 63%, layer 14 of 122, the model looked barely begun: a wide base takes most of a print's time in its first layers, and the picture is drawn at an angle, so a flat part fills most of its height anyway. The fill now follows the same percentage as the progress bar under it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The widget decided it was off screen by comparing its frame in the dashboard's coordinates with the dashboard's bounds from GeometryProxy.bounds(of:), which are in the widget's own coordinates. A widget whose left edge was right of about the middle counted as off screen, and its camera stopped three seconds after it appeared. Both rectangles are now in the widget's coordinates, as in the Cameras widget's fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Another native widget, built with Claude like the Cameras one (#22): a Bambu Lab Printer widget (Network) for keeping an eye on a print from the dashboard. It talks to the printer directly on the local network. There's no Home Assistant, no Bambu account and no cloud.
What it does
The print: the job, a progress bar, the time left and the clock time it will finish, and the layer count.
Spools: each AMS slot and the external spool in its filament's colour, with a ring on the one printing.
Alerts: HMS alerts show in the same code the printer's own screen uses.
Picture, once the widget is five columns wide:
Tall tiles stack: the job on top, the picture filling the middle, the numbers below. Wide tiles put the picture beside the details.
Setup: Find Printers in the widget's settings lists the Bambu printers on the network. Pick one, then type the access code from the printer's network settings screen. A line under the fields says "Connected to P1S" or what went wrong, such as "Wrong access code".
Follows the printer: the widget keeps the printer's serial number. If the router gives the printer a new address, the widget finds it again and saves the new address.
Dropping off the network: a printer that stops answering keeps its last status, marked OFFLINE, and is tried again with backoff. A wrong access code waits for a new one instead of retrying.
Camera only while visible: the camera streams only while the widget is on screen and the displays are awake.
How
BambuMQTTSessionconnects over TLS (Network.framework) asbblpwith the printer's LAN access code, and subscribes todevice/{serial}/report.BambuJSON.merginglays each report over the last: objects merge key by key, and lists of objects with anid(AMS units, trays) merge entry by entry.MQTT.swiftis just enough MQTT 3.1.1 for this: CONNECT, SUBSCRIBE, PUBLISH, PINGREQ and DISCONNECT, all at QoS 0. CONTRIBUTING rules out third-party code, and this much of the protocol is small..3mfcarries the slicer's PNG of each plate.REST(502), so a file can't be read from the middle. Bambu Studio and OrcaSlicer put the pictures first and the G-code last, though.ThreeMFPreviewReaderreads the ZIP entries as they stream in. It hangs up once it has the picture of the plate being printed, which is named by that plate's ownplate_N.jsonorplate_N.gcodeentry. That's about 100 KB, two seconds, for a project of any size, once per job.BambuPreviewSessionis the FTP client: USER, PASS, PBSZ, PROT P, TYPE I, PASV and RETR.BambuDiscoveryinstead tries port 8883 on every address of the Mac's IPv4 networks (each narrowed to 256 addresses). It then finishes a TLS handshake only on the few that answered, and keeps those whose certificate comes from Bambu's "BBL CA" with a serial-shaped name. Nothing is sent to the printer, and a home network takes two to four seconds.KeychainSecretStore(serviceai.pakslab.edgecontrol.bambu), keyed by address. It stays out oflayout.json.ServiceKey.bambuandBambuService;ConfigFieldType.bambuPrinter, rendered byBambuPrinterEditor;NSLocalNetworkUsageDescriptionin Info.plist.Choices worth a look
Theme.widgetPadding, because its text runs the width and height of the tile. With a widget gap of 0, that padding is all that keeps it off the edge.Testing
xcodebuild testpasses in full: 442 Swift Testing tests in 47 suites, plus the XCTest suite. 55 of the tests are new, in ten suites:.3mfpicture reader, against synthetic ZIPs laid out like Bambu Studio's;Overlaps with #22
#22 (Cameras) and the Printers PR touch the same places this one does:
ConfigFieldType,ServiceKey,AppModelandWidgetRegistry;NSLocalNetworkUsageDescription;Whichever lands later, I'll rebase. The conflicts are a line or two each.
Not in this PR
🤖 Generated with Claude Code