Merge branch 'main' of git.labolyon.fr:DTux/pws2mqtt-qt

This commit is contained in:
DTux committed 2026-04-13 17:17:45 +02:00
commit 0fe18e0fd3
1 file changed
+10 -12
+10 -12
View File
@@ -2,7 +2,6 @@
#include "barometertrend.h"
//#include <cstring>
#include <QtGlobal>
//#include <iostream>
#include <QList>
#include <QtHttpServer/QHttpServer>
#include <QtHttpServer/QHttpServerRequest>
@@ -10,6 +9,7 @@
#include <QImage>
#include <QTransform>
//#include <sys/stat.h>
#include "qstringview.h"
#include "utcicalculator.h"
#include <QNetworkAccessManager>
#include <QNetworkReply>
@@ -90,17 +90,15 @@ Pws2mqtt::~Pws2mqtt()
void Pws2mqtt::init()
{
debug(DEBUGMACRO, "init http server", INFO);
httpServer->setMissingHandler([](const QHttpServerRequest &request, QHttpServerResponder &&responder)
/*httpServer->setMissingHandler([](const QHttpServerRequest &request, QHttpServerResponder &&responder)
{
(void) responder;
debug(DEBUGMACRO, "body " + request.url().toString(), WARNING);
return QHttpServerResponse("404 - Page non trouvée. Route par défaut.", QHttpServerResponse::StatusCode::NotFound);
//responder.write(QHttpServerResponse("404 - Page non trouvée. Route par défaut.", QHttpServerResponse::StatusCode::NotFound));
});
//responder.write(QHttpServerResponse(QString("404 - Page non trouvée. Route par défaut."), QHttpServerResponse::StatusCode::NotFound));
responder.write(QByteArray("404 - Page non trouvée. Route par défaut."), "text/plain", QHttpServerResponse::StatusCode::NotFound);
});*/
httpServer->route("/", [](const QHttpServerRequest &request)
{
QList<std::pair<QByteArray, QByteArray>> headersList = request.headers().toList();
debug(DEBUGMACRO, "Remote address" + request.remoteAddress().toString(), WARNING);
return QHttpServerResponse("text/plain", "Failed\n");
});
@@ -173,7 +171,8 @@ void Pws2mqtt::listeningHttp()
{
//QByteArray data;
debug (DEBUGMACRO, "listening http requests", DEBUG);
const auto port = httpServer->listen(QHostAddress::Any, 5000);
QTcpServer *tcpServer = new QTcpServer(this);
const auto port =tcpServer->listen(QHostAddress::Any, 5000);
if (!port)
{
debug(DEBUGMACRO, "Http Server failed to listen on a port.", ERROR);
@@ -193,12 +192,12 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
QStringList priorityList {"", "min", "low", "default", "High", "urgent"};
QString attachment = "";
QString tag = "";
QHash <QByteArray, quint8> priority;
bool start = false;
double propertyValue = 0;
bool propertyFlag = false;
bool deviceFlag = false;
static QDateTime timer = QDateTime::currentDateTime().addSecs(-2000);
static QHash <QByteArray, quint8> priority = {};
static bool start = false;
debug(DEBUGMACRO, "looping list of query", DEBUG);
@@ -274,6 +273,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
propertyValue = value.toFloat();
rotateAndSaveImage(this->inputPath, this->outputPath, (qreal)propertyValue);
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
propertyList[name] = formatNotifString(propertyName[name], QByteArray::number(propertyValue));
propertiesValue[name] = propertyValue;
}else if (name == "windspeedmph")
@@ -435,7 +435,6 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
debug(DEBUGMACRO, "current datetime : " + QDateTime::currentDateTime().toString() + ", timer = " + timer.toString(), DEBUG);
//bool changed = false;
quint8 aPriority= 0;
@@ -599,7 +598,6 @@ QString formatNotifString (QPair<QString, QByteArray> property ,QByteArray value
return text += "\n";
}
void rotateAndSaveImage(const QString &inputPath, const QString &outputPath, qreal angle)
{
QImage image(inputPath);