↓ Skip to main content
  1. Posts/

Inventory Management: From a Spreadsheet Macro to a Web App with a Raspberry Pi Label Printer

·2899 words·14 mins
David Steeman
Author
David Steeman

Earlier this year I wrote about labeling my basement inventory : a LibreOffice spreadsheet called KelderInventory.ods with a macro that prints 12 × 50 mm (½ × 2 in) labels on a Dymo LabelWriter 450. It worked, but only from a PC on my network with the spreadsheet open. Standing in a shop, or in the garage with a phone, I had no way to check whether I already had M3 pan-head screws or which bin the heat-shrink tubing was in.

Today, together with Claude Code, I replaced the whole thing. The inventory is now a small web app on steeman.be: anyone can search it, I can edit it after logging in, and labels come out of the Dymo in the basement no matter which device I press “Print” on.

The box 09 cabinet with the first labels printed by the new system

What I asked for
#

The starting point was short: turn the spreadsheet into a web page so I can look up components anywhere, protect adding and editing with a password, and print labels on the Dymo with the same layout as before. The decisions that followed:

  • Hosting on the same shared hosting as this site, at steeman.be/inventory/ , next to VERBA .
  • Search is public and covers every field, comments included. Only editing needs the password. The pages ask search engines not to index them.
  • The web app replaces the spreadsheet. One source of truth, no syncing between the two.
  • The Dymo moves from the Windows PC to its own Raspberry Pi.
  • Weekly backups as a spreadsheet, kept in three places.
  • A go/no-go test first. If a Pi couldn’t print the labels with the right layout, the project would stop there.

Before writing any code, Claude wrote a functional specification with the design, the security model and a numbered test plan. It grew to about 35 KB and became the place where test results were recorded as the day went on.

Phase 0: can a Pi print these labels?
#

The old macro fought for weeks with label orientation (it’s most of the earlier post). Printing from Linux without a word processor in between meant starting over, so this came first.

My first choice was a Raspberry Pi Zero 2 W, but I had no OTG adapter for its micro-USB port. A Raspberry Pi 1 Model B+ was lying in a drawer with full-size USB and Ethernet, so that became labelpi. It runs 32-bit Raspberry Pi OS with CUPS and the open-source Dymo driver (printer-driver-dymo). Labels are drawn as PDFs with ReportLab in Python, in DejaVu Sans so characters like Ω, µ and × come out right.

The first finding was that my labels were not what I thought. I had always called them Dymo 30334, but in the Linux driver a 30334 is 57 × 32 mm (2¼ × 1¼ in). The roll in the printer is a 99017 suspension-file label, which CUPS knows as w36h144: 12.7 × 50.8 mm (½ × 2 in).

To find the printable area, the test script prints a calibration label with millimetre rulers and puts every layout parameter on the command line. The Dymo can only print from about 5.7 to 49.3 mm along the label and 1.2 to 11.6 mm across it, and the content has to be rotated 270°. At 90° it comes out upside down.

The first calibration label, with a millimetre ruler and the rotation and offset printed on it

I stuck the numbered test labels on a printed scale card with 10 mm squares and rulers, so that I could photograph it and hand it to Claude Code, which worked out all the label formatting from the photo without me touching a ruler. Labels 1 and 2 are the rotation tests (2 is the upside-down one), the others are sample labels with growing amounts of text.

Test labels taped onto a calibration sheet with rulers and a checkerboard

The final layout uses margins of 6.5 mm left, 2.0 mm right, 1.2 mm top and 2.0 mm bottom, with box and bin on the right, printed 1:1 without scaling. All eight tests passed: a batch of six labels without drift, an identical reprint after a reboot, and the special characters. The only weak point is speed. The Pi 1 needs about 9 seconds per label, which I accepted. The decision was go.

The web app
#

The hosting offers PHP 8.4 and MariaDB, so that’s what the app is written in, without a framework. Before building it, a small probe script checked what the host actually supports (PHP extensions, collation, whether .htaccess rules work, whether there’s an edge cache). It found one surprise: plain HTTP was not redirected to HTTPS. The app’s own .htaccess now does that.

Search#

The public page is one search box with live results as you type. Every word has to match somewhere, and case and accents don’t matter. Box and bin numbers work as search terms too: 03/02 (or 3-2) shows box 03, bin 02, and 03 puts box 03 first.

Searching for “screw” in the public inventory search

Admin
#

Behind the password are add, edit, duplicate and delete, a settings page for the label layout with a live SVG preview of the label, and a history of every change, from which deleted items can be restored. The fastest way to fill a box turned out to be Save, print label, add another: type an item, press Enter, the label goes to the printer and an empty form comes back.

Since the admin is reachable from the internet, it got more attention than a hobby page usually does: a strong password hash (argon2id), lockouts per IP address and overall after failed logins, hashed session tokens, protection against cross-site requests and a strict content security policy. The public pages are read-only, set no cookies and are rate-limited.

Printing from anywhere
#

A web server on shared hosting can’t reach a printer in my basement, and I didn’t want to open a port at home. So the Pi does the reaching: a small Python print agent asks the website every 5 seconds whether there’s anything to print, over plain outbound HTTPS with a token. That token can fetch print jobs and backups and nothing else.

Each job carries a snapshot of the label text and the layout settings at the moment I pressed Print, so editing an item afterwards doesn’t change a label that’s already queued. The agent renders the PDF, sends it to CUPS, waits until CUPS reports it as done and then reports back. A job that hangs for two minutes is marked as failed and is not retried automatically, because a retry after a partial failure is how you end up with two labels.

In the admin, a green or red pill shows whether the agent has checked in recently, and each item shows “in print queue” or “printed” with a date, updating by itself while labels are waiting.

The Raspberry Pi 1 B+ next to the Dymo LabelWriter 450

The rest of the day’s labels went straight into the cabinet: chipboard and drywall screws, wall plugs and bolts in box 09.

The box 09 cabinet seen from the front, with new labels on the bins

Backups in three places
#

With the spreadsheet gone, the backup has to be a spreadsheet. Every week the server writes the whole inventory as an .ods file in the old column layout (so it opens in LibreOffice or Excel) plus a .json file for an exact restore. The Pi fetches both every Sunday, checks them and keeps them on its SD card. Every night my main Linux machine pulls them from the Pi with a key that can only read that one folder, and from there they go into the Borg backup and on to the offsite Pi .

The server and the Pi keep the 10 newest sets plus the first of every month, forever. They implement that rule in PHP and in Python respectively, so a test runs both over three simulated years and checks that they keep exactly the same files. If the newest backup gets older than 8 days, the weekly summary mail of my backup system says so.

Restoring takes a .json or an .ods in the old layout. It makes a backup of the current state first, so a wrong restore can be undone.

Testing
#

All of this was developed against a Docker container that mimics the hosting (same PHP and MariaDB versions), so nothing was tried out on the live site first. At the end of the day there were 128 HTTP tests for the web app, the retention test above, and a deploy script that, after uploading, checks the live site: HTTPS redirect, security headers, blocked files, no PHP source visible and no caching of admin pages.

Browser caching caused the only confusing moment. The host sends no cache headers for static files, so my browser kept the very first stylesheet, and two new features (a back-to-top arrow and the green printer status) were invisible to me while working fine. Asset URLs now carry the file’s modification time, so a changed stylesheet reaches the browser at once.

A stand for the Pi
#

A bare Pi 1 with a USB cable and power lead next to the Dymo is untidy, so the last job of the day was an enclosure with the same footprint as the Dymo, 127 × 186 mm (5 × 7.3 in), that the printer stands on. I didn’t draw a single line of it. Claude Code designed it in OpenSCAD from what I told it and from photos I took with my phone, and I only printed the result.

How the design came together
#

I spoke my prompts and let dictation turn them into text, the same way I talk to a friend who’s going to draw something for me. The first one described what I wanted rather than how to build it: the same footprint as the labelmaker so it can stand on top, the Pi’s network and USB side at the back, the cover closed with M2.5 × 5 mm Phillips screws in heat-set inserts, and if possible some room to coil up the spare USB cable to the Dymo. I also mentioned that I use Tinkercad and a Bambu P1S.

Claude chose OpenSCAD because it describes a part in code. Every dimension is a named parameter at the top of the file (footprint, wall thickness, insert hole, screw clearance, corner radii), so a change like “the inserts are smaller” is one number, not a redrawn model. OpenSCAD wasn’t installed, so Claude installed it, wrote pi_enclosure.scad, and exported the base, the cover and a small test coupon as STL files that Bambu Studio or Tinkercad can open directly.

It didn’t hand me the files unchecked. After each change it rendered preview images of the model from several angles (from behind, from above with the cover off, the cover upside down as it prints) and looked at them itself. That is how it noticed its first previews were badly framed, and later that the cover’s partitions stuck 2.3 mm (0.09 in) out above the top panel. For dimensions it trusted numbers more than pictures: it loaded the STL files in Python, checked that they were watertight, and cut horizontal cross-sections through them to measure hole diameters and depths. When I asked whether the insert holes in the cover had really changed or only those in the test coupon, it answered by measuring the holes in the exported files: 3.2 mm, 4.5 mm deep.

The first version used the Dymo’s dimensions from its spec sheet, about 125 × 186 mm, as a plain rounded rectangle. To get the real shape, I turned the Dymo upside down, taped a strip of paper ruler across the underside and took a photo straight from above. I also photographed the Pi.

The underside of the Dymo LabelWriter 450 with a paper ruler taped across it for scale

The ruler gives the photo a scale: its 70 mm (2¾ in) between the 80 and 150 marks span a known number of pixels, so any distance in the picture can be converted to millimetres. Claude read the outline from it at about 127 mm (5 in) wide and 185 mm (7¼ in) deep, close to the spec sheet. The photo also showed what a rectangle would have missed: the front is strongly rounded and the back corners less so, so the footprint got corner radii of 30 mm (1⅕ in) at the front and 20 mm (¾ in) at the back. Later, the back corners went down to 5 mm (⅕ in) so the back wall stays straight where the ports come through. The same photo showed that the Dymo’s cables plug in underneath at the back and leave towards the back, which fixed where the cable exits had to go.

A photo like this is a good check, not a precise measurement. The ruler lies on the bottom of the printer, while the widest part of the body is a few centimetres further from the camera and looks slightly smaller. For a stand that only has to match the printer’s outline to within a few millimetres, it’s enough.

Six rounds of feedback
#

Each round was the same loop: I looked at the previews Claude put on the fileshare, said what I wanted changed, and got a new model, new STLs and an updated assembly guide a few minutes later.

  1. First design from my description: a rectangle with the spec-sheet footprint, the Pi on standoffs, an oval spool at the front to wind the spare cable around, and three notches in the back wall, open at the bottom, for the cables.
  2. The real shape from the photos: the outline of the Dymo with its rounded front, and more room behind the Pi for the USB plug, which with its strain relief is about 40 mm (1.6 in) long.
  3. Ports in the back wall. I didn’t want cables leaving through notches. The USB and Ethernet ports now sit flush with the back wall so I can plug in without opening the stand, the micro-USB power plug goes through a hole next to them, and the spool made way for a cable pocket that opens at the back.
  4. The mirrored Pi. I asked whether the Pi was really positioned right relative to the openings. Claude checked against my photo of the underside of the board and found that it had modelled a mirror image: seen from below everything is reversed, and it had placed the Ethernet and power connectors on the wrong side. It fixed that, made the pocket opening as wide as the pocket (35 mm, 1.4 in) and moved a screw post to the side wall as I asked.
  5. My inserts. Mine are 3.5 mm wide and 3 mm long, smaller than Claude had assumed. The insert holes went to 3.2 mm, a few tenths under the insert’s outside diameter, and 4.5 mm deep, because a 5 mm screw reaches past the end of a 3 mm insert. The test coupon got holes from 3.0 to 3.4 mm to try first.
  6. One name per part. The model, the guide and the file names used base, floor, shell, lid and top for two parts. Now there’s a base and a cover, and shell.stl became cover.stl.

The cover is held to the base by five M2.5 screws in brass heat-set inserts. After the first print I found the screw holes in the base too big: the heads pulled straight through. One more spoken prompt took the holes from 2.9 to 2.7 mm with a 3.4 mm wide, 1 mm deep counterbore for the heads, and removed the recesses for rubber feet, which didn’t print well.

The video below is the design session itself, recorded in the terminal: from my first request to the commit, plus the fix for the screw holes after the first print, and the printed stand at the end. About an hour of work is condensed into a few minutes. Claude’s thinking, the tool runs and the time I spent away measuring and taking photos are sped up; the clock in the bottom right corner shows the real time.

The enclosure design session in Claude Code, condensed from about an hour to a few minutes, with the printed result at the end.

The cover of the enclosure in OpenSCAD, seen from below, with the screw posts and partitions

The cover prints upside down, top panel on the build plate, without supports. It was on the Bambu P1S by the end of the afternoon.

The cover printing in orange on the Bambu P1S

By the next morning the base and cover were printed and screwed together, with the Pi inside and the Dymo on top. From the front, the stand follows the printer’s outline, rounded front and all.

The Dymo LabelWriter 450 standing on the orange printed enclosure, seen from the front

At the back, the Pi’s USB and Ethernet ports line up with the openings in the back wall, and the cables leave towards the back as planned.

The back of the stand, with the Pi’s USB and Ethernet ports in the back wall and the cables plugged in

The Dymo on its stand on my desk, seen from behind, with the Ethernet and USB cables in the back wall and the spare cable in the pocket

Where it stands
#

The spreadsheet and macro are retired into a legacy/ folder in the repository. The old macro can’t print any more anyway, because the Dymo now belongs to the Pi. The labels look the same as before, but I can now search the inventory from my phone in a shop, add a bag of resistors from the couch, and find the label waiting on the Dymo when I get to the basement.

With the Pi tucked away in the stand under the Dymo, the whole print setup takes up no more desk space than the printer alone.

Resources
#