diff --git a/src/openhab.cpp b/src/openhab.cpp index 771750c..e0c7dba 100755 --- a/src/openhab.cpp +++ b/src/openhab.cpp @@ -2,6 +2,7 @@ * * Copyright (C) 2019 Christian Riedl * Copyright (C) 2020 Andreas Mroß + * Copyright (C) 2020 Michael Löcher * * This file is part of the YIO-Remote software project. * @@ -29,6 +30,7 @@ #include #include #include +#include #include "openhab_channelmappings.h" #include "yio-interface/entities/blindinterface.h" @@ -186,12 +188,20 @@ void OpenHAB::connect() { _myEntities = m_entities->getByIntegration(integrationId()); - getItems(true); + _tries = 0; _userDisconnect = false; _wasDisconnected = false; _standby = false; + if (QProcess::execute("curl", QStringList() << "-s" << _url) == 0) { + startSse(); + _pollingTimer.start(); + getItems(true); + setState(CONNECTED); + } else { + qCDebug(m_logCategory) << "openhab not reachable"; + } } void OpenHAB::disconnect() { @@ -213,15 +223,22 @@ void OpenHAB::enterStandby() { if (_sseReply->isRunning()) { _sseReply->abort(); } - _pollingTimer.start(); + if (QProcess::execute("curl", QStringList() << "-s" << _url) == 0) { + _pollingTimer.start(); + } else { + qCDebug(m_logCategory) << "openhab not reachable"; + } } void OpenHAB::leaveStandby() { _standby = false; - - _pollingTimer.stop(); - startSse(); - getItems(false); + if (QProcess::execute("curl", QStringList() << "-s" << _url) == 0) { + // _pollingTimer.stop(); + startSse(); + getItems(false); + } else { + qCDebug(m_logCategory) << "openhab not reachable"; + } } void OpenHAB::jsonError(const QString& error) { @@ -229,7 +246,11 @@ void OpenHAB::jsonError(const QString& error) { } void OpenHAB::onPollingTimer() { - getItems(false); + if (QProcess::execute("curl", QStringList() << "-s" << _url) == 0) { + getItems(false); + } else { + qCDebug(m_logCategory) << "openhab not reachable"; + } } void OpenHAB::onNetWorkAccessible(QNetworkAccessManager::NetworkAccessibility accessibility) { @@ -255,7 +276,6 @@ void OpenHAB::getItems(bool first) { // called during connect setState(CONNECTED); // connect to the SSE source - startSse(); } processItems(doc, first); }); diff --git a/src/openhab.h b/src/openhab.h index b6155a6..5d74aa9 100755 --- a/src/openhab.h +++ b/src/openhab.h @@ -2,6 +2,7 @@ * * Copyright (C) 2019 Christian Riedl * Copyright (C) 2020 Andreas Mroß + * Copyright (C) 2020 Michael Löcher * * This file is part of the YIO-Remote software project. *