Skip to content

Architecture

Kamil Brylew edited this page Oct 30, 2026 · 1 revision

Architecture

Hardware and processes

flowchart LR
    GM1[GM 1 · Modbus unit 1] <-->|RS485 · 9600 baud| HAT[Monarco HAT]
    GM2[GM 2 · Modbus unit 2] <-->|RS485 · 9600 baud| HAT
    HAT <-->|Pi UART · 115200 baud| Reader[geiger_stream.py]
    Reader <-->|JSON lines| Node[Node-RED 5]
    Node --> UI[FlowFuse dashboard → Chromium kiosk]
    Node --> Writer[influx-write node]
    Node --> Driver[monarco_light.py]
    Driver -->|SPI0 CE0 → DOUT1/2/3| HAT
    HAT --> Light[Three-color tower]
    Writer --> Influx[InfluxDB OSS 2.x]
    Influx --> Grafana[Grafana OSS]
Loading

dashboard/scripts/make_flow.py builds dashboard/flows.json from the Vue touchscreen template and EWT logo. The deployed flow has a geiger-stream custom node, a FlowFuse ui-template, an influx-write node, and a monarco-light node. Node-RED runs as a systemd service; Chromium opens the dashboard from labwc autostart. The optional InfluxDB and Grafana services run on the same Pi.

Reading path

  1. The geiger-stream node launches python/geiger_stream.py using the pinned nlab-modbus-devices virtual environment. It owns /dev/serial0 and polls units 2, then 1 on one Modbus connection, aiming for a one-second cycle. GM 2 goes first so a GM 1 timeout does not delay its tower update.
  2. Each successful poll reads all 20 input registers in one FC04 request. The reader checks the hardware ID, decodes values using the backend register map, and emits a timestamped JSON line. Errors produce per-board offline messages; if all boards fail, the reader reconnects the serial bus.
  3. Node-RED fans readings out to the dashboard, tower controller, and optional Influx writer. It retains up to 60 seconds or 240 samples per board in memory for touchscreen plots. Touchscreen actions such as refresh, reconnect, pulse-total reset, reference-dose entry, About information, and tower-setting changes return through the flow. The reference value is shared by both GMs and held in Node-RED memory; it starts empty after a restart.
  4. The dashboard displays the selected board's values and exact raw register words. Swiping left selects GM 2 and swiping right selects GM 1. It marks displayed data stale after five seconds. The tower uses only its configured source board and rejects readings older than three seconds.

The geiger-stream node restarts a failed reader after two seconds. The tower node restarts its SPI driver if it exits. Reader restarts do not erase the separately persisted Pi-side pulse totals.

Tower control

The conditional monarco-light node saves the selected GM and ordered dose-rate boundaries in ~/.local/state/dosimeter-gate/light-zones.json. It passes only a fresh, finite dose_level_usvh value to python/monarco_light.py. Negative finite values are treated as zero for tower control. The Python driver holds an exclusive SPI lock, refreshes Monarco outputs, implements the red flash, and sends off frames when it stops. If its input is absent for more than three seconds, all outputs go off.

The default channel mapping is DOUT1 red, DOUT2 orange, DOUT3 green. The flow generator also offers diagnostic configurations for an orange heartbeat, a color cycle, or no light. The deployed default is dose-rate control.

History path

The influx-write node accepts only successful board readings. It writes a geiger measurement tagged unit=gm1 or unit=gm2 to the local InfluxDB geiger bucket in the dosimeter-gate organization. When set, the operator-entered reference_dose_usvh field is attached to each subsequent successful board sample; otherwise the field is omitted. Grafana overlays it on the dose-rate panel. It buffers at most 3,600 readings in Node-RED memory and retries failed writes every five seconds. Grafana queries the bucket through a separate read-only token. InfluxDB retains data for 90 days; earlier measurements are not backfilled.

Node-RED, InfluxDB, and Grafana bind to loopback addresses on ports 1880, 8086, and 3000 respectively. Remote access uses an SSH tunnel. The dashboard works before history is installed; its writer reports a missing token until provisioning supplies one.

State and source files

Path Purpose
dashboard/ui/geiger.vue Touchscreen template embedded into the generated flow
dashboard/nodes/ Node-RED reader, tower, and Influx writer nodes
dashboard/python/ Modbus reader, pulse accounting, and Monarco SPI driver
dashboard/timeseries/ Provisioned Grafana dashboard and configuration
dashboard/calibration/ Committed dose coefficient sets; not applied automatically
~/.local/state/dosimeter-gate/ Live per-board pulse totals and tower settings
/etc/dosimeter-gate/ Root-managed history credentials and service environment files

Live state, database files, and credentials are outside Git. The separate nlab-modbus-devices backend is cloned during installation and is not vendored into this repository.

Clone this wiki locally