temperature avec 1 décimale
This commit is contained in:
1 parent
1da315cf2e
commit
4950608291
1 file changed
+15
-13
+15
-13
@@ -2,6 +2,7 @@
|
|||||||
#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>
|
||||||
@@ -9,7 +10,6 @@
|
|||||||
#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,15 +90,17 @@ 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);
|
||||||
//responder.write(QHttpServerResponse(QString("404 - Page non trouvée. Route par défaut."), QHttpServerResponse::StatusCode::NotFound));
|
return 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);
|
//responder.write(QHttpServerResponse("404 - Page non trouvée. Route par défaut.", 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");
|
||||||
});
|
});
|
||||||
@@ -152,7 +154,7 @@ void notify(QString notif, QString priority, QString inputPath, QString tag)
|
|||||||
request.setRawHeader("Firebase", "no");
|
request.setRawHeader("Firebase", "no");
|
||||||
|
|
||||||
QNetworkReply *reply = manager->post(request, notif.toUtf8());
|
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)
|
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);
|
debug(DEBUGMACRO, "Notification envoyée", INFO);
|
||||||
}
|
}
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
});
|
|
||||||
delete(manager);
|
delete(manager);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -171,8 +173,7 @@ void Pws2mqtt::listeningHttp()
|
|||||||
{
|
{
|
||||||
//QByteArray data;
|
//QByteArray data;
|
||||||
debug (DEBUGMACRO, "listening http requests", DEBUG);
|
debug (DEBUGMACRO, "listening http requests", DEBUG);
|
||||||
QTcpServer *tcpServer = new QTcpServer(this);
|
const auto port = httpServer->listen(QHostAddress::Any, 5000);
|
||||||
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);
|
||||||
@@ -192,12 +193,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);
|
||||||
|
|
||||||
@@ -239,7 +240,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
if (name == "tempf")
|
if (name == "tempf")
|
||||||
{
|
{
|
||||||
static QDateTime timeTemp = QDateTime::currentDateTime().addSecs(-600);
|
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);
|
debug (DEBUGMACRO, "timeTemp = " + timeTemp.time().toString() + " - current :" + QDateTime::currentDateTime().toString() , DEBUG);
|
||||||
|
|
||||||
if (compare (propertiesValue[name], propertyValue, 1) and timeTemp < QDateTime::currentDateTime())
|
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();
|
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,6 +435,7 @@ 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;
|
||||||
|
|
||||||
@@ -598,6 +599,7 @@ 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