fixed log on TCP reconnection

This commit is contained in:
Emanuele Trabattoni
2025-08-29 22:18:49 +02:00
parent cde86a7f99
commit 4aeffc76b0

View File

@@ -37,6 +37,7 @@ void loop()
uint8_t sensors(0);
bool buzzing(false);
NetworkClient logStream;
LOG_ATTACH_STREAM(logStream);
//////////////// DEVICES ////////////////
// Declared here to keep devices local to the main loop otherwise the kernel crashes //
@@ -148,7 +149,6 @@ void loop()
time_t ntpTime;
uint8_t timeRetries(0);
uint8_t mqttRetries(0);
uint8_t logStreamRetries(0);
while (timeRetries++ < conf.m_ntpRetries)
{
eth.setNtpTimeOffset(conf.m_ntpTimezone);
@@ -176,14 +176,6 @@ void loop()
}
delay(250);
}
while (logStreamRetries++ < conf.m_mqttRetries)
{
if (logStream.connect(conf.m_mqttHost.c_str(), 9876))
{
LOG_ATTACH_STREAM(logStream);
break;
}
}
});
////////////////////////////////////////
@@ -194,6 +186,16 @@ void loop()
{
const uint32_t start(millis());
drivers::PCF85063::datetime_t datetime;
if (!logStream.connected())
{
logStream.stop();
logStream.clearWriteError();
logStream.setConnectionTimeout(100);
logStream.connect(conf.m_mqttHost.c_str(), 9876);
LOG_WARN("TCP LogStream Connected");
}
rtc.readDatetime(datetime);
const std::string timeStr(drivers::PCF85063::datetime2str(datetime));
LOG_INFO("[", k++, "] Loop - Current Datetime UTC", timeStr.c_str());