# raithmir/watermeter architecture

> Architecture diagram of the GitHub repository raithmir/watermeter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/raithmir/watermeter
- Repository: https://github.com/raithmir/watermeter

## Overview

This repository provides water-meter survey and gateway firmware, plus a separate handheld survey tool. The primary workflow is to hear wireless M-Bus broadcasts, identify and decode meters, then inspect or export survey results; the gateway path sends readings to Home Assistant. The Tracker survey adds GPS-tagged walks, persistent history, hunting, and a Bluetooth phone page. Relationships for the Tracker are supported by sampled source references; basic survey, gateway, and phone-page links rely on README documentation, since their implementation was not sampled.

Main entry points: [`wio-wmbus-survey/src/main.cpp`](https://github.com/raithmir/watermeter/blob/main/wio-wmbus-survey/src/main.cpp) (Tracker survey app), [`water-meter-gateway.yaml`](https://github.com/raithmir/watermeter/blob/main/water-meter-gateway.yaml) (Gateway firmware), [`water-meter-gateway-xiao.yaml`](https://github.com/raithmir/watermeter/blob/main/water-meter-gateway-xiao.yaml) (XIAO gateway firmware), [`water-meter-survey.yaml`](https://github.com/raithmir/watermeter/blob/main/water-meter-survey.yaml) (Basic survey firmware)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_discovery["Meter discovery"]
  node_survey_firmware["Basic survey firmware"]
  node_xiao_survey["XIAO survey firmware"]
  node_converter["Meter ID converter<br/>[index.html]"]
end

subgraph group_tracker["Tracker survey"]
  node_tracker_app["Tracker survey app<br/>[main.cpp]"]
  node_wmbus["wM-Bus decoding<br/>[wmbus.h]"]
  node_aes["AES routines<br/>[aes128.h]"]
  node_survey_model["Survey records<br/>[survey.h]"]
  node_board["Tracker board mapping<br/>[variant.h]"]
  node_phone["Bluetooth phone page<br/>[index.html]"]
end

subgraph group_persistence["Survey persistence"]
  node_flash[("QSPI flash")]
  node_snapshot["Snapshot ring<br/>[snapring.h]"]
  node_fat["FAT12 formatter<br/>[fat12.h]"]
end

subgraph group_gateway["Gateway and setup"]
  node_gateway_firmware["Gateway firmware"]
  node_xiao_gateway["XIAO gateway firmware"]
  node_ha["Home Assistant"]
end

node_meter(("wM-Bus meters"))

node_meter -->|"broadcasts to"| node_tracker_app
node_tracker_app -->|"decodes with"| node_wmbus
node_wmbus -->|"uses"| node_aes
node_tracker_app -->|"records with"| node_survey_model
node_tracker_app -->|"saves through"| node_snapshot
node_tracker_app -->|"formats via"| node_fat
node_snapshot -->|"reads and writes"| node_flash
node_fat -->|"formats"| node_flash
node_tracker_app -->|"uses pin definitions"| node_board
node_phone -->|"controls and downloads"| node_tracker_app
node_meter -->|"broadcasts to"| node_survey_firmware
node_meter -->|"broadcasts to"| node_xiao_survey
node_converter -->|"supplies meter ID"| node_gateway_firmware
node_survey_firmware -->|"identify then configure"| node_gateway_firmware
node_xiao_survey -->|"identify then configure"| node_xiao_gateway
node_meter -->|"broadcasts to"| node_gateway_firmware
node_meter -->|"broadcasts to"| node_xiao_gateway
node_gateway_firmware -->|"sends readings"| node_ha
node_xiao_gateway -->|"sends readings"| node_ha

click node_tracker_app "https://github.com/raithmir/watermeter/blob/main/wio-wmbus-survey/src/main.cpp"
click node_wmbus "https://github.com/raithmir/watermeter/blob/main/wio-wmbus-survey/src/wmbus.h"
click node_aes "https://github.com/raithmir/watermeter/blob/main/wio-wmbus-survey/src/aes128.h"
click node_survey_model "https://github.com/raithmir/watermeter/blob/main/wio-wmbus-survey/src/survey.h"
click node_board "https://github.com/raithmir/watermeter/blob/main/wio-wmbus-survey/variants/seeed_wio_tracker_L1/variant.h"
click node_snapshot "https://github.com/raithmir/watermeter/blob/main/wio-wmbus-survey/src/snapring.h"
click node_fat "https://github.com/raithmir/watermeter/blob/main/wio-wmbus-survey/src/fat12.h"
click node_phone "https://github.com/raithmir/watermeter/blob/main/wio-wmbus-survey/web/index.html"
click node_survey_firmware "https://github.com/raithmir/watermeter/blob/main/water-meter-survey.yaml"
click node_xiao_survey "https://github.com/raithmir/watermeter/blob/main/water-meter-survey-xiao.yaml"
click node_converter "https://github.com/raithmir/watermeter/blob/main/meter-id/index.html"
click node_gateway_firmware "https://github.com/raithmir/watermeter/blob/main/water-meter-gateway.yaml"
click node_xiao_gateway "https://github.com/raithmir/watermeter/blob/main/water-meter-gateway-xiao.yaml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_survey_firmware,node_xiao_survey,node_converter toneBlue
class node_tracker_app,node_wmbus,node_aes,node_survey_model,node_board,node_phone toneAmber
class node_flash,node_snapshot,node_fat toneMint
class node_gateway_firmware,node_xiao_gateway,node_ha toneRose
class node_meter toneIndigo
```

## Components

### Meter discovery

- [Basic survey firmware](https://github.com/raithmir/watermeter/blob/main/water-meter-survey.yaml): `water-meter-survey.yaml`
- [XIAO survey firmware](https://github.com/raithmir/watermeter/blob/main/water-meter-survey-xiao.yaml): `water-meter-survey-xiao.yaml`
- [Meter ID converter](https://github.com/raithmir/watermeter/blob/main/meter-id/index.html): `meter-id/index.html`

### Tracker survey

- [Tracker survey app](https://github.com/raithmir/watermeter/blob/main/wio-wmbus-survey/src/main.cpp): `wio-wmbus-survey/src/main.cpp`
- [wM-Bus decoding](https://github.com/raithmir/watermeter/blob/main/wio-wmbus-survey/src/wmbus.h): `wio-wmbus-survey/src/wmbus.h`
- [AES routines](https://github.com/raithmir/watermeter/blob/main/wio-wmbus-survey/src/aes128.h): `wio-wmbus-survey/src/aes128.h`
- [Survey records](https://github.com/raithmir/watermeter/blob/main/wio-wmbus-survey/src/survey.h): `wio-wmbus-survey/src/survey.h`
- [Tracker board mapping](https://github.com/raithmir/watermeter/blob/main/wio-wmbus-survey/variants/seeed_wio_tracker_L1/variant.h): `wio-wmbus-survey/variants/seeed_wio_tracker_L1/variant.h`
- [Bluetooth phone page](https://github.com/raithmir/watermeter/blob/main/wio-wmbus-survey/web/index.html): `wio-wmbus-survey/web/index.html`

### Survey persistence

- **QSPI flash**
- [Snapshot ring](https://github.com/raithmir/watermeter/blob/main/wio-wmbus-survey/src/snapring.h): `wio-wmbus-survey/src/snapring.h`
- [FAT12 formatter](https://github.com/raithmir/watermeter/blob/main/wio-wmbus-survey/src/fat12.h): `wio-wmbus-survey/src/fat12.h`

### Gateway and setup

- [Gateway firmware](https://github.com/raithmir/watermeter/blob/main/water-meter-gateway.yaml): `water-meter-gateway.yaml`
- [XIAO gateway firmware](https://github.com/raithmir/watermeter/blob/main/water-meter-gateway-xiao.yaml): `water-meter-gateway-xiao.yaml`
- **Home Assistant**

### Other components

- **wM-Bus meters**

## Connections

- wM-Bus meters → Tracker survey app: broadcasts to (evidence: `README.md`)
- Tracker survey app → wM-Bus decoding: decodes with (evidence: `wio-wmbus-survey/src/main.cpp`)
- wM-Bus decoding → AES routines: uses (evidence: `wio-wmbus-survey/src/wmbus.h`)
- Tracker survey app → Survey records: records with (evidence: `wio-wmbus-survey/src/main.cpp`)
- Tracker survey app → Snapshot ring: saves through (evidence: `wio-wmbus-survey/src/main.cpp`)
- Tracker survey app → FAT12 formatter: formats via (evidence: `wio-wmbus-survey/src/main.cpp`)
- Snapshot ring → QSPI flash: reads and writes (evidence: `wio-wmbus-survey/src/snapring.h`)
- FAT12 formatter → QSPI flash: formats (evidence: `wio-wmbus-survey/src/fat12.h`)
- Tracker survey app → Tracker board mapping: uses pin definitions (evidence: `wio-wmbus-survey/src/main.cpp`)
- Bluetooth phone page → Tracker survey app: controls and downloads (evidence: `README.md`)
- wM-Bus meters → Basic survey firmware: broadcasts to (evidence: `README.md`)
- wM-Bus meters → XIAO survey firmware: broadcasts to (evidence: `README.md`)
- Meter ID converter → Gateway firmware: supplies meter ID (evidence: `README.md`)
- Basic survey firmware → Gateway firmware: identify then configure (evidence: `README.md`)
- XIAO survey firmware → XIAO gateway firmware: identify then configure (evidence: `README.md`)
- wM-Bus meters → Gateway firmware: broadcasts to (evidence: `README.md`)
- wM-Bus meters → XIAO gateway firmware: broadcasts to (evidence: `README.md`)
- Gateway firmware → Home Assistant: sends readings (evidence: `README.md`)
- XIAO gateway firmware → Home Assistant: sends readings (evidence: `README.md`)
