diff --git a/libnymea-app-core/connection/awsclient.cpp b/libnymea-app-core/connection/awsclient.cpp index e07a0e11..27b38c49 100644 --- a/libnymea-app-core/connection/awsclient.cpp +++ b/libnymea-app-core/connection/awsclient.cpp @@ -690,7 +690,7 @@ void AWSClient::getCredentialsForIdentity(const QString &identityId) if (qc.method == "fetchDevices") { fetchDevices(); } else if (qc.method == "postToMQTT") { - postToMQTT(qc.boxId, qc.callback); + postToMQTT(qc.boxId, qc.timestamp, qc.callback); } } }); @@ -701,7 +701,7 @@ bool AWSClient::tokensExpired() const return (m_accessTokenExpiry.addSecs(-10) < QDateTime::currentDateTime()) || (m_sessionTokenExpiry.addSecs(-10) < QDateTime::currentDateTime()); } -bool AWSClient::postToMQTT(const QString &boxId, std::function callback) +bool AWSClient::postToMQTT(const QString &boxId, const QString ×tamp, std::function callback) { if (!isLoggedIn()) { qWarning() << "Cannot post to MQTT. Not logged in to AWS"; @@ -710,7 +710,7 @@ bool AWSClient::postToMQTT(const QString &boxId, std::function callb if (tokensExpired()) { qDebug() << "Cannot post to MQTT. Need to refresh the tokens first"; refreshAccessToken(); - m_callQueue.append(QueuedCall("postToMQTT", boxId, callback)); + m_callQueue.append(QueuedCall("postToMQTT", boxId, timestamp, callback)); return true; // So far it looks we're doing ok... let's return true } QString topic = QString("%1/%2/proxy").arg(boxId).arg(QString(m_identityId)); @@ -726,7 +726,7 @@ bool AWSClient::postToMQTT(const QString &boxId, std::function callb QVariantMap params; params.insert("token", m_idToken); - params.insert("timestamp", QDateTime::currentDateTime().toSecsSinceEpoch()); + params.insert("timestamp", timestamp); QByteArray payload = QJsonDocument::fromVariant(params).toJson(QJsonDocument::Compact); diff --git a/libnymea-app-core/connection/awsclient.h b/libnymea-app-core/connection/awsclient.h index 8d970043..37d29680 100644 --- a/libnymea-app-core/connection/awsclient.h +++ b/libnymea-app-core/connection/awsclient.h @@ -109,7 +109,7 @@ public: Q_INVOKABLE void fetchDevices(); - Q_INVOKABLE bool postToMQTT(const QString &boxId, std::function callback); + Q_INVOKABLE bool postToMQTT(const QString &boxId, const QString ×tamp, std::function callback); Q_INVOKABLE void getId(); bool tokensExpired() const; @@ -165,9 +165,10 @@ private: public: QueuedCall(const QString &method): method(method) { } QueuedCall(const QString &method, const QString &boxId): method(method), boxId(boxId) { } - QueuedCall(const QString &method, const QString &boxId, std::function callback): method(method), boxId(boxId), callback(callback) {} + QueuedCall(const QString &method, const QString &boxId, const QString ×tamp, std::function callback): method(method), boxId(boxId), timestamp(timestamp), callback(callback) {} QString method; QString boxId; + QString timestamp; std::function callback; }; diff --git a/libnymea-app-core/connection/cloudtransport.cpp b/libnymea-app-core/connection/cloudtransport.cpp index 06666a51..9cdd971d 100644 --- a/libnymea-app-core/connection/cloudtransport.cpp +++ b/libnymea-app-core/connection/cloudtransport.cpp @@ -29,7 +29,7 @@ CloudTransport::CloudTransport(AWSClient *awsClient, QObject *parent): QObject::connect(m_remoteproxyConnection, &RemoteProxyConnection::ready, this,[this]() { qDebug() << "Proxy ready. Authenticating channel."; - m_remoteproxyConnection->authenticate(m_awsClient->idToken()); + m_remoteproxyConnection->authenticate(m_awsClient->idToken(), QString::number(m_timestamp.toMSecsSinceEpoch())); }); QObject::connect(m_remoteproxyConnection, &RemoteProxyConnection::dataReady, this, [this](const QByteArray &data) { emit dataReady(data); @@ -55,7 +55,8 @@ bool CloudTransport::connect(const QUrl &url) qDebug() << "Connecting to" << url; - bool postResult = m_awsClient->postToMQTT(url.host(), [this](bool success) { + m_timestamp = QDateTime::currentDateTime(); + bool postResult = m_awsClient->postToMQTT(url.host(), QString::number(m_timestamp.toMSecsSinceEpoch()), [this](bool success) { if (success) { m_remoteproxyConnection->connectServer(QUrl("wss://remoteproxy.nymea.io")); diff --git a/libnymea-app-core/connection/cloudtransport.h b/libnymea-app-core/connection/cloudtransport.h index 196a4afe..9fb9b0d5 100644 --- a/libnymea-app-core/connection/cloudtransport.h +++ b/libnymea-app-core/connection/cloudtransport.h @@ -27,6 +27,7 @@ public: private: AWSClient *m_awsClient = nullptr; remoteproxyclient::RemoteProxyConnection *m_remoteproxyConnection = nullptr; + QDateTime m_timestamp; }; #endif // CLOUDTRANSPORT_H diff --git a/nymea-remoteproxy b/nymea-remoteproxy index 3b97bc60..eacffb69 160000 --- a/nymea-remoteproxy +++ b/nymea-remoteproxy @@ -1 +1 @@ -Subproject commit 3b97bc60bbaf1ae5d4ced7eb1586d2d20fe5b0ab +Subproject commit eacffb695f8870c75b027a701277f6ec4455d327