Commit Graph
849 Commits
Author SHA1 Message Date
maziggy f3b2a24fa0 Fix external folder scan 500 on 3MF files (#846)
scan_external_folder stored raw 3MF metadata containing _thumbnail_data
  bytes directly in the JSON column, causing a serialization error. Applied
  the same clean_metadata() pattern used by upload/zip extraction and
  removed the call to the non-existent parser.extract_thumbnail().
2026-03-30 08:36:39 +02:00
maziggy 86693b4f75 Fix archives capped at 50 items, add pagination (#843)
The archives page only fetched the 50 most recent prints due to a
  hardcoded API limit default. Added client-side pagination with
  configurable page sizes (25/50/100/200/All) and bumped the fetch
  limit to return all archives. Page size is persisted to localStorage.
2026-03-30 08:27:34 +02:00
maziggy 24a5217d46 Fix filament usage not recorded when auto-archive is disabled
on_print_complete returned early when no archive_id was found (auto-
  archive off), skipping both internal inventory tracking (AMS remain%
  deltas) and Spoolman usage reporting. Moved the filament usage tracking
  block to run before the archive_id early-return so consumption is
  always recorded regardless of the auto-archive setting.
2026-03-28 12:30:45 +01:00
maziggy 68dce24cc9 Add staggered batch start for multi-printer queue jobs (#752)
When adding a print to the queue for multiple printers, users can now
  enable "Stagger printer starts" to avoid power spikes from simultaneous
  bed heating. Configurable group size and interval — first group starts
  immediately (ASAP) or at scheduled time, subsequent groups get offset
  scheduled_time values. No backend queue/scheduler changes — leverages
  existing scheduled_time field.

  Also adds a dedicated Queue tab in Settings (stagger defaults + auto-
  drying moved from Filament tab), i18n keys for all 7 locales, frontend
  and backend tests.
2026-03-28 12:11:22 +01:00
maziggy 208793c934 Fix swapped nozzle comment and update changelog for 0.2.2.2 release (#836)
Corrected left/right nozzle labels in ams_mapping2 comment
  (255=main/right, 254=deputy/left). Added [0.2.2.2] release header
  and #836 changelog entry noting the nozzle routing fix was already
  included via the #797 ams_mapping2 format change.
2026-03-28 09:25:34 +01:00
maziggy a077fd138d Fix native install misdetected as Docker in LXC containers
The _is_docker_environment() fallback assumed Docker when .git/ was
  absent, which is also true for native installs in Proxmox LXC
  containers. Replace the .git/ fallback with a check of
  /run/systemd/container (only matches docker/podman/oci, not lxc).
2026-03-27 14:35:08 +01:00
maziggy 3887938e8f Security: add token-based auth for all media endpoints
Camera streams, snapshots, thumbnails, timelapse videos, photos, QR
  codes, and cover images served via <img>/<video> tags were previously
  unauthenticated because browser media elements cannot send Authorization
  headers. When auth is enabled, these endpoints are now protected by a
  reusable stream token (?token=xxx) obtained from POST
  /printers/camera/stream-token (requires CAMERA_VIEW permission).
2026-03-27 12:58:08 +01:00
maziggy 7a0ea8faed Revert " Optimize SpoolBuddy kiosk performance on Raspberry Pi"
This reverts commit 24cda842af.
2026-03-27 12:00:14 +01:00
maziggy 24cda842af Optimize SpoolBuddy kiosk performance on Raspberry Pi
Replace Chromium with cog (WPE WebKit) for the kiosk browser. Cog is
  purpose-built for embedded kiosk displays with a fraction of Chromium's
  CPU and memory footprint on Pi hardware.

  Add React Query `select` to SpoolBuddyLayout and SpoolBuddyDashboard
  printer status queries so only `connected` is extracted. Temperature,
  fan, and progress changes no longer trigger re-renders on every MQTT
  tick.

  Expand service/package stripping to disable pipewire audio stack, CUPS
  printing, rpcbind, upower, polkit, accounts-daemon, xdg-desktop-portal,
  and mpris-proxy. Add user-level service masking for pipewire/portals.

  Update SSH update cache clearing to handle both WPE WebKit and legacy
  Chromium cache paths.
2026-03-27 11:43:55 +01:00
maziggy 866103bb96 Fix ruff format check for spool_assignment_notifications.py 2026-03-27 09:33:28 +01:00
maziggy 886fb90339 Fix print failing on files with spaces in filename (#824)
Filenames with spaces (e.g. "Junktion Box PRO 90.3mf") broke the MQTT
  print command because the url field (ftp://file name.3mf) contained
  unencoded spaces the firmware can't parse. FTP upload succeeded but the
  printer silently ignored the command and stayed IDLE. Replace spaces
  with underscores in the remote filename before upload and print command.
2026-03-27 08:38:08 +01:00
maziggy c6f62f9cd9 Add persistent auto-off option for smart plugs (#826)
Auto-off now has a "Keep Enabled" toggle that keeps it active between
  prints instead of disabling after each use (one-shot). Useful for HA
  accessories like BentoBox filters that should always power off after
  prints. Default behavior (one-shot) is unchanged.
2026-03-27 07:50:47 +01:00
maziggy a05b880a0b Fixed backend/tests/unit/test_spoolbuddy_system_stats.py 2026-03-26 16:35:29 +01:00
maziggy 161015a577 Fix rapid MQTT disconnect/reconnect bouncing (#813)
The stale connection fix force-closed the socket on every frontend
  status poll, causing a tight close→reconnect→stale→close loop. Added
  a 30-second cooldown between stale reconnect attempts so paho has time
  to re-establish the connection. Also added reconnect backoff (1-30s)
  and unique-per-process MQTT client IDs to prevent broker session
  takeovers.
2026-03-26 14:33:23 +01:00
maziggy 6c2df27860 Fix MQTT connected/disconnected UI bouncing caused by stale reconnect
The stale connection fix (6ac375a) force-closed the socket to trigger
  paho reconnect, but paho's disconnect callback redundantly broadcast
  state changes, causing rapid connected/disconnected cycling in the UI.
  Now sets a flag before the force-close so _on_disconnect skips the
  redundant broadcast. Also relaxed keepalive from 15s to 30s — the
  aggressive interval caused spurious disconnects on transient hiccups.

  Moved _disconnection_event.set() to the top of _on_disconnect so no
  early-return filter can prevent it from unblocking disconnect() callers.

  Removed leftover debug payload dump.
2026-03-26 13:32:38 +01:00
maziggy 77cb7158d2 Add SpoolBuddy System tab with live OS stats from Raspberry Pi
The daemon now collects CPU temp, core count, load average, memory/disk
  usage, OS info, and system uptime every heartbeat using stdlib-only reads
  from /proc and /sys. Stats are sent as a JSON blob in the heartbeat
  payload, stored in a new system_stats TEXT column, and displayed in a
  new "System" tab in SpoolBuddy Settings with color-coded usage bars.
2026-03-26 09:57:09 +01:00
maziggy 1df5130df2 Broadcast spool assignment changes via WebSocket for cross-tab updates
Assigning or unassigning a spool now broadcasts a spool_assignment_changed
  event to all connected WebSocket clients. The frontend handles this event
  by invalidating the spool-assignments and slotPresets caches, so other
  open tabs update automatically without a page reload.
2026-03-26 09:34:46 +01:00
maziggy 7d94bf7896 Fix P1S/P1P printer card showing "Printing" when idle (#813)
Some P1S/P1P firmware reports stg_cur=0 when idle, which maps to
  the "Printing" stage name and overrides the correct IDLE gcode_state
  on the printer card. Extend the existing A1/A1 Mini stg_cur idle bug
  workaround to also cover P1S and P1P models.
2026-03-25 17:55:36 +01:00
maziggy 6ac375a700 Fix stale MQTT connection not triggering reconnect (#813)
Two issues prevented recovery from stale printer MQTT connections:

  1. The spurious-disconnect filter (30s window) could suppress real
     keepalive-timeout disconnects (which fire at ~22.5s with keepalive=15s).
     Now checks rc.is_failure so error disconnects are never suppressed,
     and tightens the window from 30s to 10s.

  2. Stale detection (60s no messages) set state.connected=False but left
     the TCP socket open, so paho kept publishing into the void. Now
     force-closes the socket so paho's loop thread detects the break and
     auto-reconnects.
2026-03-25 16:16:50 +01:00
maziggy 7c20efb7c3 Set _completion_triggered on unseen-RUNNING terminal states (#790)
When a printer enters FINISH/FAILED without Bambuddy ever seeing
  RUNNING (e.g. after a restart), mark _completion_triggered = True
  so the flag is clean for the next print cycle.
2026-03-25 14:34:53 +01:00
maziggy 5926e722f8 Fix H2D external spool print failing with 0700_8012 (#797)
BambuStudio converts virtual tray IDs (254/255) to -1 in the flat
  ams_mapping and relies on ams_mapping2 for external spool routing.
  Bambuddy was passing raw 254/255 in the flat array, which H2D firmware
  rejects with "Failed to get AMS mapping table".

  - Convert external tray IDs to -1 in flat ams_mapping (match BambuStudio)
  - Fix ams_mapping2 for external trays: each virtual tray is its own AMS
    unit with slot_id 0, not a shared unit differentiated by slot
  - Fix main/deputy nozzle ID comment (255=main, 254=deputy per BambuStudio)
  - Add 8 unit tests for start_print() mapping construction
2026-03-25 11:38:27 +01:00
maziggy b8fa2df36d Increase database connection pool limits for large printer farms
QueuePool exhaustion at 100+ printers. Bumped pool_size 10→20,
  max_overflow 20→200, and SQLite busy_timeout 5s→15s.
2026-03-25 08:20:22 +01:00
maziggy 95c703282d Fix missing image thumbnails in external folder scan (#124)
External folder scan generated thumbnails for 3mf/stl/gcode files but
  skipped image files. Added IMAGE_EXTENSIONS check with
  create_image_thumbnail() to the scan loop.
2026-03-24 16:32:45 +01:00
maziggy c9efa4b8bb Fix stale AMS slot data and empty slot button visibility (#784)
Some printers (e.g. H2D) only send {id, state} in incremental MQTT
  tray updates — no tray_type, tray_color, or other fields. When
  filament is unloaded (state changes from 11 to 10), the old tray
  data persisted indefinitely because the merge logic only updates
  fields present in the incoming message.

  Backend:
  - Detect tray state != 11 without tray_type in incremental updates
    and clear stale tray data (bambu_mqtt.py)
  - Expose tray `state` field via REST API and WebSocket broadcasts
    (printer.py schema, printers.py route, printer_manager.py)
  - Include AMS tray content in WebSocket dedup key so load/unload
    transitions trigger broadcasts (main.py)

  Frontend:
  - Add `state` to AMSTray interface (client.ts)
  - Show configure/assign buttons for state=10 (spool present, not
    loaded) but hide for state=9 (truly empty) on AMS/HT slots
  - Hide fill level bar on empty slots

  Tests:
  - 5 new tests covering state-based clearing, preservation, reload,
    and idempotency
2026-03-24 16:03:34 +01:00
Keybored 6e648804fc [Feature] Spoolbuddy Fixes and Improvements (#787)
[Feature] Spoolbuddy Fixes and Improvements (#787)
2026-03-24 11:56:33 +01:00
Keybored 3f7d0e2d55 Add notification for no spool assigned for active trays, improve usage tracker logic in edge cases (#789)
Add notification for no spool assigned for active trays, improve usage tracker logic in edge cases (#789)
2026-03-24 11:31:32 +01:00
maziggy dd75c8f0c9 feat: auto-link untagged inventory spools on AMS insert (#538)
When a Bambu Lab spool is detected in the AMS but no tag match exists,
  check for an untagged inventory spool with matching material/subtype/color
  before creating a new entry. Links the RFID tag to the existing spool
  (data_origin="rfid_linked") to prevent duplicate inventory entries.
2026-03-24 09:23:25 +01:00
maziggy 82278e8d93 Add external folder mounting for File Manager (#124)
Host directories (NAS, USB, network shares) can now be mounted
  into the File Manager without copying files. Files are indexed
  into the database on scan but read directly from their original
  location. Supports read-only mode, hidden file filtering, and
  automatic thumbnail extraction for 3MF/STL/gcode.

  - POST /library/folders/external — create with path validation
  - POST /library/folders/{id}/scan — discover/sync files
  - Block uploads, moves, and deletes for read-only external folders
  - Never delete actual files from external paths (DB-only removal)
  - Purple folder icon + info bar with rescan button in UI
  - i18n for all 7 languages
  - 19 backend + 11 frontend tests
2026-03-24 08:43:23 +01:00
maziggy 293ebd9b3f Fix ffmpeg process leak causing multi-GB memory growth (#776)
When a user closed the camera viewer, the stop endpoint killed the
  ffmpeg process but never signaled the stream generator's disconnect
  event. The generator saw "process died" as a dropped RTSP session
  and respawned ffmpeg — up to 30 times per stream. The orphan cleanup
  couldn't catch these because they were still tracked as active.

  - Add per-stream disconnect events dict so stop endpoint can signal
    generators to stop reconnecting before killing the process
  - Check if stream_id was removed from _active_streams before
    reconnecting (belt-and-suspenders with the event)
  - Track frame timestamps per stream_id instead of per printer_id
    so stale detection isn't fooled by newer streams for the same
    printer
  - Reduce stale thresholds from 120s+60s to 60s+30s
  - Signal disconnect events from cleanup when killing stale streams
2026-03-24 07:49:54 +01:00
maziggy 7b91cde6db Fixed typo in version 2026-03-23 16:14:44 +01:00
maziggy 745ff232eb Fix log flood: "State is FINISH but completion NOT triggered" (#790)
Diagnostic log added in 0.2.2.1 fired on every MQTT update while a
  printer was in FINISH/FAILED state, not just on the state transition.
  For farms with multiple idle printers, this produced thousands of log
  lines per minute. Guard the log to only fire once when the state first
  changes to FINISH/FAILED.
2026-03-23 16:07:44 +01:00
maziggy b8a3aa842b Add tests for SpoolBuddy SSH update service and settings UI
15 backend unit tests covering keypair management, branch detection,
  SSH command execution (success/failure/timeout), and full update flow
  with error handling. 4 new frontend tests for the Updates tab (version
  display, buttons, SSH setup, update available state).
2026-03-23 15:55:44 +01:00
maziggy c42d834219 Revert "version test"
This reverts commit cf8f43169b.
2026-03-23 15:46:10 +01:00
maziggy cf8f43169b version test 2026-03-23 15:45:08 +01:00
maziggy 364b02b8ac Housekeeping 2026-03-23 15:44:49 +01:00
maziggy 382daef6e2 Revert "version test"
This reverts commit 36494a6f6b.
2026-03-23 15:34:15 +01:00
maziggy 36494a6f6b version test 2026-03-23 15:33:10 +01:00
maziggy bc37c12f90 Disable service worker on SpoolBuddy kiosk to prevent stale frontend
The kiosk touchscreen has no way to hard-refresh, and the service worker
  served stale cached JS after updates. SpoolBuddy pages now unregister
  any existing SW and skip registration entirely. Regular desktop/mobile
  users still get the SW. Restored kiosk restart in SSH update flow since
  SW is no longer an obstacle.
2026-03-23 15:28:24 +01:00
maziggy c63c4fc39b version test 2026-03-23 15:21:39 +01:00
maziggy 7f1ced60fd Fix stale frontend after deploy due to service worker caching
The SW used stale-while-revalidate for JS/CSS, serving old cached
  bundles even after a new build. Changed to network-first (Vite already
  content-hashes filenames), bumped cache version v24→v25, and added
  Cache-Control: no-cache to the sw.js endpoint so browsers always fetch
  the latest service worker.
2026-03-23 15:12:18 +01:00
maziggy 559d41cc5e Fix SpoolBuddy update UI: loading states, page reload, stale data
Check button had no visual feedback because isFetching doesn't trigger
  reliably with cached data — replaced with manual loading state. Removed
  kiosk restart via getty; the frontend now detects daemon re-registration
  via WebSocket and calls window.location.reload(), keeping the user on
  the same page and fetching all fresh data.
2026-03-23 14:59:12 +01:00
maziggy 0e44e149bd ● Compact SpoolBuddy updates tab layout to fit without scrolling
Merged version, status, and update check into a single card. Buttons
  are side by side when up to date. Reduced padding and font sizes.
  Removed separate "complete" banner since status is now cleared on
  re-registration. SSH Setup section is smaller and more compact.
2026-03-23 14:36:58 +01:00
maziggy b83a99ebab ● Fix SpoolBuddy update status stuck after restart
The SSH update set status to "complete" after the daemon had already
  restarted and re-registered, overwriting the cleared state so it stuck
  forever. Removed the post-restart "complete" write — daemon
  re-registration is now the completion signal, clearing any update status.
2026-03-23 14:26:50 +01:00
maziggy 811813165b Fix stale SpoolBuddy update status after daemon restart
After an SSH update completed, the UI kept showing "Update complete,
  daemon restarting..." and the old "update available" banner because
  nothing cleared the stale state. Registration now resets update_status
  when the daemon comes back, and WebSocket handlers for spoolbuddy_update
  and spoolbuddy_online invalidate the frontend queries immediately.
2026-03-23 13:55:12 +01:00
maziggy 136ecb7c92 Replace SpoolBuddy self-update with SSH-based updates from Bambuddy
The daemon's self-update mechanism (git fetch/reset on its own code) was
  fragile: .git permission errors, self-modifying code mid-run, hardcoded
  main branch. Bambuddy now SSHes into the SpoolBuddy Pi and drives the
  update remotely — matching its own branch, with step-by-step progress
  via WebSocket. After updating the daemon, the kiosk browser is also
  restarted so it loads the updated frontend.

  SSH key pairing is automatic: Bambuddy generates an ED25519 keypair and
  returns the public key in the registration response. The daemon deploys
  it to authorized_keys on first connect — no manual setup needed.

  Changes:
  - New: backend/app/services/spoolbuddy_ssh.py
  - Rewritten: trigger_daemon_update endpoint (SSH instead of pending_command)
  - New: GET /spoolbuddy/ssh/public-key endpoint
  - Auto SSH key deployment via registration response + daemon
  - Removed: daemon _perform_update() and cmd=="update" handler
  - Install script: bash shell, sudoers for daemon + kiosk restart, .ssh/ setup
  - Dockerfile: added openssh-client
  - Frontend: SSH key display, force update button
  - Fixed: update check compares APP_VERSION, not GitHub releases
  - Fixed: kiosk browser restart after update
2026-03-23 13:46:45 +01:00
maziggy 5e9481859b Replace SpoolBuddy self-update with SSH-based updates from Bambuddy
The daemon's self-update mechanism (git fetch/reset on its own code) was
  fragile: .git permission errors, self-modifying code mid-run, hardcoded
  main branch. Bambuddy now SSHes into the SpoolBuddy Pi and drives the
  update remotely — matching its own branch, with step-by-step progress
  via WebSocket.

  SSH key pairing is automatic: Bambuddy generates an ED25519 keypair and
  returns the public key in the registration response. The daemon deploys
  it to authorized_keys on first connect — no manual setup needed.

  - New: backend/app/services/spoolbuddy_ssh.py (keypair, SSH commands, update orchestration)
  - Rewritten: trigger_daemon_update endpoint uses SSH instead of pending_command
  - New: GET /spoolbuddy/ssh/public-key endpoint for manual pairing
  - Removed: daemon _perform_update() and cmd=="update" heartbeat handler
  - Updated: install.sh — bash shell, sudoers for systemctl restart, .ssh/ setup
  - Updated: Dockerfile — added openssh-client
  - Updated: frontend — SSH key display, force update button
  - Fixed: update check now compares against APP_VERSION, not GitHub releases
2026-03-23 13:32:42 +01:00
maziggy bc1bba078b Replace SpoolBuddy self-update with SSH-based updates from Bambuddy
The daemon's self-update mechanism (git fetch/reset on its own code) was
  fragile: .git permission errors, self-modifying code mid-run, hardcoded
  main branch. Bambuddy now SSHes into the SpoolBuddy Pi and drives the
  update remotely — matching its own branch, with step-by-step progress
  via WebSocket. Install script updated with SSH access, sudoers entry,
  and --ssh-pubkey flag for pairing.
2026-03-23 12:51:21 +01:00
maziggy 511ece791a Fix SpoolBuddy update check comparing against GitHub releases instead of backend version
The SpoolBuddy daemon update endpoint fetched GitHub releases and compared
  them against device.firmware_version, which always showed "up to date"
  because the comparison source was wrong. Now compares directly against
  APP_VERSION from the running backend, so a daemon at 0.2.3b1 correctly
  sees 0.2.3 as an available update.
2026-03-23 12:05:20 +01:00
maziggy 8e5625d1d9 Fix A1 virtual printer proxy by adding ports 2024-2026 (#757)
BambuStudio connects to undocumented proprietary ports 2024-2026
  on A1/P1S models during the print flow. The proxy wasn't forwarding
  these ports, causing connection refused (RST) and triggering the
  access code dialog instead of printing. MQTT and FTP worked fine —
  port 2024 was the sole blocker.

  Added transparent TCP pass-through proxies for ports 2024-2026,
  following the same pattern as the existing FileTransfer (6000) and
  RTSP (322) proxies. Silently ignored on models that don't use them.
2026-03-23 10:47:41 +01:00
maziggy 40f0405ea0 Revert "Feature/multiple switches per prtinter (#786)"
This reverts commit 9e81f246d8.
2026-03-23 10:11:56 +01:00