# amusarra/esp32-mqtt-publish-subscribe architecture

> Architecture diagram of the GitHub repository amusarra/esp32-mqtt-publish-subscribe, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amusarra/esp32-mqtt-publish-subscribe
- Repository: https://github.com/amusarra/esp32-mqtt-publish-subscribe

## Overview

This repository provides ESP32 firmware for an IoT environmental-monitoring and relay-control device. Its main runtime flow reads BME280 measurements and relay state, publishes telemetry over MQTT, and receives MQTT commands to operate relays and report their state. The README also describes a broker, dashboard/mobile subscribers, and a gateway LCD as parts of the broader solution; their implementation is not present in this source tree. Edges reflect only documented behavior or calls visible in the firmware excerpt.

Main entry points: [`src/esp32_mqtt_publish_subscribe.cpp`](https://github.com/amusarra/esp32-mqtt-publish-subscribe/blob/master/src/esp32_mqtt_publish_subscribe.cpp) (Device runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_device["ESP32 firmware"]
  node_firmware["Device runtime"]
end

subgraph group_environment["IoT environment"]
  node_sensor["BME280 sensor"]
  node_relay["Relay module"]
  node_broker["MQTT broker"]
  node_gateway["Gateway LCD"]
end

node_user(("Dashboard / phone"))

node_firmware -->|"reads via I2C"| node_sensor
node_firmware -->|"drives GPIO"| node_relay
node_firmware -->|"publishes telemetry"| node_broker
node_broker -->|"dispatches telemetry"| node_user
node_user -->|"publishes commands"| node_broker
node_broker -->|"delivers commands"| node_firmware
node_firmware -->|"publishes relay status"| node_broker
node_gateway -.->|"subscribes to data"| node_broker

click node_firmware "https://github.com/amusarra/esp32-mqtt-publish-subscribe/blob/master/src/esp32_mqtt_publish_subscribe.cpp"

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_firmware toneBlue
class node_sensor,node_relay,node_broker,node_gateway toneAmber
class node_user toneIndigo
```

## Components

### ESP32 firmware

- [Device runtime](https://github.com/amusarra/esp32-mqtt-publish-subscribe/blob/master/src/esp32_mqtt_publish_subscribe.cpp): `src/esp32_mqtt_publish_subscribe.cpp`

### IoT environment

- **BME280 sensor**
- **Relay module**
- **MQTT broker**
- **Gateway LCD**

### Other components

- **Dashboard / phone**

## Connections

- Device runtime → BME280 sensor: reads via I2C (evidence: `src/esp32_mqtt_publish_subscribe.cpp`)
- Device runtime → Relay module: drives GPIO (evidence: `src/esp32_mqtt_publish_subscribe.cpp`)
- Device runtime → MQTT broker: publishes telemetry (evidence: `README.markdown`)
- MQTT broker → Dashboard / phone: dispatches telemetry (evidence: `README.markdown`)
- Dashboard / phone → MQTT broker: publishes commands (evidence: `README.markdown`)
- MQTT broker → Device runtime: delivers commands (evidence: `README.markdown`)
- Device runtime → MQTT broker: publishes relay status (evidence: `src/esp32_mqtt_publish_subscribe.cpp`)
- Gateway LCD → MQTT broker: subscribes to data (evidence: `README.markdown`)
