Sungrow: Improve connection stability
parent
6bd514f44e
commit
0a06dc565c
|
|
@ -318,13 +318,24 @@ void IntegrationPluginSungrow::postSetupThing(Thing *thing)
|
||||||
qCDebug(dcSungrow()) << "Starting plugin timer...";
|
qCDebug(dcSungrow()) << "Starting plugin timer...";
|
||||||
m_refreshTimer = hardwareManager()->pluginTimerManager()->registerTimer(2);
|
m_refreshTimer = hardwareManager()->pluginTimerManager()->registerTimer(2);
|
||||||
connect(m_refreshTimer, &PluginTimer::timeout, this, [this] {
|
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()) {
|
if (connection->initializing()) {
|
||||||
qCDebug(dcSungrow()) << "Skip updating" << connection->modbusTcpMaster() << "since the connection is still initializing.";
|
qCDebug(dcSungrow()) << "Skip updating" << connection->modbusTcpMaster() << "since the connection is still initializing.";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
qCDebug(dcSungrow()) << "Updating connection" << connection->modbusTcpMaster()->hostAddress().toString();
|
if (connection->reachable()) {
|
||||||
connection->update();
|
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();
|
m_refreshTimer->start();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue