diff --git a/src/pws2mqtt.cpp b/src/pws2mqtt.cpp index 793029f..79027d0 100644 --- a/src/pws2mqtt.cpp +++ b/src/pws2mqtt.cpp @@ -2,7 +2,6 @@ #include "barometertrend.h" //#include #include -//#include #include #include #include @@ -10,6 +9,7 @@ #include #include //#include +#include "qstringview.h" #include "utcicalculator.h" #include #include @@ -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> 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> queryList) QStringList priorityList {"", "min", "low", "default", "High", "urgent"}; QString attachment = ""; QString tag = ""; + QHash priority; + bool start = false; double propertyValue = 0; bool propertyFlag = false; bool deviceFlag = false; static QDateTime timer = QDateTime::currentDateTime().addSecs(-2000); - static QHash priority = {}; - static bool start = false; debug(DEBUGMACRO, "looping list of query", DEBUG); @@ -274,6 +273,7 @@ void Pws2mqtt::parseData(QList> 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> queryList) debug(DEBUGMACRO, "current datetime : " + QDateTime::currentDateTime().toString() + ", timer = " + timer.toString(), DEBUG); - //bool changed = false; quint8 aPriority= 0; @@ -457,7 +456,7 @@ void Pws2mqtt::parseData(QList> queryList) } if (aPriority >= 3) { - notif = "**ALERTES**\n" + listProperties2notify (propertyList, priority, 3); + notif = "**ALERTES**\n" + listProperties2notify (propertyList,priority, 3); precPropertyList = propertyList; notify (notif, priorityList[aPriority], attachment, tag); } @@ -599,7 +598,6 @@ QString formatNotifString (QPair property ,QByteArray value return text += "\n"; } - void rotateAndSaveImage(const QString &inputPath, const QString &outputPath, qreal angle) { QImage image(inputPath);