correction de notify()
This commit is contained in:
1 parent
f80313eaa5
commit
40c4c7fae3
1 file changed
+159
-160
+159
-160
@@ -5,12 +5,12 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <iostream>
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <QtHttpServer/QHttpServer>
|
#include <QtHttpServer/QHttpServer>
|
||||||
#include <QtHttpServer/QHttpServerRequest>
|
#include <QtHttpServer/QHttpServerRequest>
|
||||||
|
#include <QHttpServerResponse>
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
@@ -47,9 +47,9 @@ QMap <QByteArray, QPair<QString, QByteArray>> propertyName
|
|||||||
{"tempf", {"Température extérieure", "°C"}},
|
{"tempf", {"Température extérieure", "°C"}},
|
||||||
{"humidity", {"Humidité extérieure", "%"}},
|
{"humidity", {"Humidité extérieure", "%"}},
|
||||||
{"dewptf", {"Point de rosée", "°C"}},
|
{"dewptf", {"Point de rosée", "°C"}},
|
||||||
{"windchill", {"Température ressentie", "°C"}},
|
{"windchill", {"Température ressentie", "°C"}},
|
||||||
{"winddir", {"Direction du vent", "°"}},
|
{"winddir", {"Direction du vent", "°"}},
|
||||||
{"windspeedmph", {"Vitesse du vent", " km/h"}},
|
{"windspeedmph", {"Vitesse du vent", " km/h"}},
|
||||||
{"windgustmph", {"Rafales", " km/h"}},
|
{"windgustmph", {"Rafales", " km/h"}},
|
||||||
{"rainin", {"Pluie", " mm/h"}},
|
{"rainin", {"Pluie", " mm/h"}},
|
||||||
{"dailyrainin", {"Pluie de la journée", " mm"}},
|
{"dailyrainin", {"Pluie de la journée", " mm"}},
|
||||||
@@ -58,7 +58,7 @@ QMap <QByteArray, QPair<QString, QByteArray>> propertyName
|
|||||||
// {"solarradiation", {"Énergie solaire", " W/m²"}},
|
// {"solarradiation", {"Énergie solaire", " W/m²"}},
|
||||||
// {"indoortempf", {"Température intérieure", "°C"}},
|
// {"indoortempf", {"Température intérieure", "°C"}},
|
||||||
// {"indoorhumidity", {"Humidité intérieure", "%"}},
|
// {"indoorhumidity", {"Humidité intérieure", "%"}},
|
||||||
{"baromin", {"Pression atmosphérique", " hPa"}},
|
{"baromin", {"Pression atmosphérique", " hPa"}},
|
||||||
// {"lowbatt", {"Alerte batterie faible", ""}},
|
// {"lowbatt", {"Alerte batterie faible", ""}},
|
||||||
{"UV", {"Alerte UV", ""}}
|
{"UV", {"Alerte UV", ""}}
|
||||||
};
|
};
|
||||||
@@ -74,7 +74,7 @@ QList <QList <QVariant>> forceVent
|
|||||||
{38, "Bonne brise", 1},
|
{38, "Bonne brise", 1},
|
||||||
{49, "Vent frais", 3},
|
{49, "Vent frais", 3},
|
||||||
{61, "Grand vent", 4},
|
{61, "Grand vent", 4},
|
||||||
{74, "Vent fort", 4},
|
{74, "Vent fort", 4},
|
||||||
{88, "Vent violent", 5},
|
{88, "Vent violent", 5},
|
||||||
{117, "Tempête", 5},
|
{117, "Tempête", 5},
|
||||||
{1000, "Ouragan", 5}
|
{1000, "Ouragan", 5}
|
||||||
@@ -92,17 +92,15 @@ Pws2mqtt::~Pws2mqtt()
|
|||||||
void Pws2mqtt::init()
|
void Pws2mqtt::init()
|
||||||
{
|
{
|
||||||
debug(DEBUGMACRO, "init http server", DEBUG);
|
debug(DEBUGMACRO, "init http server", DEBUG);
|
||||||
httpServer->setMissingHandler([](const QHttpServerRequest &request, QHttpServerResponder &&responder)
|
httpServer->setMissingHandler(httpServer,[](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");
|
||||||
});
|
});
|
||||||
@@ -126,18 +124,19 @@ void Pws2mqtt::init()
|
|||||||
|
|
||||||
return QHttpServerResponse("text/plain", "Success\n");
|
return QHttpServerResponse("text/plain", "Success\n");
|
||||||
});
|
});
|
||||||
for (auto [name, pair]: propertyName.asKeyValueRange())
|
for (auto [name, pair]: propertyName.asKeyValueRange())
|
||||||
{
|
{
|
||||||
propertyList[name].append(formatNotifString(pair.first, pair.second, "0"));
|
propertyList[name].append(formatNotifString(pair.first, pair.second, "0"));
|
||||||
debug (DEBUGMACRO, "Init " + name + " => " + propertyList[name], DEBUG);
|
debug (DEBUGMACRO, "Init " + name + " => " + propertyList[name], DEBUG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pws2mqtt::listeningHttp()
|
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);
|
||||||
@@ -154,12 +153,12 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
QString notif = "";
|
QString notif = "";
|
||||||
QStringList priorityList {"", "min", "low", "default", "High", "urgent"};
|
QStringList priorityList {"", "min", "low", "default", "High", "urgent"};
|
||||||
QString attachment = "";
|
QString attachment = "";
|
||||||
QString tag = "";
|
QString tag = "";
|
||||||
quint8 priority = 2;
|
quint8 priority = 2;
|
||||||
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);
|
||||||
|
|
||||||
debug(DEBUGMACRO, "looping list of query", DEBUG);
|
debug(DEBUGMACRO, "looping list of query", DEBUG);
|
||||||
|
|
||||||
@@ -217,28 +216,28 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
//notif += formatNotifString (propertyName[name].first, propertyName[name].second , value);
|
//notif += formatNotifString (propertyName[name].first, propertyName[name].second , value);
|
||||||
propertyList[name] = formatNotifString(propertyName[name].first, propertyName[name].second, QByteArray::number(propertyValue));
|
propertyList[name] = formatNotifString(propertyName[name].first, propertyName[name].second, QByteArray::number(propertyValue));
|
||||||
propertiesValue[name] = propertyValue;
|
propertiesValue[name] = propertyValue;
|
||||||
}
|
}
|
||||||
}else if (name == "winddir")
|
}else if (name == "winddir")
|
||||||
{
|
{
|
||||||
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].first, propertyName[name].second, QByteArray::number(propertyValue));
|
propertyList[name] = formatNotifString(propertyName[name].first, propertyName[name].second, QByteArray::number(propertyValue));
|
||||||
propertiesValue[name] = propertyValue;
|
propertiesValue[name] = propertyValue;
|
||||||
}else if (name == "windspeedmph")
|
}else if (name == "windspeedmph")
|
||||||
{
|
{
|
||||||
QString msg = "";
|
QString msg = "";
|
||||||
quint8 i;
|
quint8 i;
|
||||||
static QDateTime timeWind = QDateTime::currentDateTime().addSecs(-600);
|
static QDateTime timeWind = QDateTime::currentDateTime().addSecs(-600);
|
||||||
quint8 windPriority = 1;
|
quint8 windPriority = 1;
|
||||||
|
|
||||||
propertiesValue["vent"] = round(mphTokmh(value.toFloat()));
|
propertiesValue["vent"] = round(mphTokmh(value.toFloat()));
|
||||||
|
|
||||||
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertiesValue["vent"]), DEBUG);
|
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertiesValue["vent"]), DEBUG);
|
||||||
|
|
||||||
for (i=0; i<forceVent.size();i++)
|
for (i=0; i<forceVent.size();i++)
|
||||||
{
|
{
|
||||||
if (propertiesValue["vent"] <= forceVent[i][0].toDouble())
|
if (propertiesValue["vent"] <= forceVent[i][0].toDouble())
|
||||||
{
|
{
|
||||||
msg = forceVent[i][1].toString();
|
msg = forceVent[i][1].toString();
|
||||||
windPriority = forceVent[i][2].toUInt();
|
windPriority = forceVent[i][2].toUInt();
|
||||||
@@ -246,35 +245,35 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
propertyList[name] = formatNotifString ("Vent - " + msg, propertyName[name].second , QByteArray::number(propertiesValue["vent"]));
|
propertyList[name] = formatNotifString ("Vent - " + msg, propertyName[name].second , QByteArray::number(propertiesValue["vent"]));
|
||||||
propertiesValue["forcevent"] = i;
|
propertiesValue["forcevent"] = i;
|
||||||
if (i >= 5)
|
if (i >= 5)
|
||||||
{
|
{
|
||||||
attachment = this->outputPath;
|
attachment = this->outputPath;
|
||||||
}
|
|
||||||
|
|
||||||
if (propertiesValue["forcevent"] != i)
|
|
||||||
{
|
|
||||||
priority = qMax(priority, windPriority);
|
|
||||||
}
|
}
|
||||||
debug (DEBUGMACRO, "priority = " + QString::number(priority), DEBUG);
|
|
||||||
}else if (name == "windgustmph")
|
|
||||||
{
|
|
||||||
QString msg = "";
|
|
||||||
static QDateTime timeWind = QDateTime::currentDateTime().addSecs(-600);
|
|
||||||
|
|
||||||
propertiesValue[name] = round(mphTokmh(value.toFloat()));
|
if (propertiesValue["forcevent"] != i)
|
||||||
|
{
|
||||||
|
priority = qMax(priority, windPriority);
|
||||||
|
}
|
||||||
|
debug (DEBUGMACRO, "priority = " + QString::number(priority), DEBUG);
|
||||||
|
}else if (name == "windgustmph")
|
||||||
|
{
|
||||||
|
QString msg = "";
|
||||||
|
static QDateTime timeWind = QDateTime::currentDateTime().addSecs(-600);
|
||||||
|
|
||||||
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertiesValue["rafale"]), DEBUG);
|
propertiesValue[name] = round(mphTokmh(value.toFloat()));
|
||||||
|
|
||||||
propertyList[name] = formatNotifString (propertyName[name].first, propertyName[name].second , QByteArray::number(propertiesValue[name]));
|
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertiesValue["rafale"]), DEBUG);
|
||||||
|
|
||||||
if (propertiesValue["rafales"] > 50)
|
propertyList[name] = formatNotifString (propertyName[name].first, propertyName[name].second , QByteArray::number(propertiesValue[name]));
|
||||||
{
|
|
||||||
priority = qMax(priority, (quint8)4);
|
if (propertiesValue["rafales"] > 50)
|
||||||
}
|
{
|
||||||
debug (DEBUGMACRO, "priority = " + QString::number(priority), DEBUG);
|
priority = qMax(priority, (quint8)4);
|
||||||
}else if (name == "rainin")
|
}
|
||||||
|
debug (DEBUGMACRO, "priority = " + QString::number(priority), DEBUG);
|
||||||
|
}else if (name == "rainin")
|
||||||
{
|
{
|
||||||
static double ecart;
|
static double ecart;
|
||||||
quint8 raininPriority = 1;
|
quint8 raininPriority = 1;
|
||||||
@@ -292,11 +291,11 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
QString pluviosite = getPluviosite(propertyValue, raininPriority);
|
QString pluviosite = getPluviosite(propertyValue, raininPriority);
|
||||||
priority = setPriority (priority, raininPriority);
|
priority = setPriority (priority, raininPriority);
|
||||||
//debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
|
//debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
|
||||||
propertyList[name] = formatNotifString(pluviosite, propertyName[name].second, QByteArray::number(propertyValue));
|
propertyList[name] = formatNotifString(pluviosite, propertyName[name].second, QByteArray::number(propertyValue));
|
||||||
propertiesValue[name] = propertyValue;
|
propertiesValue[name] = propertyValue;
|
||||||
}
|
}
|
||||||
debug (DEBUGMACRO, "priority = " + QString::number(priority), DEBUG);
|
debug (DEBUGMACRO, "priority = " + QString::number(priority), DEBUG);
|
||||||
}else if (name == "dailyrainin")
|
}else if (name == "dailyrainin")
|
||||||
{
|
{
|
||||||
static double ecart;
|
static double ecart;
|
||||||
propertyValue = round(pair.second.toFloat()*100)/100;
|
propertyValue = round(pair.second.toFloat()*100)/100;
|
||||||
@@ -310,37 +309,37 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
|
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
|
||||||
if (compare (propertiesValue[name], propertyValue, ecart))
|
if (compare (propertiesValue[name], propertyValue, ecart))
|
||||||
{
|
{
|
||||||
//priority = setPriority (priority, 3);
|
//priority = setPriority (priority, 3);
|
||||||
//debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
|
//debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
|
||||||
propertyList[name] = formatNotifString(propertyName[name].first, propertyName[name].second, QByteArray::number(propertyValue));
|
propertyList[name] = formatNotifString(propertyName[name].first, propertyName[name].second, QByteArray::number(propertyValue));
|
||||||
propertiesValue[name] = propertyValue;
|
propertiesValue[name] = propertyValue;
|
||||||
}
|
}
|
||||||
debug (DEBUGMACRO, "priority = " + QString::number(priority), DEBUG);
|
debug (DEBUGMACRO, "priority = " + QString::number(priority), DEBUG);
|
||||||
}else if (name == "baromin")
|
}else if (name == "baromin")
|
||||||
{
|
{
|
||||||
//static QDateTime timePrevision = QDateTime::currentDateTime().addSecs(-1000);
|
//static QDateTime timePrevision = QDateTime::currentDateTime().addSecs(-1000);
|
||||||
|
|
||||||
propertyValue = round(tohPa(pair.second.toFloat()) * 100) / 100;
|
propertyValue = round(tohPa(pair.second.toFloat()) * 100) / 100;
|
||||||
debug (DEBUGMACRO, "Barometre en hPa : " + QByteArray::number(propertyValue), DEBUG);
|
debug (DEBUGMACRO, "Barometre en hPa : " + QByteArray::number(propertyValue), DEBUG);
|
||||||
baro->addPressure(propertyValue);
|
baro->addPressure(propertyValue);
|
||||||
propertyList[name] = formatNotifString(propertyName[name].first, "", QByteArray::number(propertyValue));
|
propertyList[name] = formatNotifString(propertyName[name].first, "", QByteArray::number(propertyValue));
|
||||||
propertiesValue[name] = propertyValue;
|
propertiesValue[name] = propertyValue;
|
||||||
|
|
||||||
static QString prevision;
|
static QString prevision;
|
||||||
auto ret = baro->forecast(propertiesValue["tempf"], propertiesValue["humidity"]);
|
auto ret = baro->forecast(propertiesValue["tempf"], propertiesValue["humidity"]);
|
||||||
|
|
||||||
prevision = ret.message;
|
prevision = ret.message;
|
||||||
//if (prevision != newPrevision)
|
//if (prevision != newPrevision)
|
||||||
//{
|
//{
|
||||||
priority = setPriority(priority, ret.urgency);
|
priority = setPriority(priority, ret.urgency);
|
||||||
tag += ret.icons;
|
tag += ret.icons;
|
||||||
|
|
||||||
propertyList["prevision"] = prevision;
|
propertyList["prevision"] = prevision;
|
||||||
debug (DEBUGMACRO, "priority = " + QString::number(priority), DEBUG);
|
debug (DEBUGMACRO, "priority = " + QString::number(priority), DEBUG);
|
||||||
}else if (name == "UV")
|
}else if (name == "UV")
|
||||||
{
|
{
|
||||||
static QDateTime timeUV = QDateTime::currentDateTime().addSecs(-600);
|
static QDateTime timeUV = QDateTime::currentDateTime().addSecs(-600);
|
||||||
propertyValue = pair.second.toUInt();
|
propertyValue = pair.second.toUInt();
|
||||||
|
|
||||||
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
|
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
|
||||||
if (compare (propertiesValue[name], propertyValue, 1) and timeUV < QDateTime::currentDateTime())
|
if (compare (propertiesValue[name], propertyValue, 1) and timeUV < QDateTime::currentDateTime())
|
||||||
@@ -353,20 +352,20 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
timeUV = timeUV.currentDateTime().addSecs(300);
|
timeUV = timeUV.currentDateTime().addSecs(300);
|
||||||
propertiesValue[name] = propertyValue;
|
propertiesValue[name] = propertyValue;
|
||||||
debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
|
debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
|
||||||
propertyList[name] = formatNotifString(propertyName[name].first, "", QByteArray::number(propertyValue));
|
propertyList[name] = formatNotifString(propertyName[name].first, "", QByteArray::number(propertyValue));
|
||||||
}
|
}
|
||||||
debug (DEBUGMACRO, "priority = " + QString::number(priority), DEBUG);
|
debug (DEBUGMACRO, "priority = " + QString::number(priority), DEBUG);
|
||||||
|
|
||||||
}else if (name == "solarradiation")
|
}else if (name == "solarradiation")
|
||||||
{
|
{
|
||||||
propertiesValue[name] = round(pair.second.toFloat()*100/100);
|
propertiesValue[name] = round(pair.second.toFloat()*100/100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
propertiesValue["windchill"] = calc.computeUTCI(propertiesValue["tempf"], propertiesValue["vent"], propertiesValue["solarradiation"], propertiesValue["humidity"]);
|
propertiesValue["windchill"] = calc.computeUTCI(propertiesValue["tempf"], propertiesValue["vent"], propertiesValue["solarradiation"], propertiesValue["humidity"]);
|
||||||
propertyList["windchill"] = formatNotifString(propertyName["windchill"].first, propertyName["windchill"].second, QByteArray::number(propertiesValue["windchill"]));
|
propertyList["windchill"] = formatNotifString(propertyName["windchill"].first, propertyName["windchill"].second, QByteArray::number(propertiesValue["windchill"]));
|
||||||
//windChill(propertiesValue["tempf"], propertiesValue["vent"]);
|
//windChill(propertiesValue["tempf"], propertiesValue["vent"]);
|
||||||
//calculerHumidex(propertiesValue["tempf"], propertiesValue["humidity"]);
|
//calculerHumidex(propertiesValue["tempf"], propertiesValue["humidity"]);
|
||||||
|
|
||||||
if (!jsonString.isEmpty())
|
if (!jsonString.isEmpty())
|
||||||
{
|
{
|
||||||
@@ -380,66 +379,66 @@ 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);
|
||||||
|
|
||||||
if (priority > 3 or QDateTime::currentDateTime() > timer.addSecs(1800))
|
if (priority > 3 or QDateTime::currentDateTime() > timer.addSecs(1800))
|
||||||
{
|
{
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
timer = QDateTime::currentDateTime();
|
timer = QDateTime::currentDateTime();
|
||||||
debug(DEBUGMACRO, "looping to fill notif, priority = " + QString::number(priority), DEBUG);
|
debug(DEBUGMACRO, "looping to fill notif, priority = " + QString::number(priority), DEBUG);
|
||||||
|
|
||||||
if (precPropertyList.size() == 0)
|
if (precPropertyList.size() == 0)
|
||||||
{
|
{
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
for (auto [name, value]: propertyList.asKeyValueRange())
|
for (auto [name, value]: propertyList.asKeyValueRange())
|
||||||
{
|
{
|
||||||
if (precPropertyList.contains(name))
|
if (precPropertyList.contains(name))
|
||||||
{
|
{
|
||||||
if (precPropertyList[name] != propertyList[name])
|
if (precPropertyList[name] != propertyList[name])
|
||||||
{
|
{
|
||||||
debug(DEBUGMACRO, "changed = true", DEBUG);
|
debug(DEBUGMACRO, "changed = true", DEBUG);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(DEBUGMACRO, "Name = " + name + ", value = " + value, DEBUG);
|
debug(DEBUGMACRO, "Name = " + name + ", value = " + value, DEBUG);
|
||||||
if (! (name == "prevision"))
|
if (! (name == "prevision"))
|
||||||
{
|
{
|
||||||
notif += propertyList[name];
|
notif += propertyList[name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (changed)
|
if (changed)
|
||||||
{
|
{
|
||||||
notify (notif, priorityList[priority], attachment, tag);
|
notify (notif, priorityList[priority], attachment, tag);
|
||||||
precPropertyList = propertyList;
|
precPropertyList = propertyList;
|
||||||
}
|
}
|
||||||
|
|
||||||
notif = "**Prévisions à 12/24h**\n" + propertyList["prevision"];
|
notif = "**Prévisions à 12/24h**\n" + propertyList["prevision"];
|
||||||
notify (notif, priorityList[priority], attachment, tag);
|
notify (notif, priorityList[priority], attachment, tag);
|
||||||
debug(DEBUGMACRO, "calling notify with notif = #" + notif + "#", DEBUG);
|
debug(DEBUGMACRO, "calling notify with notif = #" + notif + "#", DEBUG);
|
||||||
|
|
||||||
}
|
}
|
||||||
debug(DEBUGMACRO, "parseData: Returning", DEBUG);
|
debug(DEBUGMACRO, "parseData: Returning", DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
double calculerUTCI(double temperature, double humiditeRelative, double vitesseVent, double rayonnement)
|
double calculerUTCI(double temperature, double humiditeRelative, double vitesseVent, double rayonnement)
|
||||||
{
|
{
|
||||||
double e = (humiditeRelative / 100.0) * 6.105 * exp((17.27 * temperature) / (237.7 + temperature));
|
double e = (humiditeRelative / 100.0) * 6.105 * exp((17.27 * temperature) / (237.7 + temperature));
|
||||||
debug(DEBUGMACRO, "UTCI => e = " + QString::number(e), DEBUG);
|
debug(DEBUGMACRO, "UTCI => e = " + QString::number(e), DEBUG);
|
||||||
double V = vitesseVent * 5.0 / 18.0; // Vitesse du vent en m/s
|
double V = vitesseVent * 5.0 / 18.0; // Vitesse du vent en m/s
|
||||||
debug(DEBUGMACRO, "UTCI => V = " + QString::number(V), DEBUG);
|
debug(DEBUGMACRO, "UTCI => V = " + QString::number(V), DEBUG);
|
||||||
|
|
||||||
double utci = temperature +
|
double utci = temperature +
|
||||||
(0.607562 + 0.022437 * e + 7.3869e-4 * temperature * e - 3.5582e-6 * temperature * temperature * e) +
|
(0.607562 + 0.022437 * e + 7.3869e-4 * temperature * e - 3.5582e-6 * temperature * temperature * e) +
|
||||||
(-11.4 + 0.11 * temperature + 0.55 * V) +
|
(-11.4 + 0.11 * temperature + 0.55 * V) +
|
||||||
(0.0023 * temperature * temperature - 0.118 * V - 0.0014 * temperature * V);
|
(0.0023 * temperature * temperature - 0.118 * V - 0.0014 * temperature * V);
|
||||||
debug(DEBUGMACRO, "UTCI = " + QString::number(utci), DEBUG);
|
debug(DEBUGMACRO, "UTCI = " + QString::number(utci), DEBUG);
|
||||||
|
|
||||||
// Ajustement simplifié pour le rayonnement
|
// Ajustement simplifié pour le rayonnement
|
||||||
double ref = 200.0; // Rayonnement de référence (W/m²)
|
double ref = 200.0; // Rayonnement de référence (W/m²)
|
||||||
double k = 0.02; // Coefficient empirique
|
double k = 0.02; // Coefficient empirique
|
||||||
utci = utci + k * (rayonnement - ref);
|
utci = utci + k * (rayonnement - ref);
|
||||||
debug(DEBUGMACRO, "UTCI = " + QString::number(utci), DEBUG);
|
debug(DEBUGMACRO, "UTCI = " + QString::number(utci), DEBUG);
|
||||||
return round(utci * 100) / 100;
|
return round(utci * 100) / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString getPluviosite(double value, quint8 &priority)
|
QString getPluviosite(double value, quint8 &priority)
|
||||||
@@ -509,13 +508,13 @@ bool compare (double value, double currentValue, double ecart)
|
|||||||
|
|
||||||
QString formatNotifString (QString name, QString unit ,QByteArray value)
|
QString formatNotifString (QString name, QString unit ,QByteArray value)
|
||||||
{
|
{
|
||||||
QString text = "- " + name + " : " + value;
|
QString text = "- " + name + " : " + value;
|
||||||
if (!unit.isEmpty())
|
if (!unit.isEmpty())
|
||||||
{
|
{
|
||||||
text += unit;
|
text += unit;
|
||||||
//"- " + propertyName[name].first + " : " + value + " " + propertyName[name].second + " ";
|
//"- " + propertyName[name].first + " : " + value + " " + propertyName[name].second + " ";
|
||||||
}
|
}
|
||||||
return text += "\n";
|
return text += "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t ReadFile(void *ptr, size_t size, size_t nmemb, void *stream) {
|
static size_t ReadFile(void *ptr, size_t size, size_t nmemb, void *stream) {
|
||||||
@@ -527,9 +526,9 @@ static size_t ReadFile(void *ptr, size_t size, size_t nmemb, void *stream) {
|
|||||||
// Callback for curl library
|
// Callback for curl library
|
||||||
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, std::string *output)
|
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, std::string *output)
|
||||||
{
|
{
|
||||||
size_t total_size = size * nmemb;
|
size_t total_size = size * nmemb;
|
||||||
output->append((char*)contents, total_size);
|
output->append((char*)contents, total_size);
|
||||||
return total_size;
|
return total_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void notify(QString notif, QString priority, QString inputPath, QString tag)
|
void notify(QString notif, QString priority, QString inputPath, QString tag)
|
||||||
@@ -539,35 +538,35 @@ void notify(QString notif, QString priority, QString inputPath, QString tag)
|
|||||||
std::string readBuffer;
|
std::string readBuffer;
|
||||||
|
|
||||||
priority = "Priority: " + priority;
|
priority = "Priority: " + priority;
|
||||||
debug (DEBUGMACRO, "notifying at priority " + priority + "with tag : " + tag + " - message : " + notif, DEBUG);
|
debug (DEBUGMACRO, "notifying at priority " + priority + "with tag : " + tag + " - message : " + notif, DEBUG);
|
||||||
|
|
||||||
// Initialise libcurl
|
// Initialise libcurl
|
||||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
if (curl)
|
if (curl)
|
||||||
{
|
{
|
||||||
// Définis les en-têtes pour le titre et les priorités
|
// Définis les en-têtes pour le titre et les priorités
|
||||||
struct curl_slist *headers = NULL;
|
struct curl_slist *headers = NULL;
|
||||||
|
|
||||||
notif.replace("\\", "\\\\\\'"); // Échappe les apostrophes
|
notif.replace("\\", "\\\\\\'"); // Échappe les apostrophes
|
||||||
|
|
||||||
if (!tag.isEmpty())
|
if (!tag.isEmpty())
|
||||||
{
|
{
|
||||||
headers = curl_slist_append(headers, ("Tags: " + tag).toStdString().c_str());
|
headers = curl_slist_append(headers, ("Tags: " + tag).toStdString().c_str());
|
||||||
}
|
}
|
||||||
headers = curl_slist_append(headers, "Title: Météo");
|
headers = curl_slist_append(headers, "Title: Météo");
|
||||||
headers = curl_slist_append(headers, priority.toStdString().c_str());
|
headers = curl_slist_append(headers, priority.toStdString().c_str());
|
||||||
headers = curl_slist_append(headers, "Markdown: yes");
|
headers = curl_slist_append(headers, "Markdown: yes");
|
||||||
// headers = curl_slist_append(headers, "Config: /etc/ntfy.client.yml");
|
// headers = curl_slist_append(headers, "Config: /etc/ntfy.client.yml");
|
||||||
headers = curl_slist_append(headers, "Firebase: no");
|
headers = curl_slist_append(headers, "Firebase: no");
|
||||||
// headers = curl_slist_append(headers, "Content-Type: charset=UTF-8; text/markdown"); // Ajout de l'encodage
|
// headers = curl_slist_append(headers, "Content-Type: charset=UTF-8; text/markdown"); // Ajout de l'encodage
|
||||||
|
|
||||||
struct curl_slist *h = headers;
|
struct curl_slist *h = headers;
|
||||||
while (h) {
|
while (h) {
|
||||||
debug(DEBUGMACRO, "Header: " + QString(h->data), DEBUG);
|
debug(DEBUGMACRO, "Header: " + QString(h->data), DEBUG);
|
||||||
h = h->next;
|
h = h->next;
|
||||||
}
|
}
|
||||||
debug(DEBUGMACRO, "Notif: " + notif, DEBUG);
|
debug(DEBUGMACRO, "Notif: " + notif, DEBUG);
|
||||||
|
|
||||||
// Configure la requête POST
|
// Configure la requête POST
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:81/Meteo");
|
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:81/Meteo");
|
||||||
@@ -575,11 +574,11 @@ void notify(QString notif, QString priority, QString inputPath, QString tag)
|
|||||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, notif.toUtf8().constData());
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, notif.toUtf8().constData());
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
|
||||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||||
|
|
||||||
// Exécute la requête
|
// Exécute la requête
|
||||||
|
|
||||||
res = curl_easy_perform(curl);
|
res = curl_easy_perform(curl);
|
||||||
|
|
||||||
// Vérifie les erreurs
|
// Vérifie les erreurs
|
||||||
if (res != CURLE_OK)
|
if (res != CURLE_OK)
|
||||||
@@ -587,7 +586,7 @@ void notify(QString notif, QString priority, QString inputPath, QString tag)
|
|||||||
debug(DEBUGMACRO, "Erreur libcurl :" + QString(curl_easy_strerror(res)), DEBUG);
|
debug(DEBUGMACRO, "Erreur libcurl :" + QString(curl_easy_strerror(res)), DEBUG);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
debug(DEBUGMACRO, "Réponse du serveur: " + QString::fromStdString(readBuffer), DEBUG);
|
debug(DEBUGMACRO, "Réponse du serveur: " + QString::fromStdString(readBuffer), DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nettoie les ressources
|
// Nettoie les ressources
|
||||||
|
|||||||
Reference in new issue
Block a user