# mruettgers/smlreader architecture

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

- Interactive diagram: https://gitdiagram.com/mruettgers/smlreader
- Repository: https://github.com/mruettgers/smlreader

## Overview

SMLReader is an ESP8266 smart-meter-to-MQTT gateway. Its principal workflow reads SML bytes from configured optical sensor inputs, detects and parses complete messages, then publishes meter values as MQTT topics. The firmware also provides Wi-Fi and MQTT configuration through a web interface, an HTTP update endpoint, and optional serial diagnostics. The graph follows the sampled runtime code and README; external library internals and unsampled configuration behavior are not expanded.

Main entry points: [`src/main.cpp`](https://github.com/mruettgers/smlreader/blob/develop/src/main.cpp) (Firmware loop), [`src/Sensor.h`](https://github.com/mruettgers/smlreader/blob/develop/src/Sensor.h) (Sensor reader), [`src/MqttPublisher.h`](https://github.com/mruettgers/smlreader/blob/develop/src/MqttPublisher.h) (MQTT publisher), [`src/debug.h`](https://github.com/mruettgers/smlreader/blob/develop/src/debug.h) (Serial diagnostics)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_meter["Meter ingestion"]
  node_config["Sensor settings<br/>[config.h]"]
  node_sensor["Sensor reader<br/>[Sensor.h]"]
  node_handler["Message handler<br/>[main.cpp]"]
  node_sml["SML parser"]
  node_main["Firmware loop<br/>[main.cpp]"]
end

subgraph group_connectivity["Device connectivity"]
  node_web["Setup interface"]
  node_wifi["Wi-Fi network"]
  node_updater["HTTP updater"]
  node_publisher["MQTT publisher<br/>[MqttPublisher.h]"]
end

subgraph group_support["Runtime support"]
  node_debug["Serial diagnostics<br/>[debug.h]"]
  node_units["DLMS units<br/>[unit.h]"]
end

node_meter(("Optical meter"))
node_broker(("MQTT broker"))

node_meter -->|"sends bytes"| node_sensor
node_main -->|"reads settings"| node_config
node_main -->|"creates and loops"| node_sensor
node_sensor -->|"calls callback"| node_handler
node_handler -->|"parses message"| node_sml
node_handler -->|"publishes file"| node_publisher
node_main -->|"configures routes"| node_web
node_main -->|"initializes Wi-Fi"| node_wifi
node_main -->|"sets up updates"| node_updater
node_main -->|"connects on Wi-Fi"| node_publisher
node_publisher -->|"publishes MQTT"| node_broker
node_main -->|"logs runtime"| node_debug
node_sensor -->|"logs sensor state"| node_debug
node_debug -->|"formats unit labels"| node_units

click node_config "https://github.com/mruettgers/smlreader/blob/develop/src/config.h"
click node_sensor "https://github.com/mruettgers/smlreader/blob/develop/src/Sensor.h"
click node_handler "https://github.com/mruettgers/smlreader/blob/develop/src/main.cpp"
click node_main "https://github.com/mruettgers/smlreader/blob/develop/src/main.cpp"
click node_publisher "https://github.com/mruettgers/smlreader/blob/develop/src/MqttPublisher.h"
click node_debug "https://github.com/mruettgers/smlreader/blob/develop/src/debug.h"
click node_units "https://github.com/mruettgers/smlreader/blob/develop/src/unit.h"

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_config,node_sensor,node_handler,node_sml,node_main toneBlue
class node_web,node_wifi,node_updater,node_publisher toneAmber
class node_debug,node_units toneMint
class node_meter,node_broker toneIndigo
```

## Components

### Meter ingestion

- [Sensor settings](https://github.com/mruettgers/smlreader/blob/develop/src/config.h): `src/config.h`
- [Sensor reader](https://github.com/mruettgers/smlreader/blob/develop/src/Sensor.h): `src/Sensor.h`
- [Message handler](https://github.com/mruettgers/smlreader/blob/develop/src/main.cpp): `src/main.cpp`
- **SML parser**
- [Firmware loop](https://github.com/mruettgers/smlreader/blob/develop/src/main.cpp): `src/main.cpp`

### Device connectivity

- **Setup interface**
- **Wi-Fi network**
- **HTTP updater**
- [MQTT publisher](https://github.com/mruettgers/smlreader/blob/develop/src/MqttPublisher.h): `src/MqttPublisher.h`

### Runtime support

- [Serial diagnostics](https://github.com/mruettgers/smlreader/blob/develop/src/debug.h): `src/debug.h`
- [DLMS units](https://github.com/mruettgers/smlreader/blob/develop/src/unit.h): `src/unit.h`

### Other components

- **Optical meter**
- **MQTT broker**

## Connections

- Optical meter → Sensor reader: sends bytes (evidence: `README.md`)
- Firmware loop → Sensor settings: reads settings (evidence: `src/main.cpp`)
- Firmware loop → Sensor reader: creates and loops (evidence: `src/main.cpp`)
- Sensor reader → Message handler: calls callback (evidence: `src/Sensor.h`)
- Message handler → SML parser: parses message (evidence: `src/main.cpp`)
- Message handler → MQTT publisher: publishes file (evidence: `src/main.cpp`)
- Firmware loop → Setup interface: configures routes (evidence: `src/main.cpp`)
- Firmware loop → Wi-Fi network: initializes Wi-Fi (evidence: `src/main.cpp`)
- Firmware loop → HTTP updater: sets up updates (evidence: `src/main.cpp`)
- Firmware loop → MQTT publisher: connects on Wi-Fi (evidence: `src/main.cpp`)
- MQTT publisher → MQTT broker: publishes MQTT (evidence: `src/MqttPublisher.h`)
- Firmware loop → Serial diagnostics: logs runtime (evidence: `src/main.cpp`)
- Sensor reader → Serial diagnostics: logs sensor state (evidence: `src/Sensor.h`)
- Serial diagnostics → DLMS units: formats unit labels (evidence: `src/debug.h`)
