diff --git a/src/MyMqttClient.cpp b/src/MyMqttClient.cpp index d00747c..140ac01 100644 --- a/src/MyMqttClient.cpp +++ b/src/MyMqttClient.cpp @@ -22,6 +22,11 @@ MyMqttClient::MyMqttClient() mqttClient.setKeepAlive(300); } +/** + * Ensures the MQTT broker connection is established. + * Attempts reconnection at most once every MQTT_RECONNECT_INTERVAL_MS. + * Returns true if connected and ready to publish. + */ bool MyMqttClient::ensureConnected() { if (mqttClient.connected()) @@ -67,6 +72,10 @@ bool MyMqttClient::ensureConnected() return ok; } +/** + * Publishes a window open/close event to MQTT_TOPIC_FENSTER. + * Payload: {"fenster":"","event":"open"|"close"} + */ void MyMqttClient::publishFensterEvent(const char* name, bool bOpen) { if (!ensureConnected()) @@ -89,6 +98,9 @@ void MyMqttClient::publishFensterEvent(const char* name, bool bOpen) } } +/** + * Publishes an arbitrary status payload to MQTT_TOPIC_STATUS. + */ void MyMqttClient::publishStatus(const char* payload) { if (!ensureConnected()) @@ -98,6 +110,10 @@ void MyMqttClient::publishStatus(const char* payload) mqttClient.publish(MQTT_TOPIC_STATUS, payload); } +/** + * Main loop handler. Reconnects WiFi if lost, maintains the MQTT connection, + * and publishes the WiFi RSSI periodically. Call from the main loop. + */ void MyMqttClient::onLoop() { if (!WiFi.isConnected())