_get_mac_id() used Path.iterdir() to find a network interface for the
device ID, but iteration order is non-deterministic. On different boots
it could pick eth0 (MAC …3100) or wlan0 (MAC …3102), producing a
different device_id each time. Since calibration is stored per device ID
in the backend DB, a new ID meant registering as an uncalibrated device.
Sort interfaces alphabetically so the same one is always selected.
The tare and calibrate buttons on the Settings page queued commands
but never executed them due to three broken links:
1. Daemon received tare command via heartbeat but never called
scale.tare() — the ScaleReader was available in shared dict
but unused
2. No API endpoint for the daemon to report the new tare offset
back to the backend DB, so tare results were lost
3. Heartbeat updated config but never called
scale.update_calibration(), so ScaleReader kept initial values
Added set-tare endpoint + API client method, and fixed heartbeat
loop to execute tare, persist the result, and propagate calibration
changes to the ScaleReader instance. Skip calibration sync on the
heartbeat cycle that delivers a tare command, since the response
predates the tare and would overwrite it with stale values.
The tare and calibrate buttons on the Settings page queued commands
but never executed them due to three broken links:
1. Daemon received tare command via heartbeat but never called
scale.tare() — the ScaleReader was available in shared dict
but unused
2. No API endpoint for the daemon to report the new tare offset
back to the backend DB, so tare results were lost
3. Heartbeat updated config but never called
scale.update_calibration(), so ScaleReader kept initial values
Added set-tare endpoint + API client method, and fixed heartbeat
loop to execute tare, persist the result, and propagate calibration
changes to the ScaleReader instance.
Frontend: Replace inline SpoolInfoCard/UnknownTagCard with full-screen
TagDetectedModal that auto-opens on NFC tag detection. Known spools show
remaining weight, fill bar, and offer "Assign to AMS" (new sub-modal with
printer selector + AMS slot grid) and "Sync Weight". Unknown tags offer
"Add to Inventory" and "Link to Spool". Modal stays open on tag removal,
won't re-open for dismissed tags, reopens on re-place after removal.
Daemon: Fix PN5180 NFC reader failing to detect tags. Each
activate_type_a() call returning None corrupts the PN5180 transceive
state, silently preventing all subsequent tag detection. Fixed by
performing a full hardware reset (RST pin toggle + RF re-init) before
every idle poll (~240ms, ~1.8 Hz rate). When a tag is present, a light
RF off/on cycle (13ms) resets the card from ACTIVE to IDLE state for
continuous re-selection. Also added error-based recovery, periodic
status logging, and accurate heartbeat NFC/scale health reporting.
Frontend: Replace inline SpoolInfoCard/UnknownTagCard with full-screen
TagDetectedModal that auto-opens on NFC tag detection. Known spools show
remaining weight, fill bar, and offer "Assign to AMS" (new sub-modal with
printer selector + AMS slot grid) and "Sync Weight". Unknown tags offer
"Add to Inventory" and "Link to Spool". Modal stays open on tag removal,
won't re-open for dismissed tags, reopens on re-place after removal.
Daemon: Fix PN5180 NFC reader failing to maintain tag detection. After a
successful SELECT the card stays in ACTIVE state and ignores subsequent
WUPA/REQA. Added a conditional RF off/on cycle (13ms) before each poll,
but only when a tag is present — resets card from ACTIVE to IDLE for
re-selection. The cycle is skipped when idle to avoid degrading reader
state with continuous RF toggling, which prevented new tags from being
detected after removal. Also added a preventive full hardware reset every
60s when idle to recover from deeper stuck states, error-based recovery
after 10 consecutive exceptions, and accurate heartbeat reporting of
NFC/scale health.
Frontend: Replace inline SpoolInfoCard/UnknownTagCard with full-screen
TagDetectedModal that auto-opens on NFC tag detection. Known spools show
remaining weight, fill bar, and offer "Assign to AMS" (new sub-modal with
printer selector + AMS slot grid) and "Sync Weight". Unknown tags offer
"Add to Inventory" and "Link to Spool". Modal stays open on tag removal,
won't re-open for dismissed tags, reopens on re-place after removal.
Daemon: Fix PN5180 NFC reader failing to maintain tag detection. After a
successful SELECT the card stays in ACTIVE state and ignores subsequent
WUPA/REQA, causing immediate false "tag removed" events. Added a brief
RF off/on cycle (13ms) before each poll to force cards back to IDLE
state. Also added a preventive full hardware reset every 60s when idle
to recover from deeper stuck states where activate_type_a() silently
returns None without exceptions. Heartbeat now reports actual nfc_ok/
scale_ok instead of hardcoded True.
Frontend: Replace inline SpoolInfoCard/UnknownTagCard with full-screen
TagDetectedModal that auto-opens on NFC tag detection. Known spools show
remaining weight, fill bar, and offer "Assign to AMS" (new sub-modal with
printer selector + AMS slot grid) and "Sync Weight". Unknown tags offer
"Add to Inventory" and "Link to Spool". Modal stays open on tag removal,
won't re-open for dismissed tags, reopens on re-place after removal.
Daemon: Fix PN5180 NFC reader silently stopping tag detection. The reader
drifts into a stuck state where activate_type_a() returns None without
raising exceptions, making error-based recovery useless. Changed the
preventive idle maintenance from a lightweight RF off/on cycle to a full
hardware reset (RST pin toggle + RF re-init) every 60s — the same reset
that a service restart performs. Also added error-based auto-recovery
after 10 consecutive exceptions, promoted poll errors to WARNING, added
periodic status logging, and fixed heartbeat to report actual nfc_ok/
scale_ok instead of hardcoded True.
Frontend: Replace inline SpoolInfoCard/UnknownTagCard with full-screen
TagDetectedModal that auto-opens on NFC tag detection. Known spools show
remaining weight, fill bar, and offer "Assign to AMS" (new sub-modal with
printer selector + AMS slot grid) and "Sync Weight". Unknown tags offer
"Add to Inventory" and "Link to Spool". Modal stays open on tag removal,
won't re-open for dismissed tags, reopens on re-place after removal.
Daemon: Fix PN5180 NFC reader silently stopping tag detection when the
reader drifts into a stuck state. Add auto-recovery (full hardware reset
after 10 consecutive errors), preventive RF cycling every 60s when idle,
and periodic status logging. Heartbeat now reports actual nfc_ok/scale_ok
from reader instances instead of hardcoded True.
When Bambuddy auth is enabled, the SpoolBuddy kiosk gets redirected to
the login page because ProtectedRoute requires a user from GET /auth/me,
which only handled JWT tokens. The kiosk daemon already has an API key
but couldn't use it to satisfy the frontend auth check.
- Backend: /auth/me now accepts API keys (Bearer bb_xxx or X-API-Key)
and returns a synthetic admin UserResponse with all permissions
- Frontend: AuthContext reads ?token= from URL on first load, stores in
localStorage, and strips from URL (prevents history/referrer leakage)
- Install script: kiosk URL now includes ?token=${API_KEY}
- Tests: 3 new integration tests (Bearer API key, X-API-Key header,
invalid key rejection)
When ADC noise kept the spread hovering around the 2g stability
threshold, the stable flag toggled every cycle, forcing a report with
a slightly different weight each time. Now only actual weight changes
of >=2g trigger reports. The stable flag is still included in each
report for consumers that need it.
5 samples at 100ms (500ms window) wasn't enough to smooth NAU7802 ADC
noise — the averaged value still varied by >2g between 1s report
intervals, and the stability state kept flipping, triggering a report
every cycle. Increased to 20 samples (2s window) so noise is smoothed
before reaching the reporting layer.
The daemon imports read_tag and scale_diag as bare modules, but they
live in spoolbuddy/scripts/ which isn't on sys.path when systemd runs
the daemon. Added scripts/ to sys.path at startup, resolved relative
to the module file. Also moved the read_tag import inside NFCReader's
try/except (was crashing the daemon instead of skipping gracefully)
and demoted hardware-not-available messages from ERROR to INFO.
NFCReader.__init__ imported read_tag and instantiated PN5180() outside
the try/except block, so a missing module crashed the entire daemon.
Moved the import inside the existing try/except so the daemon gracefully
skips NFC polling — matching the scale reader's existing behavior.
constructor before the try/except, so the FileNotFoundError was unhandled and crashed the entire daemon via asyncio.gather().
Now when the scale hardware isn't available (no /dev/i2c-0), it logs "Scale init failed" and sets self._ok = False, so scale_poll_loop will skip polling with "Scale not
available, skipping scale polling" — same graceful degradation the NFC reader already has.
SpoolBuddy turns a Raspberry Pi 4B with a PN5180 NFC reader and
NAU7802 scale into a filament management station that integrates
with Bambuddy via REST API and WebSocket.
Backend: SpoolBuddyDevice model, 10 REST endpoints (/spoolbuddy/*),
6 WebSocket broadcast types, background offline-detection watchdog.
RPi daemon: asyncio service with concurrent NFC polling (300ms,
MIFARE Classic + Bambu HKDF key derivation), scale reading (10 SPS,
5-sample moving average, stability detection), and 10s heartbeat
with exponential backoff reconnect.
Frontend: kiosk-optimized 1024x600 UI at /spoolbuddy with Dashboard
(live weight + NFC spool detection), AMS Overview, Inventory,
Printers, and Settings pages. useSpoolBuddyState reducer hook
driven by WebSocket CustomEvents.
i18n: all 6 locales (en, de, fr, it, ja, pt-BR).