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::manejarPuertosSeriales(QComboBox *comboBox, int baud) | |
| { | |
| if (!comboBox) { | |
| qWarning() << "Debes pasar un QComboBox válido."; | |
| return; | |
| } | |
| // --- Poblar puertos --- | |
| auto poblarPuertos = [comboBox]() { |
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
| manejarPuertosSeriales(ui->comboBox,115200); |
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
| ui->displayHumedad->setDigitCount(5); // p.ej. "65.8" | |
| ui->displayHumedad->setSegmentStyle(QLCDNumber::Flat); |
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
| // --- Configuración de los displays --- | |
| ui->displayTemperatura->setDigitCount(5); // p.ej. "25.5" | |
| ui->displayTemperatura->setSegmentStyle(QLCDNumber::Flat); |
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
| ui->lineEdit->setPlaceholderText( | |
| R"({"sensor":"dht22","pin":4})" | |
| ); |
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::on_pushButton_clicked() | |
| { | |
| if (!serialActual || !serialActual->isOpen()) { | |
| QMessageBox::warning(this, "Error", "No hay ningún puerto abierto."); | |
| return; | |
| } | |
| // Tomar el texto escrito por el usuario (ej: {"sensor":"dht22","pin":4}) | |
| QString jsonStr = ui->lineEdit->text().trimmed(); | |
| if (jsonStr.isEmpty()) { |
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::onSerialLineaRecibida(const QString &linea) | |
| { | |
| // Ejemplo de respuesta: {"ok":true,"temp":25.5,"humedad":65.8} | |
| const QByteArray bytes = linea.toUtf8(); | |
| QJsonParseError perr; | |
| const QJsonDocument doc = QJsonDocument::fromJson(bytes, &perr); | |
| if (perr.error != QJsonParseError::NoError || !doc.isObject()) { | |
| qWarning() << "JSON inválido:" << perr.errorString() << "en" << linea; | |
| return; | |
| } |
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())); |
NewerOlder