Merge branch 'main' of git.labolyon.fr:DTux/pws2mqtt-qt
This commit is contained in:
commit
0fe18e0fd3
1 file changed
+10
-12
+10
-12
@@ -2,7 +2,6 @@
|
|||||||
#include "barometertrend.h"
|
#include "barometertrend.h"
|
||||||
//#include <cstring>
|
//#include <cstring>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
//#include <iostream>
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QtHttpServer/QHttpServer>
|
#include <QtHttpServer/QHttpServer>
|
||||||
#include <QtHttpServer/QHttpServerRequest>
|
#include <QtHttpServer/QHttpServerRequest>
|
||||||
@@ -10,6 +9,7 @@
|
|||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QTransform>
|
#include <QTransform>
|
||||||
//#include <sys/stat.h>
|
//#include <sys/stat.h>
|
||||||
|
#include "qstringview.h"
|
||||||
#include "utcicalculator.h"
|
#include "utcicalculator.h"
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
@@ -90,17 +90,15 @@ Pws2mqtt::~Pws2mqtt()
|
|||||||
void Pws2mqtt::init()
|
void Pws2mqtt::init()
|
||||||
{
|
{
|
||||||
debug(DEBUGMACRO, "init http server", INFO);
|
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);
|
debug(DEBUGMACRO, "body " + request.url().toString(), WARNING);
|
||||||
return 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(QHttpServerResponse("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)
|
httpServer->route("/", [](const QHttpServerRequest &request)
|
||||||
{
|
{
|
||||||
QList<std::pair<QByteArray, QByteArray>> headersList = request.headers().toList();
|
|
||||||
debug(DEBUGMACRO, "Remote address" + request.remoteAddress().toString(), WARNING);
|
debug(DEBUGMACRO, "Remote address" + request.remoteAddress().toString(), WARNING);
|
||||||
return QHttpServerResponse("text/plain", "Failed\n");
|
return QHttpServerResponse("text/plain", "Failed\n");
|
||||||
});
|
});
|
||||||
@@ -173,7 +171,8 @@ void Pws2mqtt::listeningHttp()
|
|||||||
{
|
{
|
||||||
//QByteArray data;
|
//QByteArray data;
|
||||||
debug (DEBUGMACRO, "listening http requests", DEBUG);
|
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)
|
if (!port)
|
||||||
{
|
{
|
||||||
debug(DEBUGMACRO, "Http Server failed to listen on a port.", ERROR);
|
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"};
|
QStringList priorityList {"", "min", "low", "default", "High", "urgent"};
|
||||||
QString attachment = "";
|
QString attachment = "";
|
||||||
QString tag = "";
|
QString tag = "";
|
||||||
|
QHash <QByteArray, quint8> priority;
|
||||||
|
bool start = false;
|
||||||
double propertyValue = 0;
|
double propertyValue = 0;
|
||||||
bool propertyFlag = false;
|
bool propertyFlag = false;
|
||||||
bool deviceFlag = false;
|
bool deviceFlag = false;
|
||||||
static QDateTime timer = QDateTime::currentDateTime().addSecs(-2000);
|
static QDateTime timer = QDateTime::currentDateTime().addSecs(-2000);
|
||||||
static QHash <QByteArray, quint8> priority = {};
|
|
||||||
static bool start = false;
|
|
||||||
|
|
||||||
debug(DEBUGMACRO, "looping list of query", DEBUG);
|
debug(DEBUGMACRO, "looping list of query", DEBUG);
|
||||||
|
|
||||||
@@ -274,6 +273,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
propertyValue = value.toFloat();
|
propertyValue = value.toFloat();
|
||||||
rotateAndSaveImage(this->inputPath, this->outputPath, (qreal)propertyValue);
|
rotateAndSaveImage(this->inputPath, this->outputPath, (qreal)propertyValue);
|
||||||
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
|
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
|
||||||
|
|
||||||
propertyList[name] = formatNotifString(propertyName[name], QByteArray::number(propertyValue));
|
propertyList[name] = formatNotifString(propertyName[name], QByteArray::number(propertyValue));
|
||||||
propertiesValue[name] = propertyValue;
|
propertiesValue[name] = propertyValue;
|
||||||
}else if (name == "windspeedmph")
|
}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);
|
debug(DEBUGMACRO, "current datetime : " + QDateTime::currentDateTime().toString() + ", timer = " + timer.toString(), DEBUG);
|
||||||
|
|
||||||
|
|
||||||
//bool changed = false;
|
//bool changed = false;
|
||||||
quint8 aPriority= 0;
|
quint8 aPriority= 0;
|
||||||
|
|
||||||
@@ -599,7 +598,6 @@ QString formatNotifString (QPair<QString, QByteArray> property ,QByteArray value
|
|||||||
return text += "\n";
|
return text += "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void rotateAndSaveImage(const QString &inputPath, const QString &outputPath, qreal angle)
|
void rotateAndSaveImage(const QString &inputPath, const QString &outputPath, qreal angle)
|
||||||
{
|
{
|
||||||
QImage image(inputPath);
|
QImage image(inputPath);
|
||||||
|
|||||||
Reference in new issue
Block a user