From 06eb7a6b4bf6169da2b68330adf9eeb64f081bbd Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 30 Oct 2022 12:20:27 +0100 Subject: finish merge of branch `qt-settings` --- client/consts.h | 2 ++ client/dbconnector.h | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'client') diff --git a/client/consts.h b/client/consts.h index 7ee81c8..a73fea7 100644 --- a/client/consts.h +++ b/client/consts.h @@ -1,5 +1,7 @@ #pragma once +#include "../shared/wifi.h" + // delay between new record request in seconds #define WS_CLIENT_STATION_POLL_INTERVAL 10 diff --git a/client/dbconnector.h b/client/dbconnector.h index 5b9b1cf..73f4084 100644 --- a/client/dbconnector.h +++ b/client/dbconnector.h @@ -5,8 +5,7 @@ #include //#include //#include - -#define WS_ESP8266_WLAN_IP "129.168.0.1" +#include "consts.h" namespace Ui { class dbConnector; -- cgit v1.2.3 From e892ee5639d0f538740e4f1d51284ec27039e270 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 30 Oct 2022 14:34:49 +0100 Subject: fix last record time delta fetch --- client/Client.cpp | 37 +++++++++++++++++-------------------- client/Client.h | 2 +- makefile | 6 +++--- 3 files changed, 21 insertions(+), 24 deletions(-) (limited to 'client') diff --git a/client/Client.cpp b/client/Client.cpp index 4d948fa..e50be5e 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -35,29 +35,26 @@ void Client::ClientEcho() timer->start(1000); } -void Client::timeFunction() -{ - totalRecords = WS_MAX(1, _missingRecords); +void Client::timeFunction() { + if((QTime::currentTime().second() % WS_CLIENT_STATION_POLL_INTERVAL) != 0) return; - char* msg = NULL; - asprintf(&msg, "last-records %x %x\n", totalRecords, offsetRecords); - QByteArray msgToSend = msg; - free(msg); + this->missingRecords(); + totalRecords = WS_MAX(1, _missingRecords); - QTime time = QTime::currentTime(); - qint16 currentSeconds = time.second(); - if((currentSeconds % WS_CLIENT_STATION_POLL_INTERVAL) == 1){ + char* msg = NULL; + asprintf(&msg, "last-records %x %x\n", totalRecords, offsetRecords); + QByteArray msgToSend = msg; + free(msg); - socket->connectToHost(networkAddress, tcpPortAddress); - socket->write(msgToSend); - } + socket->connectToHost(networkAddress, tcpPortAddress); + socket->write(msgToSend); } -void Client::missingRecords() -{ - QSqlQuery queryTimeData; - queryTimeData.exec("SELECT (unix_timestamp(now()) - unix_timestamp(`time`))/60 as delta FROM `WSdb`.`tblMain` limit 1"); - - _missingRecords = queryTimeData.value(0).toInt(); - +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"); + queryTimeData.first(); + unsigned int secondsSinceLastRecord = queryTimeData.value(0).toInt(); + _missingRecords = secondsSinceLastRecord / WS_CLIENT_STATION_POLL_INTERVAL; } + diff --git a/client/Client.h b/client/Client.h index b90e5e9..433aecf 100644 --- a/client/Client.h +++ b/client/Client.h @@ -25,7 +25,7 @@ public slots: private: void missingRecords(); - int _missingRecords; + int _missingRecords = 0; QTcpSocket *socket; // tcpsocket for communicating QTimer *timer; // timer to read every second what time it curruntly is. diff --git a/makefile b/makefile index 60e06ef..a94d2a0 100644 --- a/makefile +++ b/makefile @@ -8,10 +8,10 @@ client_makefile: qmake client/client.pro -o client/makefile client: client_makefile - make -C client + make -jC client client_compile_commands: client_makefile - compiledb -o client/compile_commands.json make -C client + compiledb -o client/compile_commands.json make -BnC client stm32: - make -C stm32f091 + make -jC stm32f091 -- cgit v1.2.3 From a2f62610144d1ba496ece3946a1e64fe8d6e0f9c Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 30 Oct 2022 14:40:34 +0100 Subject: WIP fix HandleMessage --- client/HandleMessage.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'client') diff --git a/client/HandleMessage.cpp b/client/HandleMessage.cpp index aa73828..dc25b21 100644 --- a/client/HandleMessage.cpp +++ b/client/HandleMessage.cpp @@ -17,15 +17,12 @@ QString HandleMessage::ParseMessage(const QString Msg , int totalRecords ) void HandleMessage::ParseToSQL(QString input) { QSqlQuery queryInsertData; - QString output = "INSERT INTO `WSdb`.`tblMain` () VALUES "; + QString output = "insert into WSdb.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))); @@ -35,11 +32,11 @@ void HandleMessage::ParseToSQL(QString input) } output.append(")"); - if (i+1 < list.size()){ output.append(","); } } + printf("%s\n", output.toStdString().c_str()); queryInsertData.exec(output); } -- cgit v1.2.3 From 0c8e3c7e6cdc99a14b38edd747d07d7b03fb294c Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 30 Oct 2022 15:55:56 +0100 Subject: client fix --- client/Client.cpp | 30 +++++++++++++++++------------- client/HandleMessage.cpp | 47 ++++++++++++++--------------------------------- client/HandleMessage.h | 2 -- 3 files changed, 31 insertions(+), 48 deletions(-) (limited to 'client') diff --git a/client/Client.cpp b/client/Client.cpp index e50be5e..61e51e4 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -18,28 +18,32 @@ Client::~Client() delete timer; } -void Client::ClientEcho() -{ - - connect(timer, SIGNAL(timeout()),this,SLOT(timeFunction())); // connect timer to time every minute - - // connect to readyread to receive data; - connect(socket,&QTcpSocket::readyRead, [&]() { - QTextStream T(socket); - QString text = T.readAll(); // reads all data - Handlemsg.ParseToSQL(Handlemsg.ParseMessage(text, (totalRecords-'0'))); +void Client::ClientEcho() { + static unsigned int lineCounter = 0; + connect(timer, SIGNAL(timeout()),this,SLOT(timeFunction())); // connect timer to time every minute + // connect to readyread to receive data; + connect(socket,&QTcpSocket::readyRead, [&]() { + QTextStream T(socket); + QString text = T.readAll(); // reads all data + lineCounter++; + if (lineCounter <= 2) return; + Handlemsg.ParseToSQL(text); + }); - }); + connect(socket, &QTcpSocket::disconnected, [&]() { + socket->disconnectFromHost(); + lineCounter = 0; + }); - timer->start(1000); + timer->start(1000); } void Client::timeFunction() { if((QTime::currentTime().second() % WS_CLIENT_STATION_POLL_INTERVAL) != 0) return; this->missingRecords(); - totalRecords = WS_MAX(1, _missingRecords); + totalRecords = WS_MIN(WS_MAX(1, _missingRecords), 50); char* msg = NULL; asprintf(&msg, "last-records %x %x\n", totalRecords, offsetRecords); diff --git a/client/HandleMessage.cpp b/client/HandleMessage.cpp index dc25b21..a6b9ce4 100644 --- a/client/HandleMessage.cpp +++ b/client/HandleMessage.cpp @@ -1,43 +1,24 @@ #include "HandleMessage.h" +HandleMessage::HandleMessage(QObject *parent) : QObject(parent) { } -HandleMessage::HandleMessage(QObject *parent) : QObject(parent) -{ +void HandleMessage::ParseToSQL(QString input) { + QSqlQuery queryInsertData; + QString output = "insert into WSdb.tblMain (temperature, humidity, pressure) values "; + QStringList data; -} - -QString HandleMessage::ParseMessage(const QString Msg , int totalRecords ) -{ - QString message= Msg.section('\n',2,(3+totalRecords)); + output.append("("); + data=input.split(","); - return message; + for (int i = 1; i < data.size(); i++) { + bool valid; + output.append(QString::number(data[i].toInt(&valid, 16))); + if (i + 1 < data.size()) output.append(","); + } -} + output.append(")"); -void HandleMessage::ParseToSQL(QString input) -{ - QSqlQuery queryInsertData; - QString output = "insert into WSdb.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(","); - } - } - printf("%s\n", output.toStdString().c_str()); - queryInsertData.exec(output); + queryInsertData.exec(output); } diff --git a/client/HandleMessage.h b/client/HandleMessage.h index f228633..f5995c7 100644 --- a/client/HandleMessage.h +++ b/client/HandleMessage.h @@ -12,8 +12,6 @@ class HandleMessage : public QObject Q_OBJECT public: HandleMessage(QObject *parent = 0); - - QString ParseMessage(const QString , int); void ParseToSQL(QString); private: -- cgit v1.2.3