# Klipper printers
The **Klipper printer** widget shows 3D printers that run [Klipper](https://www.klipper3d.org) with
[Moonraker](https://moonraker.readthedocs.io), the API behind Mainsail and Fluidd: a **Snapmaker U1**, a Voron, a
Creality K1 or K2 with Moonraker, a RatRig and so on. For each printer it shows the state, the progress, the time left
and when the print will be done, the layer, the file name and the temperatures. On a printer with several tool heads,
such as the Snapmaker U1, each head gets a chip with the colour and the material of the filament loaded in it, and the
one in use stands out.

Demo data. From the left: 6 × 4, 4 × 3, 2 × 2 and, in the bottom row beside the metric tiles, 3 × 2.
The agent on the computer asks the printer, never the phone, and it only reads: it sends no G-code and calls nothing
that changes the printer, so it cannot start, pause, stop or change a print.
## Set it up
1. Find the printer's IP address: in its network settings on its screen, in your router, or in the address bar of
Mainsail or Fluidd.
2. In **Settings › General › Klipper printers**, press **Add a printer** and enter a **Name** (what the phone shows) and
the **IP address**. The **Port** is Moonraker's, 7125 unless you changed it; on the Snapmaker U1, 80 works as well.
3. Press **Test**. It asks Moonraker once, with what is on the page (even before you save), and says Klipper's state
and Moonraker's version, or what went wrong.
4. Turn on **Read Klipper printers** and save.
5. Add the **Klipper printer** widget to a page (**Web & data**). With **Printer name** empty it shows every printer;
with a name, only that one. Its options also hide the file name or the temperatures.

Up to four printers can be added. The printer has to be on your local network: a private IPv4 address (`10.x`,
`172.16–31.x`, `192.168.x`), a link-local one, an IPv6 unique local one (`fd…`) or this computer. Any other address is
refused, and so is a name that resolves to none of these, before anything is sent. **Test** says so for such an address,
and saving leaves that printer out. When a name resolves to several local addresses, they are tried in turn. A name is
looked up through this computer's DNS resolver first, which may be outside your network; an IP address needs no lookup.
### API key
Moonraker answers without a key from the addresses its `[authorization]` section trusts, which on most printers
(the Snapmaker U1 included) covers the local network. If it asks for one (Test says so), enter Moonraker's API key in **API key**: Moonraker
answers `GET /access/api_key` with it from an address it trusts, and Mainsail and Fluidd show it in their settings. The key is write-only, like the MQTT password: the settings page shows that one is
saved but never gets it back, and it never reaches the phone or the log. **Remove the saved key**, under the printer,
removes it when you save.
Two things to know about the key:
- Moonraker's API is plain HTTP, so the key crosses the local network unencrypted, as it does from Mainsail or Fluidd.
- A Moonraker key allows control as well as reading: whoever has it can send G-code, start, pause or cancel a print.
PhoneBox only reads with it, and it stays on this computer for that reason.
## What the widget shows
| | Where it comes from |
|---|---|
| State | Klipper's print state (`print_stats.state`): printing, paused, finished, cancelled, error, idle. When Klipper itself is not ready (shut down, starting) the widget says so with Klipper's message |
| Progress | The slicer's own progress (`M73`, which Snapmaker Orca, OrcaSlicer, PrusaSlicer and SuperSlicer write), else how far the file has been read |
| Time left, finish time | See below. The phone counts down between updates and works out the finish time on its own clock |
| Layer | `SET_PRINT_STATS_INFO` (sent by Orca and PrusaSlicer based slicers), else the slicer's layer count |
| File | The file's name without its folder and `.gcode` |
| Tool heads | Every `extruder`, `extruder1`… with its temperature and target. On the Snapmaker U1 also the colour and the material of the filament set on the printer (`print_task_config`); the head in use is outlined |
| Bed, chamber | `heater_bed`, and a chamber sensor: the U1's `temperature_sensor cavity`, or a `temperature_sensor` or `heater_generic` with "chamber" in its name |
The time left starts from the slicer's estimate (from the file's metadata) less the time printed so far, and leans
more on the printer's real pace as the print goes on: at 10 % it is mostly the slicer's estimate, at 90 % mostly the
pace so far. Tool changes and cooling on a multi-head printer make the real pace slower than the slicer thinks, and the
estimate catches up as the print goes on. A file printed without metadata uses the pace alone.
### Small sizes
The widget fits the size you give it. From 4 × 3 up it shows everything that fits, and leaves out a row that does not
fit whole rather than cutting it: the temperatures first, then the layer and file, then the tool heads. Smaller than that, a 3 × 2 tile next
to the metric tiles for example, it switches to a compact view: the percentage large, the time left, the bar, the finish
time and the tool head in use. At 2 × 2 it keeps the name, the percentage, the time left and the bar.
## When it asks the printer
A printer is asked only while a **Klipper printer** widget on an enabled page (or in an enabled Smart Stack) shows it:
every 5 seconds, `/printer/objects/query` for the objects above, `/printer/objects/list` once per connection and the
file's metadata once per file (asked again later when a read fails). With no such widget, with the setting off or the printer removed, the agent does not
ask it on its own. Only **Test** in Settings still asks `/server/info` once, when you press it, even before the setting
is on. A printer that does not answer is tried again after 5 seconds, then 10, 20, 40 and every 60 seconds.
The phone gets each printer's name, the connection's state (and only the kind of an error) and what the table above
lists. It never gets the address, the port or the API key, and it never contacts the printer itself.
## Troubleshooting
| The widget says | Check |
|---|---|
| The printer could not be reached | The IP address and the port, that the printer is on and on the same network as the computer. Mainsail or Fluidd should open at `http://` from the computer |
| Moonraker asks for an API key | See [API key](#api-key) |
| Something answered, but not Moonraker | The port: 7125 by default. Port 80 is often Mainsail's or Fluidd's web server, which on most printers passes the API through, but not on all |
| This address is not on your local network | Enter the printer's local address (such as `192.168.1.35`), not a public one or a cloud link |
| No time left while printing | The slicer wrote no estimate and the print has barely started: the time appears from about 1 % |