This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void MainWindow::sendHeartbeat() { | |
QJsonObject heartbeatMessage; | |
heartbeatMessage["type"] = "heartbeat"; | |
heartbeatMessage["timestamp"] = QDateTime::currentSecsSinceEpoch(); // Unix timestamp | |
QJsonDocument doc(heartbeatMessage); | |
QString jsonString = doc.toJson(QJsonDocument::Compact); | |
if (m_connected) { | |
m_webSocket->sendTextMessage(jsonString); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void MainWindow::loop(){ | |
//Verificar si el websocket esta abierto | |
if(m_connected == false){ | |
m_webSocket->open(QUrl("ws://192.168.0.105/ws")); // Reemplaza <ESP32_IP> con la IP de tu ESP32 | |
m_connected = true; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QTimer *cronos = new QTimer(this); | |
cronos->start(1000); | |
connect(cronos, SIGNAL(timeout()),this, SLOT(loop())); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void MainWindow::loop(){ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m_webSocket = new QWebSocket(); | |
m_connected = false; | |
// Conectar WebSocket | |
connect(m_webSocket, &QWebSocket::connected, this, &MainWindow::onConnected); | |
connect(m_webSocket, &QWebSocket::disconnected, this, &MainWindow::onDisconnected); | |
connect(m_webSocket, &QWebSocket::textMessageReceived, this, &MainWindow::onTextMessageReceived); | |
connect(m_webSocket, &QWebSocket::errorOccurred, this, &MainWindow::onError); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void MainWindow::sendHeartbeat() { | |
QJsonObject heartbeatMessage; | |
heartbeatMessage["type"] = "heartbeat"; | |
heartbeatMessage["timestamp"] = QDateTime::currentSecsSinceEpoch(); // Unix timestamp | |
QJsonDocument doc(heartbeatMessage); | |
QString jsonString = doc.toJson(QJsonDocument::Compact); | |
if (m_connected) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private: | |
Ui::MainWindow *ui; | |
QWebSocket *m_webSocket; // Puntero al WebSocket | |
bool m_connected; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private slots: | |
void onConnected(); | |
void onTextMessageReceived(const QString &message); | |
void onDisconnected(); | |
void onError(QAbstractSocket::SocketError error); | |
void sendHeartbeat(); | |
void connectWebSocket(const QUrl &url); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QWebSocket> | |
#include <QDebug> | |
#include <QJsonObject> | |
#include <QJsonDocument> | |
#include <QTimer> | |
#include <QDateTime> | |
#include <QChartView> | |
#include <QLineSeries> | |
#include <QTimer> | |
#include <QList> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QT += core gui network websockets charts widgets | |
// |
NewerOlder