aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-10-30 11:20:43 +0100
committerlonkaars <loek@pipeframe.xyz>2022-10-30 11:21:00 +0100
commite4f41ef8b56b76214d05bce34ffd5a8896da24c9 (patch)
treeefe55c9ef28e4c787e10a5b85319b242c7525e9a
parente473fe14614401342cdc3afe3f6deee4831e6e24 (diff)
parentaf008eb04e3a5705eec63839abc5791454e763ce (diff)
finish second merge
-rw-r--r--.gitignore3
-rw-r--r--client/Client.cpp10
-rw-r--r--client/Client.h10
-rw-r--r--client/HandleMessage.h2
-rw-r--r--client/client.pro1
-rw-r--r--client/consts.h5
-rw-r--r--client/dbconnector.h1
-rw-r--r--client/dbconnector.ui8
-rw-r--r--client/ui_dbconnector.h163
-rw-r--r--client/ui_mainwindow.h110
-rw-r--r--shared/wifi.def.h (renamed from stm32f091/wifi.def.h)1
-rw-r--r--stm32f091/consts.h5
-rw-r--r--stm32f091/esp8266.c2
-rw-r--r--stm32f091/readme.md3
-rw-r--r--stm32f091/util.h4
15 files changed, 30 insertions, 298 deletions
diff --git a/.gitignore b/.gitignore
index 5b91ddc..6cbf173 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,15 +6,16 @@
# stm32-specific files
stm32f091/main.elf
stm32f091/main.bin
-stm32f091/wifi.h
# client-specific files
client/makefile
client/client
client/moc_*
+client/ui_*
**/.user
# others
+shared/wifi.h
shared/main
.qmake.stash
.vscode/.cortex-debug.registers.state.json
diff --git a/client/Client.cpp b/client/Client.cpp
index 46952b6..10d288e 100644
--- a/client/Client.cpp
+++ b/client/Client.cpp
@@ -1,5 +1,5 @@
#include "Client.h"
-
+#include "consts.h"
Client::Client(QObject *parent) : QObject(parent)
@@ -17,8 +17,6 @@ Client::~Client()
void Client::ClientEcho()
{
- QTime time1 = QTime::currentTime();
- NextMinute = time1.minute()+1;
connect(timer, SIGNAL(timeout()),this,SLOT(timeFunction())); // connect timer to time every minute
@@ -45,13 +43,11 @@ void Client::timeFunction()
QByteArray msgToSend= (msg.toUtf8() + totalRecords + offsetRecords +'\n');
QTime time = QTime::currentTime();
- qint16 currentMinute = time.minute();
+ qint16 currentSeconds = time.second();
+ if((currentSeconds % WS_CLIENT_STATION_POLL_INTERVAL) == 1){
- if(currentMinute==NextMinute){
socket->connectToHost(networkAddress, tcpPortAddress);
-
socket->write(msgToSend);
- NextMinute++;
}
}
diff --git a/client/Client.h b/client/Client.h
index 10af3e1..f675a89 100644
--- a/client/Client.h
+++ b/client/Client.h
@@ -1,5 +1,6 @@
#ifndef CLIENT_H
#define CLIENT_H
+
#include <QTcpSocket>
#include <QTextStream>
#include <QTimer>
@@ -7,6 +8,7 @@
#include <QSqlQuery>
#include "HandleMessage.h"
+#include "../shared/wifi.h"
// class client for wheather station
class Client : public QObject
@@ -27,19 +29,15 @@ private:
QTcpSocket *socket; // tcpsocket for communicating
QTimer *timer; // timer to read every second what time it curruntly is.
- qint16 NextMinute; // timing for next minute
// qint16 currentMinute; // timing for currentMinute
HandleMessage Handlemsg; // add HandleMessage to Client.h
- int tcpPortAddress = 80; // port of communication via tcp
- QString networkAddress = "192.168.137.76"; // network address for commincation via tcp
+ int tcpPortAddress = WS_SERVER_PORT; // port of communication via tcp
+ QString networkAddress = WS_ESP8266_WLAN_IP; // network address for commincation via tcp
QString msg = "last-records "; // part of mesage to send to wheather staion
char totalRecords = '1'; // total records to ask wheather station
char offsetRecords = '0'; // offset from reqeusting records
-
-
-
};
#endif // CLIENT_H
diff --git a/client/HandleMessage.h b/client/HandleMessage.h
index bfc5063..f228633 100644
--- a/client/HandleMessage.h
+++ b/client/HandleMessage.h
@@ -16,8 +16,6 @@ public:
QString ParseMessage(const QString , int);
void ParseToSQL(QString);
-
-
private:
};
diff --git a/client/client.pro b/client/client.pro
index 76f2b56..8305949 100644
--- a/client/client.pro
+++ b/client/client.pro
@@ -3,6 +3,7 @@ QT += core gui sql charts network
HEADERS += \
Client.h \
HandleMessage.h \
+ consts.h \
dbconnector.h \
main.h \
mainwindow.h
diff --git a/client/consts.h b/client/consts.h
new file mode 100644
index 0000000..7ee81c8
--- /dev/null
+++ b/client/consts.h
@@ -0,0 +1,5 @@
+#pragma once
+
+// 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 db8ac4e..b989e57 100644
--- a/client/dbconnector.h
+++ b/client/dbconnector.h
@@ -6,7 +6,6 @@
//#include <QtSql>
//#include <QSqlDatabase>
-
namespace Ui {
class dbConnector;
}
diff --git a/client/dbconnector.ui b/client/dbconnector.ui
index 1159faf..5c5b326 100644
--- a/client/dbconnector.ui
+++ b/client/dbconnector.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>362</width>
- <height>273</height>
+ <width>401</width>
+ <height>288</height>
</rect>
</property>
<property name="windowTitle">
@@ -18,8 +18,8 @@
<rect>
<x>60</x>
<y>60</y>
- <width>241</width>
- <height>173</height>
+ <width>270</width>
+ <height>171</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
diff --git a/client/ui_dbconnector.h b/client/ui_dbconnector.h
deleted file mode 100644
index dec4d7b..0000000
--- a/client/ui_dbconnector.h
+++ /dev/null
@@ -1,163 +0,0 @@
-/********************************************************************************
-** Form generated from reading UI file 'dbconnector.ui'
-**
-** Created by: Qt User Interface Compiler version 5.15.6
-**
-** WARNING! All changes made in this file will be lost when recompiling UI file!
-********************************************************************************/
-
-#ifndef UI_DBCONNECTOR_H
-#define UI_DBCONNECTOR_H
-
-#include <QtCore/QVariant>
-#include <QtWidgets/QApplication>
-#include <QtWidgets/QDialog>
-#include <QtWidgets/QFormLayout>
-#include <QtWidgets/QFrame>
-#include <QtWidgets/QHBoxLayout>
-#include <QtWidgets/QLabel>
-#include <QtWidgets/QLineEdit>
-#include <QtWidgets/QPushButton>
-#include <QtWidgets/QWidget>
-
-QT_BEGIN_NAMESPACE
-
-class Ui_dbConnector
-{
-public:
- QWidget *formLayoutWidget;
- QFormLayout *formLayout;
- QLabel *label_3;
- QLineEdit *lineEdit_adress;
- QLabel *label_4;
- QLineEdit *lineEdit_database;
- QFrame *line;
- QLabel *label;
- QLineEdit *lineEdit_username;
- QLabel *label_2;
- QLineEdit *lineEdit_password;
- QLabel *connectLabel;
- QHBoxLayout *horizontalLayout;
- QPushButton *pushButton_login;
- QPushButton *pushButton_cancel;
-
- void setupUi(QDialog *dbConnector)
- {
- if (dbConnector->objectName().isEmpty())
- dbConnector->setObjectName(QString::fromUtf8("dbConnector"));
- dbConnector->resize(362, 273);
- formLayoutWidget = new QWidget(dbConnector);
- formLayoutWidget->setObjectName(QString::fromUtf8("formLayoutWidget"));
- formLayoutWidget->setGeometry(QRect(60, 60, 241, 173));
- formLayout = new QFormLayout(formLayoutWidget);
- formLayout->setObjectName(QString::fromUtf8("formLayout"));
- formLayout->setContentsMargins(0, 0, 0, 0);
- label_3 = new QLabel(formLayoutWidget);
- label_3->setObjectName(QString::fromUtf8("label_3"));
-
- formLayout->setWidget(0, QFormLayout::LabelRole, label_3);
-
- lineEdit_adress = new QLineEdit(formLayoutWidget);
- lineEdit_adress->setObjectName(QString::fromUtf8("lineEdit_adress"));
-
- formLayout->setWidget(0, QFormLayout::FieldRole, lineEdit_adress);
-
- label_4 = new QLabel(formLayoutWidget);
- label_4->setObjectName(QString::fromUtf8("label_4"));
-
- formLayout->setWidget(1, QFormLayout::LabelRole, label_4);
-
- lineEdit_database = new QLineEdit(formLayoutWidget);
- lineEdit_database->setObjectName(QString::fromUtf8("lineEdit_database"));
-
- formLayout->setWidget(1, QFormLayout::FieldRole, lineEdit_database);
-
- line = new QFrame(formLayoutWidget);
- line->setObjectName(QString::fromUtf8("line"));
- line->setFrameShape(QFrame::HLine);
- line->setFrameShadow(QFrame::Sunken);
-
- formLayout->setWidget(2, QFormLayout::SpanningRole, line);
-
- label = new QLabel(formLayoutWidget);
- label->setObjectName(QString::fromUtf8("label"));
-
- formLayout->setWidget(3, QFormLayout::LabelRole, label);
-
- lineEdit_username = new QLineEdit(formLayoutWidget);
- lineEdit_username->setObjectName(QString::fromUtf8("lineEdit_username"));
- lineEdit_username->setEchoMode(QLineEdit::PasswordEchoOnEdit);
-
- formLayout->setWidget(3, QFormLayout::FieldRole, lineEdit_username);
-
- label_2 = new QLabel(formLayoutWidget);
- label_2->setObjectName(QString::fromUtf8("label_2"));
-
- formLayout->setWidget(4, QFormLayout::LabelRole, label_2);
-
- lineEdit_password = new QLineEdit(formLayoutWidget);
- lineEdit_password->setObjectName(QString::fromUtf8("lineEdit_password"));
- QFont font;
- font.setUnderline(false);
- font.setStrikeOut(false);
- font.setKerning(true);
- lineEdit_password->setFont(font);
- lineEdit_password->setEchoMode(QLineEdit::Password);
-
- formLayout->setWidget(4, QFormLayout::FieldRole, lineEdit_password);
-
- connectLabel = new QLabel(formLayoutWidget);
- connectLabel->setObjectName(QString::fromUtf8("connectLabel"));
-
- formLayout->setWidget(5, QFormLayout::LabelRole, connectLabel);
-
- horizontalLayout = new QHBoxLayout();
- horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
- pushButton_login = new QPushButton(formLayoutWidget);
- pushButton_login->setObjectName(QString::fromUtf8("pushButton_login"));
-
- horizontalLayout->addWidget(pushButton_login);
-
- pushButton_cancel = new QPushButton(formLayoutWidget);
- pushButton_cancel->setObjectName(QString::fromUtf8("pushButton_cancel"));
-
- horizontalLayout->addWidget(pushButton_cancel);
-
-
- formLayout->setLayout(5, QFormLayout::FieldRole, horizontalLayout);
-
-
- retranslateUi(dbConnector);
-
- QMetaObject::connectSlotsByName(dbConnector);
- } // setupUi
-
- void retranslateUi(QDialog *dbConnector)
- {
- dbConnector->setWindowTitle(QCoreApplication::translate("dbConnector", "Dialog", nullptr));
- label_3->setText(QCoreApplication::translate("dbConnector", "Adress", nullptr));
- lineEdit_adress->setText(QCoreApplication::translate("dbConnector", "localhost", nullptr));
- lineEdit_adress->setPlaceholderText(QCoreApplication::translate("dbConnector", "Hostname/IP-Adress", nullptr));
- label_4->setText(QCoreApplication::translate("dbConnector", "Database", nullptr));
- lineEdit_database->setText(QCoreApplication::translate("dbConnector", "WSdb", nullptr));
- lineEdit_database->setPlaceholderText(QCoreApplication::translate("dbConnector", "Database name", nullptr));
- label->setText(QCoreApplication::translate("dbConnector", "Username", nullptr));
- lineEdit_username->setText(QCoreApplication::translate("dbConnector", "root", nullptr));
- lineEdit_username->setPlaceholderText(QCoreApplication::translate("dbConnector", "Username", nullptr));
- label_2->setText(QCoreApplication::translate("dbConnector", "Password", nullptr));
- lineEdit_password->setText(QCoreApplication::translate("dbConnector", "Ab12345!", nullptr));
- lineEdit_password->setPlaceholderText(QCoreApplication::translate("dbConnector", "Password", nullptr));
- connectLabel->setText(QCoreApplication::translate("dbConnector", "Connect", nullptr));
- pushButton_login->setText(QCoreApplication::translate("dbConnector", "Login", nullptr));
- pushButton_cancel->setText(QCoreApplication::translate("dbConnector", "Cancel", nullptr));
- } // retranslateUi
-
-};
-
-namespace Ui {
- class dbConnector: public Ui_dbConnector {};
-} // namespace Ui
-
-QT_END_NAMESPACE
-
-#endif // UI_DBCONNECTOR_H
diff --git a/client/ui_mainwindow.h b/client/ui_mainwindow.h
deleted file mode 100644
index 69c476b..0000000
--- a/client/ui_mainwindow.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/********************************************************************************
-** Form generated from reading UI file 'mainwindow.ui'
-**
-** Created by: Qt User Interface Compiler version 5.15.6
-**
-** WARNING! All changes made in this file will be lost when recompiling UI file!
-********************************************************************************/
-
-#ifndef UI_MAINWINDOW_H
-#define UI_MAINWINDOW_H
-
-#include <QtCore/QVariant>
-// #include <QtWidgets/QAction>
-#include <QtWidgets/QApplication>
-#include <QtWidgets/QLabel>
-#include <QtWidgets/QMainWindow>
-#include <QtWidgets/QMenu>
-#include <QtWidgets/QMenuBar>
-#include <QtWidgets/QStatusBar>
-#include <QtWidgets/QWidget>
-
-QT_BEGIN_NAMESPACE
-
-class Ui_MainWindow
-{
-public:
- QAction *actionRefresh;
- QAction *actionLOAD;
- QAction *actionQuerry;
- QAction *actionConnection;
- QAction *actionDisconnenct;
- QWidget *centralwidget;
- QLabel *label;
- QMenuBar *menubar;
- QMenu *menuAbouy;
- QMenu *menuDatabase;
- QStatusBar *statusbar;
-
- void setupUi(QMainWindow *MainWindow)
- {
- if (MainWindow->objectName().isEmpty())
- MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
- MainWindow->resize(800, 600);
- actionRefresh = new QAction(MainWindow);
- actionRefresh->setObjectName(QString::fromUtf8("actionRefresh"));
- actionLOAD = new QAction(MainWindow);
- actionLOAD->setObjectName(QString::fromUtf8("actionLOAD"));
- actionQuerry = new QAction(MainWindow);
- actionQuerry->setObjectName(QString::fromUtf8("actionQuerry"));
- actionConnection = new QAction(MainWindow);
- actionConnection->setObjectName(QString::fromUtf8("actionConnection"));
- actionDisconnenct = new QAction(MainWindow);
- actionDisconnenct->setObjectName(QString::fromUtf8("actionDisconnenct"));
- centralwidget = new QWidget(MainWindow);
- centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
- label = new QLabel(centralwidget);
- label->setObjectName(QString::fromUtf8("label"));
- label->setGeometry(QRect(270, 190, 181, 51));
- MainWindow->setCentralWidget(centralwidget);
- menubar = new QMenuBar(MainWindow);
- menubar->setObjectName(QString::fromUtf8("menubar"));
- menubar->setGeometry(QRect(0, 0, 800, 24));
- menuAbouy = new QMenu(menubar);
- menuAbouy->setObjectName(QString::fromUtf8("menuAbouy"));
- menuDatabase = new QMenu(menubar);
- menuDatabase->setObjectName(QString::fromUtf8("menuDatabase"));
- MainWindow->setMenuBar(menubar);
- statusbar = new QStatusBar(MainWindow);
- statusbar->setObjectName(QString::fromUtf8("statusbar"));
- MainWindow->setStatusBar(statusbar);
-
- menubar->addAction(menuAbouy->menuAction());
- menubar->addAction(menuDatabase->menuAction());
- menuAbouy->addAction(actionRefresh);
- menuDatabase->addAction(actionConnection);
- menuDatabase->addAction(actionDisconnenct);
-
- retranslateUi(MainWindow);
-
- QMetaObject::connectSlotsByName(MainWindow);
- } // setupUi
-
- void retranslateUi(QMainWindow *MainWindow)
- {
- MainWindow->setWindowTitle(QCoreApplication::translate("MainWindow", "MainWindow", nullptr));
- actionRefresh->setText(QCoreApplication::translate("MainWindow", "Refresh", nullptr));
-#if QT_CONFIG(shortcut)
- actionRefresh->setShortcut(QCoreApplication::translate("MainWindow", "Ctrl+R", nullptr));
-#endif // QT_CONFIG(shortcut)
- actionLOAD->setText(QCoreApplication::translate("MainWindow", "Load", nullptr));
- actionQuerry->setText(QCoreApplication::translate("MainWindow", "Query", nullptr));
- actionConnection->setText(QCoreApplication::translate("MainWindow", "Connect", nullptr));
-#if QT_CONFIG(shortcut)
- actionConnection->setShortcut(QCoreApplication::translate("MainWindow", "Ctrl+O", nullptr));
-#endif // QT_CONFIG(shortcut)
- actionDisconnenct->setText(QCoreApplication::translate("MainWindow", "Disconnenct", nullptr));
- label->setText(QCoreApplication::translate("MainWindow", "Please load data first", nullptr));
- menuAbouy->setTitle(QCoreApplication::translate("MainWindow", "Home", nullptr));
- menuDatabase->setTitle(QCoreApplication::translate("MainWindow", "Database", nullptr));
- } // retranslateUi
-
-};
-
-namespace Ui {
- class MainWindow: public Ui_MainWindow {};
-} // namespace Ui
-
-QT_END_NAMESPACE
-
-#endif // UI_MAINWINDOW_H
diff --git a/stm32f091/wifi.def.h b/shared/wifi.def.h
index 61e1706..aead0b6 100644
--- a/stm32f091/wifi.def.h
+++ b/shared/wifi.def.h
@@ -4,4 +4,5 @@
#define WS_ESP8266_WLAN_PASSWD "12345678"
// #define WS_ESP8266_WLAN_MAC "f2:9b:89:47:c4:f3"
// #define WS_ESP8266_WLAN_IP "192.168.2.69"
+#define WS_SERVER_PORT 80
diff --git a/stm32f091/consts.h b/stm32f091/consts.h
index 3d2ef5a..6d5b8d2 100644
--- a/stm32f091/consts.h
+++ b/stm32f091/consts.h
@@ -1,9 +1,10 @@
#pragma once
-#include "wifi.h"
+#include "../shared/wifi.h"
+#include "util.h"
-#define WS_SERVER_PORT "80"
#define WS_SERVER_MAX_CHANNELS 4
+#define WS_SERVER_PORT_STR WS_MTS(WS_SERVER_PORT)
#define WS_DMA_RX_BUFFER_SIZE 100
#define WS_DMA_TX_BUFFER_SIZE 1024
diff --git a/stm32f091/esp8266.c b/stm32f091/esp8266.c
index 74ec347..8ff9547 100644
--- a/stm32f091/esp8266.c
+++ b/stm32f091/esp8266.c
@@ -77,7 +77,7 @@ void ws_esp8266_ap_client_mode() {
void ws_esp8266_start_tcp_server() {
ws_esp8266_send_seq("AT+CIPSERVER=0\r\n"); // stop tcp server (if running)
ws_esp8266_send_seq("AT+CIPMUX=1\r\n"); // enable multiplexing (allow multiple connections)
- ws_esp8266_send_seq("AT+CIPSERVER=1," WS_SERVER_PORT "\r\n"); // start tcp server
+ ws_esp8266_send_seq("AT+CIPSERVER=1," WS_SERVER_PORT_STR "\r\n"); // start tcp server
}
void ws_esp8266_set_mac() {
diff --git a/stm32f091/readme.md b/stm32f091/readme.md
index d2758b5..e6af60f 100644
--- a/stm32f091/readme.md
+++ b/stm32f091/readme.md
@@ -3,7 +3,8 @@
- uses make
- make sure to initialize the git submodules
- all warnings from source files in the lib/ subfolder are hidden
-- copy wifi.def.h to wifi.h and edit the network credentials
+- copy ../shared/wifi.def.h to ../shared/wifi.h and edit the network
+ credentials
- the initialization code is broken in some way which means that a soft reset
is required for the uart dma to work, either (a) press the reset button on
the development board after plugging in, or (b) run `st-flash reset` after
diff --git a/stm32f091/util.h b/stm32f091/util.h
index 11bee6f..9c15f8b 100644
--- a/stm32f091/util.h
+++ b/stm32f091/util.h
@@ -8,6 +8,10 @@
#include "setup.h"
#include "../shared/util.h"
+// macro to string macro's
+#define WS_MTS_EXPAND(x) #x
+#define WS_MTS(x) WS_MTS_EXPAND(x)
+
#define WS_DBG_TTY_COLOR_BLK 0x0
#define WS_DBG_TTY_COLOR_RED 0x1
#define WS_DBG_TTY_COLOR_GRN 0x2