No description
  • Erlang 80.2%
  • Python 13.3%
  • Shell 3.5%
  • Dockerfile 3%
Find a file
2026-11-24 01:13:09 +01:00
.github ci: call the C4 gate that reads the front page 2026-10-23 21:10:01 +02:00
apps/mcl_victron The Erlang cookie stays on the box; distribution and epmd on loopback (PR 1 squashed) 2026-11-23 21:21:43 +01:00
architecture c4: draw the model from the code, and hold it with a gate (#10) 2026-10-23 02:51:32 +02:00
assets c4: draw the model from the code, and hold it with a gate (#10) 2026-10-23 02:51:32 +02:00
config The Erlang cookie stays on the box; distribution and epmd on loopback (PR 1 squashed) 2026-11-23 21:21:43 +01:00
deploy The Erlang cookie stays on the box; distribution and epmd on loopback (PR 1 squashed) 2026-11-23 21:21:43 +01:00
scripts The Erlang cookie stays on the box; distribution and epmd on loopback (PR 1 squashed) 2026-11-23 21:21:43 +01:00
.gitignore feat: mcl-victron 0.1.0, the macula 12 port of hecate-victron 2026-09-24 01:32:21 +02:00
.tool-versions feat: mcl-victron 0.1.0, the macula 12 port of hecate-victron 2026-09-24 01:32:21 +02:00
CHANGELOG.md deps: declare macula, at 16 2026-10-22 03:01:03 +02:00
Containerfile The Erlang cookie stays on the box; distribution and epmd on loopback (PR 1 squashed) 2026-11-23 21:21:43 +01:00
LICENSE feat: mcl-victron 0.1.0, the macula 12 port of hecate-victron 2026-09-24 01:32:21 +02:00
README.md README: drop the GitHub Sponsors badge 2026-11-23 22:20:53 +00:00
rebar.config deps: declare macula, at 16 2026-10-22 03:01:03 +02:00
SECURITY.md SECURITY.md: response times, attachment and identity rules, drills (macula-io/macula#174) 2026-10-31 02:59:51 +01:00

CI License ghcr.io BEAM Buy Me a Coffee

Macula

--- **Victron energy telemetry on the mesh.** mcl-victron watches a Victron GX device (Cerbo, Venus GX) through its `dbus-flashmq` MQTT broker on the LAN. It records every reading in its own [reckon-db](https://hex.pm/packages/reckon_db) store and publishes each one live on the [macula](https://github.com/macula-io/macula) mesh.

It runs on macula 16 through mcl_om 1.4 (wire 1.0), and every reading it publishes is signed post-quantum.

How a reading travels

  1. receive_victron_mqtt speaks MQTT 3.1.1 to the broker (mqtt_packet, QoS 0, about 200 lines, no library). It subscribes to N/+/+/+/# and sends both keepalives a GX needs: PINGREQ for the broker session, and R/<portal>/keepalive so the GX keeps publishing values. The first keepalive for a portal on each connection asks the GX to republish every topic, which is how the current values arrive. Every keepalive after that carries suppress-republish, so from then on the GX sends only what changes. A broker that stops answering for 1.5 keepalives is left and dialled again.
  2. Each notification becomes a record_victron_reading_v1 command, which evoq dispatches to the victron_device aggregate. The aggregate has one stream per GX device in mcl_victron_store: victron- followed by the first 128 bits of the sha256 of its portal id, in hex.
  3. The recorded victron_reading_recorded_v1 event reaches the emitter, which publishes it as a reading_recorded_v1 fact. Each publish runs in a worker the emitter monitors, with at most 64 in flight at once.

A zero-byte payload, a non-JSON payload and {"value": null} are absences, not measurements, so they are not recorded.

Mesh surface

One fact, on <realm>/mcl-victron/victron/energy/reading_recorded_v1:

Field What
portal_id the GX device's VRM portal id
service battery, solarcharger, vebus, grid, system, ...
instance the device instance, as text
dbus_path the D-Bus path under the service, e.g. Dc/0/Voltage
value what the GX reported: a float, an integer, text, or a list or map of those. Booleans travel as 1/0
observed_at epoch ms, when this service received it

The device and the path are in the payload, not in the topic. A consumer subscribes once and filters.

There are no procedures of its own. As on every mcl service, mcl_om adds two open ones: mcl-victron/info and mcl-victron/get_limits.

Live, not queued

The store is the durable record, and ingest never waits for the mesh. A reading the mesh does not take is dropped from publishing and kept in the store. Readings published after an outage would reach consumers as if they were current, so they are not replayed. A restart's replay of the store's history is skipped for the same reason. The emitter counts the readings it could not publish and logs the count at most once a minute.

The store keeps every reading, and a device's stream grows without bound. Snapshots mean an aggregate's start doesn't replay the whole stream, but nothing limits the store's size yet. That decision waits until a real GX has run for a week, so the rate is known: #1.

Build and test

scripts/ci-gate.sh                 # lint, eunit, dialyzer in the CI image, as root
FRESH=1 scripts/ci-gate.sh         # the same, with no cached _build: what CI sees
rebar3 as prod release

record_victron_reading_tests dispatches readings against a real reckon-db store, opened the way mcl_om:boot/1 opens it. The same test follows each reading through the real store subscription and the emitter to the publish. receive_victron_mqtt_tests runs the receiver against a fake broker on a local socket.

Configuration

Variable Default What
MCL_REALM (required) the realm tag, 64 hex
MCL_REALM_NAME (required) the realm name the topic carries; its sha256 must be MCL_REALM
MCL_REALM_KEY (required) the realm's public signing key, hex
MACULA_STATION_SEEDS (required) host[:port],...
MACULA_STATION_NODE_IDS (required) the seeds' node ids, 64 hex each, in the same order
VICTRON_MQTT_HOST (required) the GX device's LAN address
MCL_BOX (required) the host it runs on. It labels the boot claim, and the realm admits no claim without it
MCL_SERVICE_NAME mcl-victron the service, on the same claim
VICTRON_MQTT_PORT 1883 dbus-flashmq's port
VICTRON_MQTT_KEEPALIVE_SEC 30 seconds between keepalives
MCL_DATA_DIR /data the reckon-db store
MCL_HEALTH_PORT 8483 /health
MCL_NODE_NAME, MCL_NODE_HOST, MCL_COOKIE mcl_victron, 127.0.0.1, unset Erlang distribution. Distribution and epmd listen on 127.0.0.1 only. No cookie ships: with MCL_COOKIE unset the image makes a random one on first start (/etc/mcl/secrets/erlang.cookie, 0600) and keeps it.

The node identity is kept at /etc/mcl/secrets/identity.key and must be on a persistent volume. The service must share a LAN with the GX. deploy/docker-compose.yml runs it with both volumes in place.

/health reports degraded when the service is not connected to the GX's broker, or when the broker has been silent for more than 1.5 keepalives.

Architecture

The C4 model is in architecture/README.md, with its diagrams drawn by architecture/c4_diagrams.py into assets/. Change the script, run it (python3 architecture/c4_diagrams.py), and look at the result before committing.

mcl-victron system context

License

Apache-2.0