OnurCem/platesentry
关于
🛡️ A night watch for your Bambu Lab printer: local AI that spots spaghetti, detached parts and nozzle blobs before they waste a spool. Free, private, no cloud.
人工智能与机器学习可以做什么
- Live camera view, print progress, reference preview and check history (with the model's reasons) in a local web UI that also works on a phone (screenshot)
- Flags loose strands on the plate: spaghetti, and the strands that air printing and knocked-off parts leave behind
- Notifications through macOS Notification Center and/or ntfy (free push to your phone)
- Works with the printer in normal cloud mode; Bambu Handy and Bambu Studio keep working
实测星标增长
- 24小时
- +1
- 7天
- 正在收集历史
- 15天
- 正在收集历史
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文PlateSentry
A night watch for your Bambu Lab printer. A local vision-language model watches the built-in camera and tells you when a print turns into spaghetti, comes loose or starts printing into thin air. It is free and private: nothing leaves your computer.

PlateSentry is an independent project. It is not affiliated with, endorsed by or supported by Bambu Lab. "Bambu Lab" is a trademark of its owner.
How it works
flowchart LR
A[Printer camera] --> D
B[Printer status<br/>MQTT] --> G{Printing and<br/>past first layers?}
G -->|yes| C[Crop to<br/>the plate]
C --> D[Local VLM<br/>via Ollama]
D -->|description +<br/>part? strands?| R[Rule:<br/>strands = failure]
R -->|ok / failure / uncertain| F[N failures<br/>in a row]
F --> N[Notification]
- Zero-shot vision-language model, run locally. No training data and no cloud API; any Ollama vision model can be used (default
gemma3:4b). - The model observes, the code decides. The model is asked only what is on the plate (a description, "is there a solid part?", "are there loose tangled strands?") as JSON at temperature 0. Loose strands make a frame a failure; no part seen makes it
uncertain. Whengemma3:4bhad to choose the verdict itself, it described the strands and still answeredok. - No job context in the prompt. The job's 3MF is pulled from the printer for the web UI, but its preview and the expected height are not shown to the model: a small model copies them into its answer ("the cube is clearly visible") instead of reading the frame.
- Cropped to the plate. Only the part of the frame where parts are printed is sent, so small parts and thin strands are not lost when the model shrinks the image. When a part is outside the manual crop (near the plate's edges, or parts far apart), an automatic crop follows the job's parts and the bed, from the 3MF and a calibrated camera model.
- Gated by the printer's state machine. No analysis during heating, leveling or the first layers.
- Temporal filtering. N failures in a row are needed before an alert, which trades a few minutes of delay for far fewer false alarms.
- Measurable. Frames can be recorded, labeled and replayed through several models to compare precision, recall and latency (evaluation).
The reasoning behind these choices, and what testing on a real printer changed, is in docs/DESIGN.md.
Results
PlateSentry is early work. It now catches loose strands in most failure frames, at the cost of a few false flags on a print with a rough, folded surface. All numbers come from one Bambu Lab P1S with white PLA (M1 Mac, 8 GB), gemma3:4b.
| What was measured | Data | Earlier detector (model decides, with 3MF context, whole frame) | Current detector (model observes, rule decides, cropped) |
|---|---|---|---|
| Detection of deliberate failures | 11 failure frames from 3 tests on a 20 mm cube: air printing, detachment, spaghetti | 0 of 11 flagged | 7 of 11 flagged (spaghetti 3/3, detachment 2/4, air printing 2/4); 1 alert, on the spaghetti test |
| False alarms on good frames | 127 frames of a 100 mm part + 17 frames of the cube tests before the failure | 1 of 127 (0.8%), no alerts | 5 of 144 (3.5%), all on the 100 mm part at layers 470–491, where the model read its folded surface as strands; no alert (never 3 in a row) |
| Latency | Same frames | 30 s per check (mean) | 15 s (mean), 17 s (p95) |
| One-class anomaly prototype (DINOv2-small embeddings, TRAINING.md) | The same 3 tests, 59 failure frames, leave-one-print-out | AUROC 0.97–1.00 when the bank has seen the same part, 0.18–0.71 with a different part; 39 ms per frame | |
Latency (gemma3:4b) |
Same 127 frames | 20 s per check without the 3MF reference, 30 s with it (mean) |
In short: the VLM now sees strands, but a single frame does not show a missing or moved part, and it cannot tell strands from a rough surface every time. The detachment and air-printing frames it catches are the ones with strands next to the part. The anomaly prototype separates failures well only after it has seen the part, and it does not detect a part that tipped over without leaving strands. Details: first results, failure tests, detachment without strands.
Features
- Live camera view, print progress, reference preview and check history (with the model's reasons) in a local web UI that also works on a phone (screenshot)
- Flags loose strands on the plate: spaghetti, and the strands that air printing and knocked-off parts leave behind
- Notifications through macOS Notification Center and/or ntfy (free push to your phone)
- Works with the printer in normal cloud mode; Bambu Handy and Bambu Studio keep working
- Talks to the printer directly over the local network: camera, MQTT and FTPS
Compatibility
| Printer | Camera | Status |
|---|---|---|
| P1S | JPEG stream, port 6000 | Tested |
| P1P, A1, A1 mini | JPEG stream, port 6000 | Should work, not tested yet |
| X1 series, H2 series, P2S | RTSPS, port 322 (needs ffmpeg and LAN Only Liveview on the printer) | Experimental, not tested yet |
Reports for untested models are very welcome. Please open an issue.
What works in each printer mode:
| Cloud mode (default, tested on a P1S) | LAN Only Mode + Developer Mode (not tested yet) | |
|---|---|---|
| Camera | Yes | Expected |
| Printer status (MQTT) | Yes | Expected |
| Reading the job's 3MF (FTPS) | Yes | Expected |
| Pausing the print | No: the printer rejects it (0x05024007) |
Expected (third-party control is what Developer Mode is for) |
| Bambu Handy remote access | Yes | No |
In cloud mode PlateSentry only notifies you; you pause from Bambu Handy or the printer's screen.
Requirements
- macOS or Linux (Windows should work too but is untested), with Python 3.11 or newer. The
python3that ships with macOS is 3.9; install a current one withbrew install pythonor from python.org - Ollama and a vision model. About 4 GB of free RAM is enough for
gemma3:4b - The computer must reach the printer on the local network
- For X1/H2/P2S printers: ffmpeg
Setup
1. Printer details
On the printer's screen:
- IP address and the 8-digit access code: Settings → WLAN (or Network)
- Serial number: Settings → Device
If the camera does not answer, turn on LAN Only Liveview on the printer. You do not need LAN Only Mode for this.
2. Ollama
brew install ollama
brew services start ollama
ollama pull gemma3:4b
On Linux, see ollama.com/download. Other vision models (e.g. qwen2.5vl:3b, or larger ones if you have the memory) can be set with model in the config.
3. PlateSentry
git clone https://github.com/OnurCem/platesentry.git && cd platesentry
python3 -m venv .venv && .venv/bin/pip install -e .
cp config.example.json config.json
Put your printer's IP address, access code and serial number into config.json. That file is listed in .gitignore; keep it private.
4. Try it
Save one camera frame (connection test):
.venv/bin/platesentry --snapshot frame.jpg
Run the model on a photo (for example a photo of a failed print):
.venv/bin/platesentry --test-image photo.jpg
Start monitoring:
.venv/bin/platesentry
Then open http://localhost:8080.
Your computer must stay awake while it monitors a print; PlateSentry does not prevent sleep.
The monitoring loop
Every check_interval_sec seconds, while the printer is printing:
- The latest camera frame is cropped (see Cropping the frame) and sent to the local model, without any job context.
- The model describes the plate and answers two yes/no questions: is there a solid part, and are there loose tangled strands.
- PlateSentry turns that into a verdict: strands →
failure(spaghetti); a part and no strands →ok; no part seen →uncertain(the 4B model also "sees" a part on an empty plate, so a missing part is not trusted as air printing). - A
failureraises the streak; anokresets it;uncertainleaves it unchanged. When the streak reachesfailures_to_alert, you get a notification (and, if enabled and possible, the print is paused).
Checks do not run while the printer is preparing (heating, leveling, homing, ...) or before about min_layer layers are printed.
Cropping the frame
The model shrinks every image to about 900 × 900 pixels, so on a whole 1280 × 720 frame a 20 mm part and its strands are only a few pixels wide. crop sends only the part of the frame where parts are printed, as [left, top, right, bottom] fractions of the frame. On a P1S with parts near the middle of the plate:
"crop": [0.28, 0.19, 0.78, 1.0]
The bottom stays at 1.0 because on a P1S the bed moves down as the print grows. A fixed crop like this one only sees parts near the middle of the plate; for parts outside it, PlateSentry switches to the automatic crop.
Automatic crop. PlateSentry can also find the crop on its own, so it follows parts anywhere on the plate:
- Where the parts are comes from the job's 3MF (downloaded for the reference, so
serialanduse_referenceare needed): the extrusion moves in its gcode give every part's footprint, overhangs and floating islands included, and the height of every layer. - Where that is in the frame comes from a camera calibration: a model of the camera's position and wide-angle lens that turns a point on the plate into a pixel. The bed moves down as the print grows while the camera stays put, so the plate under a part drops towards the bottom of the frame and its top stays just under the nozzle; the crop follows that layer by layer. A calibration for the P1S (and P1P, same camera mount) is included.
- Each part gets a margin of
crop_pad_mm(12 mm) for strands next to it, from the plate up to a little above its printed height. Parts close together share one crop. Parts far apart, for example in opposite corners, get one crop each, and the monitor checks one per call, in turn, so a check still takes one model call (~15 s); a crop that shows a failure is checked again next, and an alert needsfailures_to_alertfailures in a row on the same crop.
auto_crop chooses between the two:
"when_needed"(default): the manualcropwhile every part printed so far is inside it, else the automatic crop. Without a manualcrop, always the automatic crop."always": always the automatic crop."off": always the manualcrop, or the whole frame without one.
The default keeps the manual crop where it works because it gave fewer false flags: both catch the same 7 of 11 failure frames, but on the 100 mm test print the automatic crop flagged 20 of 144 good frames (2 false alerts) against 5 with the manual crop (details). If the automatic crop is not possible (no 3MF, no calibration for the printer), the manual crop is used, and without it the whole frame.
The web UI shows which crop is in use next to the model name. To see the crops on your own frames (recorded with record_frames, or 10 s captures from tools/capture_frames.py):
platesentry --overlay data/dataset
It draws the plate's outline, each part's box and the crops on every frame, plus a contact sheet, into data/dataset/overlay/. If the plate outline does not line up with your plate, your camera needs its own calibration: see Calibrating the camera.
Flagged frames are saved in data/alerts/, the latest analyzed frame in data/latest.jpg, and downloaded 3MF files in data/jobs/.
Configuration
config.json (see config.example.json):
| Key | Default | Meaning |
|---|---|---|
printer_ip |
Printer IP address | |
access_code |
8-digit access code from the printer's screen | |
serial |
Serial number. Without it, status, 3MF reference and pause are disabled | |
camera |
auto |
auto, jpeg (port 6000) or rtsp (port 322) |
model |
gemma3:4b |
Ollama vision model |
ollama_url |
http://localhost:11434 |
Ollama server |
check_interval_sec |
45 |
Seconds between checks |
min_layer |
2 |
Wait until about this many layers are printed |
failures_to_alert |
3 |
Failures in a row before alerting |
min_confidence |
0.6 |
Minimum model confidence to count a failure |
use_reference |
true |
Download the job's 3MF and show its preview in the web UI. It is not sent to the model (see Results) |
auto_crop |
"when_needed" |
Crop the frame to the job's parts, from the 3MF and the camera calibration: "when_needed" (when a part is outside the manual crop, or there is none), "always" or "off". See Cropping the frame |
crop |
null |
Manual crop: [left, top, right, bottom] as fractions of the frame; null = whole frame |
camera_calibration |
null |
Your own camera calibration JSON (tools/calibrate_camera.py); null = the one included for your printer model |
crop_pad_mm |
12 |
Margin around each part, in mm, for strands next to it |
crop_max_groups |
3 |
Parts far apart are checked one crop at a time; with more groups than this, one crop covers them all |
record_frames |
false |
Save every analyzed frame to data/dataset/ for labeling and evaluation |
auto_pause |
false |
Pause on alert. Needs LAN Only Mode + Developer Mode; cloud mode rejects it |
ntfy_topic |
ntfy topic for phone push; pick a long random name, topics are public | |
ntfy_server |
https://ntfy.sh |
ntfy server (can be self-hosted) |
data_dir |
data |
Where frames and 3MF files are stored |
web_host / web_port |
127.0.0.1 / 8080 |
Web UI address |
Network and firewall
PlateSentry connects to these TCP ports on the printer:
| Port | Used for |
|---|---|
| 6000 | Camera (A1/P1 series) |
| 322 | Camera (X1/H2/P2S series) |
| 8883 | Status and commands (MQTT over TLS) |
| 990 | 3MF download (FTPS) |
| 2024–2030 | FTPS data connection (seen on a P1S) |
If the printer is on a separate Wi-Fi network or VLAN (for example an IoT or guest network), allow these ports from your computer to the printer in your router's firewall.
Command-line options
platesentry [--config FILE] [--no-web] [-v]
platesentry --snapshot FILE save one camera frame and exit
platesentry --test-image FILE [--reference 3MF] [--layer N/TOTAL]
platesentry --project JOB_NAME_OR_3MF read a job's 3MF and save its preview
platesentry --eval DIR [--models M1,M2] [--ablate-reference] [--no-reference]
Evaluation
Small local models make mistakes, so changes to the prompt or the model should be measured. PlateSentry can turn real prints into an evaluation set:
- Set
"record_frames": true. Every analyzed frame is saved todata/dataset/frames/, with a row indata/dataset/labels.csv(job, layer, progress, the job's 3MF, and the live prediction). - Label the rows: set
labeltook,failureorskip, and optionallyproblem(spaghetti,detached,blob,air_printing,other). - Replay the labeled frames through one or more models:
.venv/bin/platesentry --eval data/dataset --models gemma3:4b,qwen2.5vl:3b
The output is a table with precision, recall, F1, false-alarm rate, abstention (uncertain) rate, problem-type accuracy and p95 latency for each model. Every prediction is saved to eval-<timestamp>.json for error analysis. A frame counts as flagged exactly as in the live monitor (failure with at least min_confidence). The frame is cropped as in the monitor too; when its parts are far apart, every crop is checked and the frame counts as flagged if any crop is.
A summary of the results so far is in Results.
Security and privacy
- Camera frames are analyzed locally and never leave your computer, unless you enable ntfy, which sends the alert text and frame to your ntfy server.
- The web UI has no password and listens only on
127.0.0.1by default. If you setweb_hostto0.0.0.0, anyone on your network can see the camera and press "Pause print". - The printer uses self-signed certificates, so PlateSentry does not verify TLS certificates when talking to it. Use it on a network you trust.
- Do not share or commit
config.json: the access code gives full local access to the printer.
Limitations
- Only failures that leave strands on the plate are caught: 7 of 11 failure frames in the first tests (see Results). A part that is missing or has moved without leaving strands is not detected from a single frame. Do not rely on PlateSentry alone to catch a failed print yet.
- A rough or folded part surface can look like strands to the model (3.5% of good frames in the tests, none of them 3 in a row). Watch a few prints with the history table before trusting alerts, and raise
failures_to_alertif needed.min_confidencehas little effect now: the model's own confidence was not usable, so a flagged frame always gets 0.9. - Thin or dark parts on a dark plate are hard to see from the camera's low angle; the model then usually answers
uncertain. - Keep the chamber light on during prints; the model cannot judge dark frames.
Development
Run the tests:
.venv/bin/python -m unittest
tools/fake_printer.py serves a camera stream (and optionally a fake Ollama) from a JPEG file, so you can work on the UI without a printer:
.venv/bin/python tools/fake_printer.py --image frame.jpg
License
探索相关项目
加载中…