temperature avec 1 décimale
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "barometertrend.h"
|
||||
//#include <cstring>
|
||||
#include <QtGlobal>
|
||||
//#include <iostream>
|
||||
#include <QList>
|
||||
#include <QtHttpServer/QHttpServer>
|
||||
#include <QtHttpServer/QHttpServerRequest>
|
||||
@@ -9,7 +10,6 @@
|
||||
#include <QImage>
|
||||
#include <QTransform>
|
||||
//#include <sys/stat.h>
|
||||
#include "qstringview.h"
|
||||
#include "utcicalculator.h"
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
@@ -90,15 +90,17 @@ 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);
|
||||
//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);
|
||||
});*/
|
||||
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));
|
||||
});
|
||||
|
||||
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");
|
||||
});
|
||||
@@ -152,7 +154,7 @@ void notify(QString notif, QString priority, QString inputPath, QString tag)
|
||||
request.setRawHeader("Firebase", "no");
|
||||
|
||||
QNetworkReply *reply = manager->post(request, notif.toUtf8());
|
||||
QObject::connect(reply, &QNetworkReply::finished, [reply]()
|
||||
QObject::connect(reply, &QNetworkReply::finished, [manager, reply]()
|
||||
{
|
||||
if (reply->error() != QNetworkReply::NoError)
|
||||
{
|
||||
@@ -162,8 +164,8 @@ void notify(QString notif, QString priority, QString inputPath, QString tag)
|
||||
debug(DEBUGMACRO, "Notification envoyée", INFO);
|
||||
}
|
||||
reply->deleteLater();
|
||||
delete(manager);
|
||||
});
|
||||
delete(manager);
|
||||
}
|
||||
|
||||
|
||||
@@ -171,8 +173,7 @@ void Pws2mqtt::listeningHttp()
|
||||
{
|
||||
//QByteArray data;
|
||||
debug (DEBUGMACRO, "listening http requests", DEBUG);
|
||||
QTcpServer *tcpServer = new QTcpServer(this);
|
||||
const auto port =tcpServer->listen(QHostAddress::Any, 5000);
|
||||
const auto port = httpServer->listen(QHostAddress::Any, 5000);
|
||||
if (!port)
|
||||
{
|
||||
debug(DEBUGMACRO, "Http Server failed to listen on a port.", ERROR);
|
||||
@@ -192,12 +193,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);
|
||||
|
||||
@@ -239,7 +240,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
||||
if (name == "tempf")
|
||||
{
|
||||
static QDateTime timeTemp = QDateTime::currentDateTime().addSecs(-600);
|
||||
propertyValue = round(fahrenheitToCelsius(fValue));
|
||||
propertyValue = qRound(fahrenheitToCelsius(fValue) * 10 ) / 10.0;
|
||||
debug (DEBUGMACRO, "timeTemp = " + timeTemp.time().toString() + " - current :" + QDateTime::currentDateTime().toString() , DEBUG);
|
||||
|
||||
if (compare (propertiesValue[name], propertyValue, 1) and timeTemp < QDateTime::currentDateTime())
|
||||
@@ -273,7 +274,6 @@ 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,6 +435,7 @@ 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;
|
||||
|
||||
@@ -456,7 +457,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> 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);
|
||||
}
|
||||
@@ -598,6 +599,7 @@ QString formatNotifString (QPair<QString, QByteArray> property ,QByteArray value
|
||||
return text += "\n";
|
||||
}
|
||||
|
||||
|
||||
void rotateAndSaveImage(const QString &inputPath, const QString &outputPath, qreal angle)
|
||||
{
|
||||
QImage image(inputPath);
|
||||
|
||||
Reference in New Issue
Block a user