diff --git a/DeviceScreen.qml b/DeviceScreen.qml index 6c471c0..370dec1 100644 --- a/DeviceScreen.qml +++ b/DeviceScreen.qml @@ -28,6 +28,8 @@ Loader { DeviceConnection { id: theDeviceConnection + Component.onCompleted: start() + settings: theSettings onLogMessage: (message) => collectedMessages.push(message) diff --git a/deviceconnection.cpp b/deviceconnection.cpp index f0ad4fe..43e2152 100644 --- a/deviceconnection.cpp +++ b/deviceconnection.cpp @@ -9,11 +9,14 @@ #include #include #include +#include #include #include "msgpack.h" +using namespace std::chrono_literals; + namespace { template auto enumToString(const QEnum value) @@ -58,7 +61,10 @@ void DeviceConnection::setUrl(const QString &url) return; emit urlChanged(m_url = url); +} +void DeviceConnection::start() +{ emit logMessage(tr("Connecting to %0").arg(m_url)); if (m_settings && !m_settings->solalawebKey().isEmpty() && !m_settings->solalawebCert().isEmpty()) @@ -91,7 +97,6 @@ void DeviceConnection::setUrl(const QString &url) } after: - m_websocket.open(QUrl{m_url}); } @@ -451,18 +456,24 @@ void DeviceConnection::sendAuth(const QString &password) void DeviceConnection::connected() { + qDebug() << "called"; emit logMessage(tr("Connected!")); } void DeviceConnection::disconnected() { + qDebug() << "called"; emit logMessage(tr("Disconnected!")); + emit logMessage(tr("Reconnecting to %0").arg(m_url)); - m_websocket.open(QUrl{m_url}); + QTimer::singleShot(1s, this, [this](){ + m_websocket.open(QUrl{m_url}); + }); } void DeviceConnection::stateChanged(QAbstractSocket::SocketState state) { + qDebug() << state; emit logMessage(tr("state changed: %0").arg(enumToString(state))); } @@ -496,16 +507,19 @@ void DeviceConnection::binaryMessageReceived(QByteArray message) void DeviceConnection::errorOccurred(QAbstractSocket::SocketError error) { + qDebug() << error; emit logMessage(tr("error occured: %0").arg(enumToString(error))); } void DeviceConnection::peerVerifyError(const QSslError &error) { + qDebug() << error; emit logMessage(tr("ssl peer verify error")); } void DeviceConnection::sslErrors(const QList &errors) { + qDebug() << errors; emit logMessage(tr("ssl errors")); } @@ -516,16 +530,19 @@ void DeviceConnection::sslErrors(const QList &errors) void DeviceConnection::alertSent(QSsl::AlertLevel level, QSsl::AlertType type, const QString &description) { + qDebug() << level << type << description; emit logMessage(tr("ssl alert sent level=%0 type=%1 description=%2").arg(enumToString(level)).arg(enumToString(type)).arg(description)); } void DeviceConnection::alertReceived(QSsl::AlertLevel level, QSsl::AlertType type, const QString &description) { + qDebug() << level << type << description; emit logMessage(tr("ssl alert received level=%0 type=%1 description=%2").arg(enumToString(level)).arg(enumToString(type)).arg(description)); } void DeviceConnection::handshakeInterruptedOnError(const QSslError &error) { + qDebug() << error; emit logMessage(tr("ssl handshake interrupted on error")); } diff --git a/deviceconnection.h b/deviceconnection.h index e6c7d3c..80580ce 100644 --- a/deviceconnection.h +++ b/deviceconnection.h @@ -29,6 +29,8 @@ public: QString url() const { return m_url; } void setUrl(const QString &url); + Q_INVOKABLE void start(); + QString password() const { return m_password; } void setPassword(const QString &password);