octoturge 6ce60542c6 Add pushall + print_status cache; fix envelope, race, and matching bugs
PrintReport now flattens CommandEnvelope (sequence_id/command) -
push_status.schema.json composes the shared envelope like every other
Bambu message; the struct's old doc comment concluded otherwise from a
capture that turned out to be an incomplete example (also missing dozens
of other real fields), not proof the message lacks them.

Added BambuMqttSession's PrintStatusCache: the in-memory
print.push_status object, replaced wholesale on v2 (always full) or on a
v1 message with msg != 1 (forced/full), merged field-by-field otherwise
(v1's organic partial updates) via PrintReport::merge_from. Tracks
last_sequence_id to warn on a gap in the organic stream. BambuPrinter
gets pushall() (v1-only; pushing.pushall doesn't exist in v2's schema at
all) and print_status().

Three real bugs found and fixed via live testing against an actual P1P,
none of them guessable from the schema alone:
- pushall's reply doesn't echo the sequence_id we send - the printer
  stamps its own free-running counter regardless of what triggered it.
  request()'s ID correlation silently can't work here; first fix attempt
  added request_next_of_category (wait for the next message under a
  category, no ID needed).
- That undershot too: matching by category alone let an unrelated
  "print" message (that category carries many commands - gcode_line,
  pause, push_status, ...) satisfy the wait before the real push_status
  reply arrived, so pushall() returned Ok having consumed the wrong
  message - now keyed by (category, command).
- A real ordering race: handle_incoming_report woke a waiting oneshot
  before updating the print_status cache, so a caller could resume and
  check print_status() before the write landed - pushall() returned Ok
  immediately followed by print_status() still showing None. Fixed by
  applying the cache update before sending on any matched oneshot.

Superseded by real protocol knowledge before any of the above needed to
ship, though: push_status carries its own msg field (1 = automatic/
partial, 0 = forced/full) - the actual, reliable, self-describing signal
for which kind a message is, regardless of timing or which client (if
any) triggered it. PrintStatusCache now reads that directly instead of
inferring it from request correlation, and pushall() is plain fire-and-
forget (publish, no wait) since there's nothing left to correlate for -
confirmed live: msg reads correctly off a real P1P, and the cache
populates/updates correctly with no gap warnings across several organic
pushes. request_next_of_category is kept (a future case may still need
"no correlation ID at all" for real), just no longer used here.

Also: the poll loop now logs when it exits instead of returning silently
- that silence is exactly what made a real dropped MQTT connection to a
live H2C indistinguishable from "nothing happening" during testing.
2026-09-07 14:39:55 +00:00

continuum-proxy

Edge gateway daemon for the Continuum print farm platform. Runs on a Linux SBC on-site, talks to printers over the LAN, and keeps a connection to the cloud control plane (continuum-backend).

This is a learning-stage boilerplate

This repo is deliberately minimal right now - real printer protocol clients (Bambu MQTT+FTPS, PrusaLink REST, Klipper/Moonraker WebSocket) are not implemented yet. Each vendor is a stub that just prints what it would do (src/printer/bambu.rs, prusa.rs, klipper.rs). The idea is to learn Rust's polymorphism pattern (trait + enum, since Rust has no class inheritance) on something simple before adding real networking on top.

Getting started

cp .env.example .env
cargo run                                  # the daemon: cloud uplink + go2rtc watchdog
cargo run --example printer_polymorphism   # standalone demo, no network/env needed

cp printers.example.toml printers.toml     # fill in your real printers (gitignored)
cargo run --example test_bambu_certs       # real TLS handshake test against each Bambu printer

Structure

src/
  main.rs      Runs the uplink and the go2rtc watchdog side by side
  config.rs    Loads settings from environment variables
  fleet.rs     Loads printers.toml into ready-to-use PrinterHandles
  uplink/      WebSocket client to continuum-backend: connect, heartbeat, reconnect on drop
  printer/     GenericPrinter trait + PrinterBase + PrinterHandle enum + one stub per vendor
  go2rtc.rs    Restarts the go2rtc camera-restreaming process if it dies
examples/
  printer_polymorphism.rs   Runs all five printer stubs through one `connect()` call site
  test_bambu_certs.rs       Loads printers.toml, does a real TLS handshake to each Bambu printer

src/printer/ is where the "inheritance" question lives - see that module's doc comment for the trait+enum pattern this project uses instead of class inheritance, and run printer_polymorphism to see it work.

printers.toml (gitignored - copy from printers.example.toml) holds real per-printer connection details: host, access code, and - since not every Bambu printer trusts the same certificate (see certs/README.md) - an optional per-printer CA override. src/fleet.rs loads it; nothing in main.rs uses it yet, but test_bambu_certs does, as a real (if narrow - just the TLS handshake, no MQTT) way to check a printer's certificate without needing the full MQTT client built yet.

What's not here yet (on purpose)

  • Real MQTT/FTPS/HTTP/WebSocket printer clients - src/printer/*.rs has a println! where each of these will go.
  • Local SQLite buffering for telemetry across connectivity gaps.
  • LAN printer discovery (SSDP/mDNS).
  • The mechanical plate-changer interface (serial/GPIO).

Add these back in one at a time as you get comfortable with the Rust underneath them - each is its own small lesson (async I/O, a new crate's API, error handling for a real protocol) rather than something to absorb all at once.

S
Description
Continuum platform: continuum-proxy
Readme
914 KiB
Languages
Rust 100%