diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/Client.cpp | 8 | ||||
-rw-r--r-- | client/HandleMessage.cpp | 28 | ||||
-rw-r--r-- | client/dbconnector.cpp | 8 | ||||
-rw-r--r-- | client/dbconnector.h | 3 | ||||
-rw-r--r-- | client/mainwindow.cpp | 3 |
5 files changed, 43 insertions, 7 deletions
diff --git a/client/Client.cpp b/client/Client.cpp index 61e51e4..2075fc2 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -54,9 +54,11 @@ void Client::timeFunction() { socket->write(msgToSend); } -void Client::missingRecords() { - QSqlQuery queryTimeData; - queryTimeData.exec("select unix_timestamp(now()) - unix_timestamp(time) as delta from WSdb.tblMain order by time desc limit 1"); +void Client::missingRecords() +{ + QSqlQuery queryTimeData; + queryTimeData.exec("SELECT (unix_timestamp(now()) - unix_timestamp(`time`))/60 as delta FROM `tblMain` limit 1"); + queryTimeData.first(); unsigned int secondsSinceLastRecord = queryTimeData.value(0).toInt(); _missingRecords = secondsSinceLastRecord / WS_CLIENT_STATION_POLL_INTERVAL; diff --git a/client/HandleMessage.cpp b/client/HandleMessage.cpp index a6b9ce4..399abe8 100644 --- a/client/HandleMessage.cpp +++ b/client/HandleMessage.cpp @@ -18,7 +18,33 @@ void HandleMessage::ParseToSQL(QString input) { output.append(")"); - queryInsertData.exec(output); +void HandleMessage::ParseToSQL(QString input) +{ + QSqlQuery queryInsertData; + QString output = "INSERT INTO `tblMain` (`temperature`, `humidity`, `pressure`) VALUES "; + QStringList data; + QStringList list = input.split("\n"); + for (int i = 0; i < list.size(); ++i) { + + output += "("; + + data=list[i].split(","); + + for (int j = 1; j < data.size(); ++j) { + bool valid; + output.append(QString::number(data[j].toInt(&valid, 16))); + if (j <= data[j].size()) { + output.append(","); + } + + } + output.append(")"); + + if (i+1 < list.size()){ + output.append(","); + } + } + queryInsertData.exec(output); } diff --git a/client/dbconnector.cpp b/client/dbconnector.cpp index 256ed53..bbffc58 100644 --- a/client/dbconnector.cpp +++ b/client/dbconnector.cpp @@ -51,3 +51,11 @@ void dbConnector::on_pushButton_login_clicked() QMessageBox::warning(this, "No connection", "Failed to connect"); } } + +QString dbConnector::getdbName(){ + return _dbName; +} + +QString dbConnector::getEspHost(){ + return _espHost; +} diff --git a/client/dbconnector.h b/client/dbconnector.h index 73f4084..82b4f21 100644 --- a/client/dbconnector.h +++ b/client/dbconnector.h @@ -19,6 +19,9 @@ public: explicit dbConnector(QWidget *parent = nullptr); ~dbConnector(); + static QString getdbName(); + static QString getEspHost(); + private slots: void on_pushButton_cancel_clicked(); diff --git a/client/mainwindow.cpp b/client/mainwindow.cpp index 5f76ad8..dcffed6 100644 --- a/client/mainwindow.cpp +++ b/client/mainwindow.cpp @@ -108,8 +108,5 @@ void MainWindow::drawGraph(){ } else { QMessageBox::warning(this, "No connection", "Failed to connect"); } -// delete seriesTemperature; -// delete seriesHumidity; -// delete seriesPressure; } |