From 0a06dc565c222202e3704e6fbf26d3eafad007b5 Mon Sep 17 00:00:00 2001 From: trinnes Date: Sun, 12 May 2024 11:35:38 +0200 Subject: [PATCH] Sungrow: Improve connection stability --- sungrow/integrationpluginsungrow.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/sungrow/integrationpluginsungrow.cpp b/sungrow/integrationpluginsungrow.cpp index 7747067..5fe2cb1 100644 --- a/sungrow/integrationpluginsungrow.cpp +++ b/sungrow/integrationpluginsungrow.cpp @@ -318,13 +318,24 @@ void IntegrationPluginSungrow::postSetupThing(Thing *thing) qCDebug(dcSungrow()) << "Starting plugin timer..."; m_refreshTimer = hardwareManager()->pluginTimerManager()->registerTimer(2); connect(m_refreshTimer, &PluginTimer::timeout, this, [this] { - foreach(SungrowModbusTcpConnection *connection, m_tcpConnections) { + foreach(auto thing, myThings().filterByThingClassId(sungrowInverterTcpThingClassId)) { + auto monitor = m_monitors.value(thing); + if (!monitor->reachable()) { + continue; + } + + auto connection = m_tcpConnections.value(thing); if (connection->initializing()) { qCDebug(dcSungrow()) << "Skip updating" << connection->modbusTcpMaster() << "since the connection is still initializing."; continue; } - qCDebug(dcSungrow()) << "Updating connection" << connection->modbusTcpMaster()->hostAddress().toString(); - connection->update(); + if (connection->reachable()) { + qCDebug(dcSungrow()) << "Updating connection" << connection->modbusTcpMaster()->hostAddress().toString(); + connection->update(); + } else { + qCDebug(dcSungrow()) << "Device not reachable. Probably a TCP connection error. Reconnecting TCP socket"; + connection->reconnectDevice(); + } } }); m_refreshTimer->start();