fabbr@site:~/projects/magellan/device$

device

// ~/projects/magellan/device.rs
let device = Project {
    status: Status::Active,
    started: "2026-09-20",
    tags: &["rust", "tokio", "modbus"],
    repo: Some("https://github.com/fabbrito/magellan-device"),
};

magellan-device is a Rust binary on a Raspberry Pi 2 B. Today it reads one source, a Sofar solar inverter, through the Wi-Fi logger attached to it, over Modbus TCP on the LAN. The inverter is the one link in the chain I don’t control: its own app keeps the energy totals when the internet drops, but loses the detail of that stretch. So the binary does the reading itself, every five minutes in daylight, writes each batch to a buffer on flash, and uploads it when the cloud is reachable.

polluploadoutage: retryinverterbuffer onflashcloud

Everything specific to the inverter, from its register map to scaling and units, stays in magellan-device. It describes its sources and metrics in a manifest, and the cloud stores them as declared, so a new kind of source is a new driver here, with no change to the cloud.

How it got here

The first version was a Python prototype on an existing library for these loggers, and it never worked: the logger answered with broken frames, and at the time I couldn’t figure out why. Looking back, I believe the requests the library sent didn’t match this logger and inverter. So I stopped working around the library and mapped the inverter’s registers myself, from a community spreadsheet checked against captures from my own installation.

With the map in hand I wrote a Rust proof of concept for this one inverter, and soon dropped it in favor of Magellan. On 2026-09-21 its Modbus codec moved into magellan-device, its ten captured frames carried over unedited, and it became the first driver behind the source seam.

One more fix came from the inverter going dark. It shuts down at night, the logger with it, and when the router let the logger’s lease lapse it came back in the morning at a new address. Since 2026-09-28 the driver finds the logger by broadcast on the LAN whenever a sweep can’t reach it.

Through an outage

When the internet drops, uploads stop but polling doesn’t, since the logger is on the LAN. Each sweep’s batch is written to the buffer on flash before anything is sent, so a reboot or a power cut loses nothing already queued. When the link returns, the binary drains the buffer oldest first, one batch per second, and while the cloud keeps declining it backs off from 5 seconds up to 5 minutes, with jitter. The buffer holds 2016 batches, a week of sweeps; past that it drops the oldest, and the gap shows in the sequence. Before a reading is queued, the binary checks it against the contract’s limits and refuses it there, so nothing waits in the buffer only to be rejected by the cloud.

How the code is written

The buffer’s limit of 2016 batches is one case of a rule the whole codebase follows: everything has a stated bound. The rules come from an adaptation of TigerStyle, and the other one that shapes this binary is that a programmer error crashes it. A panic aborts the whole process, because tokio would otherwise catch it inside one task and leave a binary that looks alive and never polls again. Then systemd restarts it, and the batch it was handling is still in the buffer for the next drain. Where I departed from TigerStyle is the assertions: the workspace denies the panic family, so assertions sit only where a function cannot fail, and everywhere else a function returns an error.

Decisions

  • magellan-device only reads. The driver never writes a register or sends the inverter a command.
  • Runtime, drivers and platform are separate crates, so code that reaches across a layer fails to build.
  • The inverter is polled only inside a sun window, while an hourly heartbeat reports uptime and buffer depth day and night. So a quiet night never trips Grafana’s silent alert, which is set to fire when the binary is down or cut off; no notification channel is wired to it yet.

What’s next

Only one source is installed. magellan-device can already read a second kind, a node: an ESP32 on the LAN that publishes a register map over Modbus TCP and is found by mDNS. The contract for it is set in magellan-device, but the node itself, magellan-node, isn’t started yet.