Fix /healthz false alarms; default to 512-dot TM-T88 profile
CI / Lint, test and scan (push) Successful in 1m42s
CI / Lint, test and scan (push) Successful in 1m42s
Hardware testing on the real printer (an Epson TM-T88IV, not a TM-T20II) turned up two problems, and an adversarial review found three more. Printer status - Treat DLE EOT 2 bits (cover open, paper-end stop) as offline causes: Status.Normalized clears them while DLE EOT 1 reports the printer online. The TM-T88IV reported online + cover open while printing and cutting a long receipt, which made /healthz return 503. - PaperOut now comes only from the DLE EOT 4 roll-paper sensor; the paper-end stop is reported separately as PaperEndStop. - /healthz re-reads a printer that looks not ready after 750 ms and only reports a problem that is still there. - A status read cut short by the caller's deadline now returns context.DeadlineExceeded (503 "timeout") instead of ErrStatusUnsupported, which /healthz reported as 200 "unknown" and could hide an offline printer. Printer profiles - Default model is now tm-t88 (512 dots, 42/56 columns). A profile wider than the printer makes it break words mid-line; a narrower one only shortens lines. - Add tm-m50 (TM-m50/II) and document TM-T88IV-VII, 58 mm paper on 180-dpi printers, and that the TM-T88VII does not report paper near-end through real-time status. - README example banner shortened to 42 characters to fit the default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6502d9551d
commit
afcf96431f
12 files changed
+328
-69
No files matched your search
@@ -82,7 +82,7 @@ curl -X POST https://printer.example.com/api/v1/print \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"elements": [
|
||||
{"type": "text", "text": "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓"},
|
||||
{"type": "text", "text": "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓"},
|
||||
{"type": "text", "text": "┌─────────────────────┐\n│ !!! ACHTUNG !!! │\n└─────────────────────┘", "align": "center"},
|
||||
{"type": "text", "text": "Überbringer", "size": 2, "bold": true, "align": "center"},
|
||||
{"type": "feed"},
|
||||
@@ -136,6 +136,21 @@ curl -H "Authorization: Bearer $TOKEN" https://printer.example.com/api/v1/jobs/j
|
||||
A printer that accepts connections but does not answer status requests is
|
||||
reported as `"status": "unknown"` with HTTP `200`.
|
||||
|
||||
Details:
|
||||
|
||||
- **Brief problems are re-checked.** A printer that looks not ready is read
|
||||
again 750 ms later, and only a problem that is still there gives `503`.
|
||||
While cutting or feeding, a printer can report a problem for a moment.
|
||||
- **Timeouts.** The printer accepts one connection at a time. While it is still
|
||||
taking in a large job, the 3-second health check can run out of time. That
|
||||
gives `503` with printer status `"timeout"`, because the printer's state is
|
||||
unknown.
|
||||
- **The cover flag** is only reported while the printer is offline. Epson
|
||||
printers always go offline when the cover opens.
|
||||
- **Paper low on the TM-T88VII.** That model does not report paper near-end
|
||||
through real-time status, so `"near_end"` never appears for it; paper out
|
||||
is still reported.
|
||||
|
||||
### Errors
|
||||
|
||||
Errors are JSON: `{"error": "message", "details": ["..."]}`.
|
||||
@@ -169,7 +184,7 @@ element is already a `cut`.
|
||||
| `bold` | `false` | |
|
||||
| `underline` | `0` | 0, 1 (thin) or 2 (thick) |
|
||||
| `invert` | `false` | white on black |
|
||||
| `font` | `a` | `a` (48 columns on 80 mm) or `b` (64 columns, smaller) |
|
||||
| `font` | `a` | `a`, or `b` (smaller: 56 instead of 42 columns on a TM-T88) |
|
||||
| `align` | `left` | `left`, `center`, `right` |
|
||||
| `newline` | `true` | `false` keeps the next element on the same line |
|
||||
| `wrap` | `true` | `false` sends the text as-is and lets the printer wrap |
|
||||
@@ -179,7 +194,7 @@ default. Characters the code page lacks, such as emoji, print as `?`. Control
|
||||
characters are removed so text can never be read as printer commands.
|
||||
|
||||
**Word wrap.** The line width comes from the printer model and the character
|
||||
size: 48 characters at size 1, 24 at size 2, and so on. Lines break at spaces,
|
||||
size: on a TM-T88, 42 characters at size 1, 21 at size 2, and so on. Lines break at spaces,
|
||||
and only a word longer than a whole line (a long URL, say) is split. The
|
||||
renderer tracks the position across `"newline": false` elements, so mixed
|
||||
sizes on one line still wrap correctly.
|
||||
@@ -216,7 +231,7 @@ sizes on one line still wrap correctly.
|
||||
|----------|---------|--------|
|
||||
| `url` | | `http`/`https` URL, or use `base64` |
|
||||
| `base64` | | Image data, or a `data:image/png;base64,...` URI |
|
||||
| `width` | natural | Target width in dots, up to the paper width (576 on 80 mm) |
|
||||
| `width` | natural | Target width in dots, up to the model's print width (512 on a TM-T88) |
|
||||
| `align` | `left` | |
|
||||
|
||||
PNG, JPEG, GIF and WebP are supported. Images wider than the paper are scaled
|
||||
@@ -269,9 +284,22 @@ errors, so a typo can't silently fall back to a default.
|
||||
|
||||
Settings worth knowing:
|
||||
|
||||
- `printer.model`: `tm-t20` (default), `tm-t88`, `generic-80mm` or
|
||||
`generic-58mm`. It sets the paper width and characters per line.
|
||||
`paper_width` and `columns` override it.
|
||||
- `printer.model` sets the print width and characters per line:
|
||||
|
||||
| Model | Printers | Width | Font A / B columns |
|
||||
|-------|----------|-------|--------------------|
|
||||
| `tm-t88` (default) | TM-T88IV, V, VI, VII | 512 dots (180 dpi) | 42 / 56 |
|
||||
| `tm-m50` | TM-m50, TM-m50II | 512 dots (180 dpi) | 42 / 56 |
|
||||
| `tm-t20` | TM-T20, II, III | 576 dots (203 dpi) | 48 / 64 |
|
||||
| `generic-80mm` | other 80 mm, 203 dpi | 576 dots | 48 / 64 |
|
||||
| `generic-58mm` | 58 mm paper, 203 dpi | 384 dots | 32 / 42 |
|
||||
|
||||
For 58 mm paper on a 180-dpi printer (TM-T88VII, TM-m50II), use a
|
||||
`tm-t88` or `tm-m50` model with `paper_width = 360` (30 Font A columns).
|
||||
|
||||
If words break at the right edge (for example `seve` on one line and `ral`
|
||||
on the next), the model is wider than the printer. `paper_width` (dots) and
|
||||
`columns` (Font A characters per line) override the model.
|
||||
- `printer.codepage`: `cp437` (default), `cp850`, `cp858` (has €) or
|
||||
`cp1252`.
|
||||
- `webserver.trusted_proxies` / `proxy_header`: the real client IP for
|
||||
|
||||
Reference in new issue
Block a user