AIThis post was created with the assistance of artificial intelligence (AI).

A first-person report by Thorsten Meyer.

Buying for a business?Offer from Amazon

Get business pricing on monitors, keyboards and dev gear

  • Business-only prices and quantity discounts
  • Tax-exempt purchasing
  • Multiple users, one account, clear invoices
As an affiliate, we earn on qualifying purchases.

A 3D printer looks like hardware, but most of what matters about it is data: status messages, sliced files, material per job, hours on the machine. When I wanted to know what each print on my Bambu Lab X2D really cost, I did not need a new gadget. I needed a small, boring, local piece of software.

It is called Lagvik. Here is how it is put together, which design choices held up in the first week, and which numbers it produces.

Lagvik print record showing material cost, filament grams and result of one job
The output that matters: one record per print. Power stays empty until it is measured.

What does the architecture look like?

Deliberately plain:

  • One service on a small home server. It is written in TypeScript and serves a web interface on the home network.
  • SQLite as the database. One file, easy to back up, plenty for a single user. The schema has grown through 34 migrations so far, each one small.
  • MQTT for the printer status. The printer publishes its state on the local network. The service subscribes and never publishes a command back.
  • An encrypted file connection for the finished job. After each print, the service fetches the sliced print file from the printer, read-only, and reads the planned grams per filament from the slicer metadata inside it.
  • No cloud in the loop. Nothing leaves the network. Slicing and printer control stay in the maker’s own software, Bambu Studio and the companion app.

Why read-only towards the printer?

Because the cost of a bug is asymmetric. A tool that can only listen can produce a wrong number, which I will notice and fix. A tool that can send commands can ruin a fourteen-hour job or worse. So the printer integration has exactly two verbs: subscribe and download.

The same rule extends to power. Smart plugs measure the printer’s energy, but the service is not allowed to switch the printer’s plug, ever. It may switch harmless devices, such as an air purifier, and even that is currently a dry run: until the switching plug is installed, the rule only writes to the log when the purifier would have turned on and off.

What does a record per print give you?

Per-print records answer the questions people actually ask. Here is what the first week produced, single prints on the X2D, all successful:

  • Plate of desiccant cores — Material: PETG · Grams: 258 · Duration: 13 h 47 min · Material cost: €2.59
  • Second plate of desiccant cores — Material: PETG · Grams: 235 · Duration: 13 h 34 min · Material cost: €2.37
  • Holder for the filament-path switch — Material: PETG · Grams: 137 · Duration: 5 h 55 min · Material cost: €1.37
  • Toolbox frame — Material: PETG · Grams: 68 · Duration: 1 h 58 min · Material cost: €0.68
  • Toolbox side lock — Material: PETG · Grams: 38 · Duration: 1 h 58 min · Material cost: €0.38

Two details from building it. First, the grams come from the slicer’s plan, read back after the print. That is not a weighing, and for a failed print it would be wrong, so the result of every job is stored next to the grams. Second, an unknown value is stored as unknown, not as zero. The power column is empty, and the interface says “power unknown”. A zero would quietly make every print look cheaper than it was.

Lagvik printer record with operating hours, prints and failures
Printer record: 63.2 hours, 16 prints, 16 ok, 0 failed.

Which smaller pieces were worth building ourselves?

  • Web push without a third-party service. Notifications reach my phone through the browser’s standard push channel, with the message encryption implemented in our own code following the published web push standards. No push provider sees the content.
  • An offline-capable app. A service worker lets the interface open on the phone like an app. It needs a secure connection, so on plain HTTP the settings page says so and everything else keeps working.
  • Home Assistant integration over the same MQTT broker. The service announces itself, so the printer state can sit next to the lights and the heating, and automations can react to “print finished”.
  • Code-CAD instead of a GUI CAD dependency. Simple parts, such as a spacer sleeve, a screw-top box, a cable clip, a hinge, a snap hook and a wall hook, are defined in code from a few parameters and exported as 3MF for the slicer.

Which licence decisions shaped the code?

Some of the best open-source tools in 3D printing carry strong copyleft licences. The project rules say: slicer source code under AGPL and CAD tools under GPL are never copied into the codebase, and no LGPL code goes into the browser modules. That is why the code-CAD part is our own, small and limited, rather than a wrapper around a large CAD kernel. Every new dependency gets a licence check first.

Schematic animation of infill patterns inside a printed part
The slicer decides how dense the inside of a part is, and with it most of the grams.

How is it tested?

The test suite runs before every deploy, and anything that touches the printer counts as done only after it worked on the real printer or the real plug. The interface is checked at phone, tablet and desktop width. Each test run and review round goes into an append-only review register, so the history of what was checked stays readable.

When the service records traffic from a new printer model for test fixtures, it redacts with an allowlist: values under keys that look like serial numbers, addresses, codes or tokens are replaced, and anything else is kept only if it is short and harmless.

What this means for you

  • Start read-only. Listening to a device gives you most of the value with almost none of the risk.
  • Store unknown as unknown. Missing data that defaults to zero will mislead every report built on top of it.
  • Keep one record per event. For a printer, the event is a finished job. Aggregates can always be computed later; lost detail cannot.
  • Check licences before you borrow. In 3D printing, the convenient library is often under a licence that changes what you may ship.

Lagvik is an internal tool for our own workshop, not a product you can download. If you build your own, a single service, a SQLite file and an MQTT subscription will get you surprisingly far.

BLACK FRIDAY

Black Friday Picks

Bose QuietComfort Headphones (2nd Gen), Wireless Over-Ear Noise-Cancelling Headphones, Black

Bose QuietComfort Headphones (2nd Gen), Wireless Over-Ear Noise-Cancelling Headphones, Black

As an affiliate, we earn on qualifying purchases.

You May Also Like

The Federated Code Forge

Tangled’s new architecture lets teams host code and project records on their own servers while collaborating through the AT Protocol.

What It Took To Make My AI-Coded PDF Editor Dependable

Thorsten Meyer says six days of real-file testing and review exposed serious gaps in Docestra, his private AI-coded PDF editor.

Free Pascal Compiler Now Supports Dynamic Packages

A new Free Pascal and Lazarus release supports dynamic packages for IDE components and runtime plugins, with platform-specific restrictions.

The Forgetful CPU (Linux On M4)

A developer reports booting Linux to a shell on an M4 Mac mini after resolving early CPU, memory-mapping and interrupt-related crashes.