From ed0f9d439d6702b1563a6bf8f5d739542f1f1ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Mon, 13 May 2024 11:47:41 +0200 Subject: [PATCH] Menekes: Reconnect AmtronECU in case of dead Modbus TCP connection --- mennekes/integrationpluginmennekes.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mennekes/integrationpluginmennekes.cpp b/mennekes/integrationpluginmennekes.cpp index 51d6d12..798472c 100644 --- a/mennekes/integrationpluginmennekes.cpp +++ b/mennekes/integrationpluginmennekes.cpp @@ -564,12 +564,20 @@ void IntegrationPluginMennekes::setupAmtronECUConnection(ThingSetupInfo *info) } }); - connect(amtronECUConnection, &AmtronECU::reachableChanged, thing, [thing, amtronECUConnection](bool reachable){ + connect(amtronECUConnection, &AmtronECU::reachableChanged, thing, [thing, amtronECUConnection, monitor](bool reachable){ qCDebug(dcMennekes()) << "Reachable changed to" << reachable << "for" << thing; if (reachable) { amtronECUConnection->initialize(); } else { thing->setStateValue(amtronECUConnectedStateTypeId, false); + + // Note: sometimes the device does not repond any more on requests, but the connection is still + // up and a reconnect fixes this behavior. Let us try to reconnect in case the TCP connection is up + // or the monitor is reachable + if (amtronECUConnection->modbusTcpMaster()->connected() || monitor->reachable()) { + qCWarning(dcMennekes()) << "The amtron ECU connection is not reachable any more, but the device seems to be still reachable. Trying to reconnect..."; + amtronECUConnection->modbusTcpMaster()->reconnectDevice(); + } } });