- Erlang 80.2%
- Python 13.3%
- Shell 3.5%
- Dockerfile 3%
| .github | ||
| apps/mcl_victron | ||
| architecture | ||
| assets | ||
| config | ||
| deploy | ||
| scripts | ||
| .gitignore | ||
| .tool-versions | ||
| CHANGELOG.md | ||
| Containerfile | ||
| LICENSE | ||
| README.md | ||
| rebar.config | ||
| SECURITY.md | ||
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
receive_victron_mqttspeaks MQTT 3.1.1 to the broker (mqtt_packet, QoS 0, about 200 lines, no library). It subscribes toN/+/+/+/#and sends both keepalives a GX needs:PINGREQfor the broker session, andR/<portal>/keepaliveso 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 carriessuppress-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.- Each notification becomes a
record_victron_reading_v1command, which evoq dispatches to thevictron_deviceaggregate. The aggregate has one stream per GX device inmcl_victron_store:victron-followed by the first 128 bits of the sha256 of its portal id, in hex. - The recorded
victron_reading_recorded_v1event reaches the emitter, which publishes it as areading_recorded_v1fact. 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.
License
Apache-2.0