diff --git a/mqtt.cpp b/mqtt.cpp index 98eefc83683981c37158a7b42b3840d077e47675..08fe67ceb51960f3825b22049958c9ef049d1fd0 100644 --- a/mqtt.cpp +++ b/mqtt.cpp @@ -22,6 +22,7 @@ PubSubClient mqttClient(espClient); namespace mqtt { unsigned long last_sent_at = 0; unsigned long last_failed_at = 0; + bool connected = false; String publish_topic; const char *json_sensor_format; @@ -191,8 +192,9 @@ namespace mqtt { mqttClient.connect(publish_topic.c_str(), config::mqtt_user, config::mqtt_password); LedEffects::onBoardLEDOff(); - if (mqttClient.connected()) { - //TODO: Send local IP? + connected = mqttClient.connected(); + + if (connected) { if (config::allow_mqtt_commands) { char control_topic[60]; // Should be enough for "CO2sensors/ESPd03cc5/control" snprintf(control_topic, sizeof(control_topic), "%s/control", publish_topic.c_str()); diff --git a/mqtt.h b/mqtt.h index 8b520cc9459c2ec0fc4f7aa4cf9a45cee28c7067..2899a9996bbf8d2a484f5fc79b619d9647ee70a7 100644 --- a/mqtt.h +++ b/mqtt.h @@ -15,6 +15,7 @@ namespace config { } namespace mqtt { extern String last_successful_publish; + extern bool connected; void initialize(String &topic); void keepConnection(); void publishIfTimeHasCome(const String &timeStamp, const int16_t &co2, const float &temp, const float &hum); diff --git a/web_server.cpp b/web_server.cpp index 2fc77303bd8a90d0147e4df3ab7dd4781a63a2d8..7501263d6abebc3c0849726ecf65eb1cce6f28c9 100644 --- a/web_server.cpp +++ b/web_server.cpp @@ -95,7 +95,7 @@ namespace web_server { #endif #ifdef AMPEL_MQTT "<tr><th colspan='2'>MQTT</th></tr>\n" - //TODO: Add connected? + "<tr><td>Connected?</td><td>%s</td></tr>\n" "<tr><td>Last publish</td><td>%s</td></tr>\n" "<tr><td>Timestep</td><td>%5d s</td></tr>\n" #endif @@ -225,7 +225,7 @@ namespace web_server { csv_writer::last_successful_write.c_str(), config::csv_interval, csv_writer::getAvailableSpace() / 1024, #endif #ifdef AMPEL_MQTT - mqtt::last_successful_publish.c_str(), config::sending_interval, + mqtt::connected ? "Yes" : "No", mqtt::last_successful_publish.c_str(), config::sending_interval, #endif #if defined(AMPEL_LORAWAN) && defined(ESP32) lorawan::connected ? "Yes" : "No", LMIC_FREQUENCY_PLAN, lorawan::last_transmission.c_str(),