From 2cdbf0173600183f1fb14fdd0e01f00e8b09f308 Mon Sep 17 00:00:00 2001 From: NielsCoding Date: Mon, 10 Oct 2022 18:30:19 +0200 Subject: esp code voor qt --- client/esp/MyTcpSocket.pro | 28 ++++++++++++++++++++++++++++ client/esp/main.cpp | 29 +++++++++++++++++++++++++++++ client/esp/mytcpsocket.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ client/esp/mytcpsocket.h | 32 ++++++++++++++++++++++++++++++++ client/esp/timetest.cpp | 18 ++++++++++++++++++ client/esp/timetest.h | 27 +++++++++++++++++++++++++++ 6 files changed, 178 insertions(+) create mode 100644 client/esp/MyTcpSocket.pro create mode 100644 client/esp/main.cpp create mode 100644 client/esp/mytcpsocket.cpp create mode 100644 client/esp/mytcpsocket.h create mode 100644 client/esp/timetest.cpp create mode 100644 client/esp/timetest.h (limited to 'client/esp') diff --git a/client/esp/MyTcpSocket.pro b/client/esp/MyTcpSocket.pro new file mode 100644 index 0000000..eb1a19e --- /dev/null +++ b/client/esp/MyTcpSocket.pro @@ -0,0 +1,28 @@ +QT += core +QT -= gui +QT += network + +TARGET = QTcpSocket + +CONFIG += console +CONFIG -= app_bundle + + +TEMPLATE = app +# You can make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + main.cpp \ + mytcpsocket.cpp \ + timetest.cpp + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + +HEADERS += \ + mytcpsocket.h \ + timetest.h diff --git a/client/esp/main.cpp b/client/esp/main.cpp new file mode 100644 index 0000000..753b946 --- /dev/null +++ b/client/esp/main.cpp @@ -0,0 +1,29 @@ +#include +#include "mytcpsocket.h" +#include "timetest.h" + +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); +// qint16 startTime= 46; +TimeTest time; + + +//while(1){ + +// +// qint16 minuut = time.myfunction(); + +// if(minuut == startTime) +// { +// qDebug() << "Tijd: " << minuut; +// startTime+=1; + +// } +//} +MyTcpSocket s; +s.doConnect(); + + + return a.exec(); +} diff --git a/client/esp/mytcpsocket.cpp b/client/esp/mytcpsocket.cpp new file mode 100644 index 0000000..92dd67a --- /dev/null +++ b/client/esp/mytcpsocket.cpp @@ -0,0 +1,44 @@ +#include + +MyTcpSocket::MyTcpSocket(QObject *parent) : + QObject(parent) +{ +} + +void MyTcpSocket::doConnect() +{ + socket = new QTcpSocket(this); + + connect(socket, SIGNAL(connected()),this, SLOT(connected())); + connect(socket, SIGNAL(disconnected()),this, SLOT(disconnected())); + // connect(socket, SIGNAL(bytesWritten(qint64)),this, SLOT(bytesWritten(qint64))); + connect(socket, SIGNAL(readyRead()),this, SLOT(readyRead())); + qDebug() << "connectig..."; + + socket->connectToHost("192.168.137.141",80); + + if(!socket->waitForConnected(5000)){ + qDebug()<<"Error: "<< socket->errorString(); + } +} + +void MyTcpSocket::connected(){ + qDebug() << "connected..."; + + socket->write("Weerdata: Temp:?\r\n\r\n\r\n\r\n"); + +} +void MyTcpSocket::disconnected(){ + qDebug() << "disconnected..."; + +} + +void MyTcpSocket::bytesWritten(qint64 bytes){ + qDebug() << bytes << "bytes written..."; + +} +void MyTcpSocket::readyRead(){ + qDebug() << "reading..."; + + qDebug() << socket->readAll(); +} diff --git a/client/esp/mytcpsocket.h b/client/esp/mytcpsocket.h new file mode 100644 index 0000000..4a7e543 --- /dev/null +++ b/client/esp/mytcpsocket.h @@ -0,0 +1,32 @@ +#ifndef MYTCPSOCKET_H +#define MYTCPSOCKET_H + +#include +#include +#include +#include + +class MyTcpSocket : public QObject +{ + Q_OBJECT +public: + explicit MyTcpSocket(QObject *parent = 0); + + void doConnect(); +signals: +public slots: + void connected(); + void disconnected(); + void bytesWritten(qint64 bytes); + void readyRead(); +private: + QTcpSocket *socket; + + + + + +}; + + +#endif // MYTCPSOCKET_H diff --git a/client/esp/timetest.cpp b/client/esp/timetest.cpp new file mode 100644 index 0000000..2e575f2 --- /dev/null +++ b/client/esp/timetest.cpp @@ -0,0 +1,18 @@ +#include "timetest.h" + +TimeTest::TimeTest(QObject *parent) : QObject(parent) +{ + timer = new QTimer(this); + connect(timer, SIGNAL(timeout()),this,SLOT(myfunction())); + timer->start(5000); +} + +qint16 TimeTest::myfunction() +{ + QTime time = QTime::currentTime(); + qint16 time_text = time.minute(); + + return time_text; + + +} diff --git a/client/esp/timetest.h b/client/esp/timetest.h new file mode 100644 index 0000000..aa1d8a5 --- /dev/null +++ b/client/esp/timetest.h @@ -0,0 +1,27 @@ +#ifndef TIMETEST_H +#define TIMETEST_H +#include +#include +#include +#include + +class TimeTest : public QObject +{ + Q_OBJECT +public: + explicit TimeTest(QObject *parent = 0); + +signals: +public slots: + qint16 myfunction(); + +private: + QTimer *timer; + + + + +}; + + +#endif // TIMETEST_H -- cgit v1.2.3