Skip to content

Commit

Permalink
added time
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrwang committed Jan 12, 2025
1 parent 6fb2101 commit 0e2fbde
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions NERODevelopment/src/models/mqtt_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QtCore/QDateTime>
#include <QtMqtt/QMqttClient>
#include <QtWidgets/QMessageBox>
#include <chrono>
#include <serverdata.qpb.h>

MqttClient::MqttClient(QObject *parent) : QObject(parent) {
Expand Down Expand Up @@ -89,6 +90,14 @@ void MqttClient::sendMessage(const QString topic, const float value) {
serverdata::v2::ServerData serverData;
serverData.setUnit("");
serverData.setValues({value});

auto now = std::chrono::system_clock::now();
auto microseconds = std::chrono::duration_cast<std::chrono::microseconds>(
now.time_since_epoch())
.count();
QtProtobuf::uint64 timeUs = static_cast<QtProtobuf::uint64>(microseconds);

serverData.setTimeUs(timeUs);
QByteArray data = serverData.serialize(&this->m_serializer);
m_client->publish("NERO/" + topic, data);
}

0 comments on commit 0e2fbde

Please sign in to comment.