Merge PR #173: Menekes: Reconnect AmtronECU in case of dead Modbus TCP connection

pull/174/head
jenkins 2024-05-14 15:04:08 +02:00
commit d96720cb08
1 changed files with 9 additions and 1 deletions

View File

@ -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();
}
}
});