Skip to content

feat: MQTT client connectivity - #12

Merged
JMTamayo merged 3 commits into
mainfrom
feat/mqtt-client
Jun 21, 2026
Merged

feat: MQTT client connectivity#12
JMTamayo merged 3 commits into
mainfrom
feat/mqtt-client

Conversation

@JMTamayo

Copy link
Copy Markdown
Owner

Summary

Adds connectivity/mqtt: an MQTT client that connects to the broker using the provisioned settings (IMqttConfig: host/port/user/password) with client_id = device_id (IDeviceConfig), and exposes publish/subscribe primitives for the future app logic. Same hexagonal structure as connectivity/wifi and connectivity/provisioning.

  • Port IMqttClient (domain) + Status, Message{topic,payload}, StatusHandler/MessageHandler, ClientConfig.
  • MqttService (application) — reads broker settings + device id, builds mqtt://host:port, connects; thin pass-throughs for publish/subscribe/stop. Missing host or device id → logs and returns without crashing. Port defaults to 1883 when unset.
  • EspMqttClient (infrastructure) — esp-mqtt adapter. Event-driven (MQTT_EVENT_*), non-blocking, relies on esp-mqtt's built-in auto-reconnect. Maps MQTT_EVENT_DATA to the message callback.
  • Mqtt (facade) — start() / stop() / publish() / subscribe() / isConnected() / onStatusChange() / onMessage(); wired in main to start after Wi-Fi.

Design decisions: transport-only (connect + pub/sub + status; topic/command logic deferred to the future orchestrator), plaintext mqtt://, independent start with esp-mqtt auto-reconnect.

Notes

  • Retained "last value" / state on reconnect: supported via the standard flow — re-subscribe from the Connected status callback and the broker re-delivers the retained last value to onMessage. esp-mqtt does not auto-resubscribe, so re-subscription belongs in the consumer/App.
  • No TLS in this MVP (plaintext); the inbound retained flag is not surfaced on Message (can be added later).
  • Also ignores local .env files in .gitignore.

Build

  • Adds the mqtt component to REQUIRES. Flash ~38.8% of the 3 MB partition, RAM ~11.8%.

Verification

  • make -C firmware builds cleanly.
  • On hardware: provision Wi-Fi + MQTT + device_id, reboot, watch connectivity/mqtt reach Connected; the broker shows a client with client_id = device_id; publish/subscribe round-trip; drop the broker and confirm auto-reconnect.

JMTamayo added 3 commits June 20, 2026 21:56
Add the mqtt component to the app component requirements for the MQTT client
module.
Add connectivity/mqtt following the hexagonal structure: the IMqttClient port,
MqttService (reads broker settings from IMqttConfig and the client id from
IDeviceConfig, with client_id = device_id), the esp-mqtt adapter and the Mqtt
facade. Connects asynchronously over plaintext mqtt://, exposes publish/subscribe
and a message callback, reports connection status and relies on esp-mqtt
auto-reconnect. Wire it in main to start after Wi-Fi.
@JMTamayo
JMTamayo merged commit 1b69d18 into main Jun 21, 2026
2 checks passed
@JMTamayo
JMTamayo deleted the feat/mqtt-client branch June 21, 2026 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant