This commit is contained in:
Siwat Sirichai 2023-12-31 20:49:22 +07:00
parent 14767df9ec
commit 9cd5b7132b
2 changed files with 20 additions and 1 deletions

View File

@ -454,7 +454,8 @@ MqttConfig *ESPMegaIoT::getMqttConfig()
bool ESPMegaIoT::mqttConnected() bool ESPMegaIoT::mqttConnected()
{ {
return mqtt_connected; //return mqtt_connected;
return mqtt.connected();
} }
bool ESPMegaIoT::networkConnected() bool ESPMegaIoT::networkConnected()

View File

@ -4,6 +4,7 @@
#include <ClimateCard.hpp> #include <ClimateCard.hpp>
// #define FRAM_DEBUG // #define FRAM_DEBUG
#define MQTT_DEBUG
// Demo PLC firmware using the ESPMegaPRO OOP library // Demo PLC firmware using the ESPMegaPRO OOP library
@ -122,4 +123,21 @@ void loop()
espmega.dumpFRAMtoSerialASCII(0, 500); espmega.dumpFRAMtoSerialASCII(0, 500);
} }
#endif #endif
// Every 5 seconds, publish "I'm alive" to MQTT
#ifdef MQTT_DEBUG
static uint32_t last_mqtt_publish = 0;
if (millis() - last_mqtt_publish >= 5000)
{
last_mqtt_publish = millis();
espmega.iot->publishToTopic("/espmegai/alive", "true");
}
static uint32_t last_mqtt_status = 0;
if (millis() - last_mqtt_status >= 1000)
{
last_mqtt_status = millis();
Serial.print("MQTT Status: ");
Serial.println(espmega.iot->mqttConnected() ? "Connected" : "Disconnected");
}
#endif
} }