add comments
This commit is contained in:
@@ -22,6 +22,11 @@ MyMqttClient::MyMqttClient()
|
|||||||
mqttClient.setKeepAlive(300);
|
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()
|
bool MyMqttClient::ensureConnected()
|
||||||
{
|
{
|
||||||
if (mqttClient.connected())
|
if (mqttClient.connected())
|
||||||
@@ -67,6 +72,10 @@ bool MyMqttClient::ensureConnected()
|
|||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Publishes a window open/close event to MQTT_TOPIC_FENSTER.
|
||||||
|
* Payload: {"fenster":"<name>","event":"open"|"close"}
|
||||||
|
*/
|
||||||
void MyMqttClient::publishFensterEvent(const char* name, bool bOpen)
|
void MyMqttClient::publishFensterEvent(const char* name, bool bOpen)
|
||||||
{
|
{
|
||||||
if (!ensureConnected())
|
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)
|
void MyMqttClient::publishStatus(const char* payload)
|
||||||
{
|
{
|
||||||
if (!ensureConnected())
|
if (!ensureConnected())
|
||||||
@@ -98,6 +110,10 @@ void MyMqttClient::publishStatus(const char* payload)
|
|||||||
mqttClient.publish(MQTT_TOPIC_STATUS, 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()
|
void MyMqttClient::onLoop()
|
||||||
{
|
{
|
||||||
if (!WiFi.isConnected())
|
if (!WiFi.isConnected())
|
||||||
|
|||||||
Reference in New Issue
Block a user