coorections après fusion

This commit is contained in:
2026-04-13 17:07:35 +02:00
7 changed files with 722 additions and 860 deletions
+3 -3
View File
@@ -15,7 +15,7 @@ CONFIG -= app_bundle
SOURCES += \ SOURCES += \
src/main.cpp \ src/main.cpp \
src/mqtt.cpp \ # src/mqtt.cpp \
src/pws2mqtt.cpp \ src/pws2mqtt.cpp \
src/utcicalculator.cpp src/utcicalculator.cpp
@@ -26,8 +26,8 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
HEADERS += \ HEADERS += \
src/barometertrend.h \ src/barometertrend.h \
src/httpserver.h \ #src/httpserver.h \
src/mqtt.h \ # src/mqtt.h \
src/pws2mqtt.h \ src/pws2mqtt.h \
src/utcicalculator.h \ src/utcicalculator.h \
src/version.h src/version.h
+33 -14
View File
@@ -157,49 +157,55 @@ public:
r.urgency = 0; r.urgency = 0;
icons << "sunny"; icons << "sunny";
debug(DEBUGMACRO, "message : " + r.message, DEBUG); debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p >= 1020 && d3 < -3.0) }else if (p >= 1020 && (d3 <= +1.0 && d3 >= -1.0))
{
r.message = "- Beau temps stable";
r.urgency = 0;
icons << "sunny";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p >= 1015 && d3 < -3.0)
{ {
r.message = "- Beau, mais rapide dégradation"; r.message = "- Beau, mais rapide dégradation";
r.urgency = 4; r.urgency = 4;
icons << "sun_behind_large_cloud"; icons << "sun_behind_large_cloud";
debug(DEBUGMACRO, "message : " + r.message, DEBUG); debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p >= 1020 && d3 < -1.0) }else if (p >= 1015 && d3 < -1.0)
{ {
r.message = "- Beau, mais possible dégradation"; r.message = "- Beau, mais possible dégradation";
r.urgency = 1; r.urgency = 1;
icons << "sun_behind_small_cloud"; icons << "sun_behind_small_cloud";
debug(DEBUGMACRO, "message : " + r.message, DEBUG); debug(DEBUGMACRO, "message : " + r.message, DEBUG);
/*}else if (p >= 1020 && d3 < 0.5.0) }else if (p >= 1015 && (d3 <= 1.0 && d3 >= -1.0))
{ {
r.message = "- Beau temps"; r.message = "- Beau temps stable";
r.urgency = 0; r.urgency = 0;
icons << "sunny"; icons << "sunny";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);*/ debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p >= 1010 && d3 >= +3.0) }else if (p >= 1005 && d3 >= +3.0)
{ {
r.message = "- Nuageux, rapide amélioration"; r.message = "- Nuageux, rapide amélioration";
r.urgency = 4; r.urgency = 4;
icons << "sun_behind_small_cloud"; icons << "sun_behind_small_cloud";
debug(DEBUGMACRO, "message : " + r.message, DEBUG); debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p >= 1010 && d3 >= +1.0) }else if (p >= 1005 && d3 >= +1.0)
{ {
r.message = "- Nuageux, en amélioration"; r.message = "- Nuageux, en amélioration";
r.urgency = 0; r.urgency = 0;
icons << "sun_behind_large_cloud"; icons << "sun_behind_large_cloud";
debug(DEBUGMACRO, "message : " + r.message, DEBUG); debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p >= 1010 && d3 <= -3.0) }else if (p >= 1005 && d3 <= -3.0)
{ {
r.message = "- Nuageux, fort risque de pluie ou vent"; r.message = "- Nuageux, fort risque de pluie ou vent";
r.urgency = 4; r.urgency = 4;
icons << "sun_behind_rain_cloud"; icons << "sun_behind_rain_cloud";
debug(DEBUGMACRO, "message : " + r.message, DEBUG); debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p >= 1010 && d3 <= -1.0) }else if (p >= 1005 && d3 <= -1.0)
{ {
r.message = "- nuageux, risque de pluie ou vent"; r.message = "- nuageux, risque de pluie ou vent";
r.urgency = 2; r.urgency = 2;
icons << "sun_behind_rain_cloud"; icons << "sun_behind_rain_cloud";
debug(DEBUGMACRO, "message : " + r.message, DEBUG); debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p >= 1010 && d3 <= 0.5) }else if (p >= 1005 && (d3 <= 1.0 && d3 >= 1.0))
{ {
r.message = "- Nuageux avec des éclaircies"; r.message = "- Nuageux avec des éclaircies";
r.urgency = 2; r.urgency = 2;
@@ -229,6 +235,12 @@ public:
r.urgency = 2; r.urgency = 2;
icons << "cloud_with_rain"; icons << "cloud_with_rain";
debug(DEBUGMACRO, "message : " + r.message, DEBUG); debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p >= 1000 && (d3 <= 1.0 && d3 >= -1.0))
{
r.message = "- Pluie ou perturbation stable";
r.urgency = 2;
icons << "cloud_with_rain";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p < 1000 && d3 >= +3.0) }else if (p < 1000 && d3 >= +3.0)
{ {
r.message = "- Pluie avec accalmie temporaire, amélioration rapide"; r.message = "- Pluie avec accalmie temporaire, amélioration rapide";
@@ -247,13 +259,20 @@ public:
r.urgency = 4; r.urgency = 4;
icons << "cloud_with_rain"; icons << "cloud_with_rain";
debug(DEBUGMACRO, "message : " + r.message, DEBUG); debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p < 1000 && (d3 <= 1.0 && d3 >= -1.0))
{
r.message = "- Mauvais temps stable";
r.urgency = 4;
icons << "cloud_with_rain";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
} }
if (qAbs(d3) < 1)
/*if (qAbs(d3) < 1)
{ {
r.message += "- Stable, pas de changement significatif"; r.message += "- Stable, pas de changement significatif";
r.urgency = 0; r.urgency = 0;
debug(DEBUGMACRO, "message : " + r.message, DEBUG); debug(DEBUGMACRO, "message : " + r.message, DEBUG);
} }*/
// Risque de neige // Risque de neige
if (p < 1000 && d3 < -1.0 && temperatureC <= 1.0 && humidityPercent > 80.0) if (p < 1000 && d3 < -1.0 && temperatureC <= 1.0 && humidityPercent > 80.0)
@@ -270,7 +289,7 @@ public:
{ {
r.rainRisk = true; r.rainRisk = true;
r.message += "- Risque de pluie"; r.message += "- Risque de pluie";
r.urgency = qMax(r.urgency, 2); r.urgency = qMax(r.urgency, 3);
icons << "cloud_with_rain"; icons << "cloud_with_rain";
debug(DEBUGMACRO, "message : " + r.message, DEBUG); debug(DEBUGMACRO, "message : " + r.message, DEBUG);
} }
@@ -308,7 +327,7 @@ public:
if (d <= -1.5 && p < 1010 && humidityPercent > 80.0) if (d <= -1.5 && p < 1010 && humidityPercent > 80.0)
{ {
r.prevision1h = "- Pluie probable dans l'heure"; r.prevision1h = "- Pluie probable dans l'heure";
r.urgency = qMax(r.urgency, 4); r.urgency = qMax(r.urgency, 3);
r.confiance = 80; r.confiance = 80;
}else if (d >= +1.5 && p > 1015) }else if (d >= +1.5 && p > 1015)
{ {
+26 -45
View File
@@ -1,41 +1,39 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QString> #include <QString>
//#include <QObject> //#include <unistd.h>
#include <unistd.h>
#include <QtGlobal> #include <QtGlobal>
#include <iostream> //#include <iostream>
#include <QDebug> //#include <QDebug>
#include <sys/socket.h> #include <qhttpserver.h>
#include <netinet/in.h> #include <QHttpServerResponse>
#include "pws2mqtt.h"
#ifdef WITH_MQTT
#include "mqtt.h"
#endif
#include "src/barometertrend.h"
#include "version.h"
//#include <sys/types.h>
//#include <sys/select.h>
#ifdef WITH_MQTT
#include <QtMqtt> #include <QtMqtt>
#include <QtMqtt/QMqttClient> #include <QtMqtt/QMqttClient>
#include <QtMqtt/QMqttMessage> #include <QtMqtt/QMqttMessage>
#include <QtMqtt/QMqttSubscription> #include <QtMqtt/QMqttSubscription>
#include <qhttpserver.h> #endif
#include <QHttpServerResponse>
#include "pws2mqtt.h"
#include "mqtt.h"
#include "src/barometertrend.h"
#include "version.h"
#include <curl/curl.h>
#include <sys/types.h>
#include <sys/select.h>
#include <sys/socket.h>
#define CLIENT_ID "Client_ID" #define CLIENT_ID "Client_ID"
#define BROKER_ADDRESS "localhost"
#define MQTT_PORT 1883;
uint debugLevel = DEBUG | INFO | NOTICE | INFO | WARNING | ERROR | ALERT; uint debugLevel = INFO | ERROR | ALERT;
QByteArray toFollow; QByteArray toFollow;
//class MqttClient; #ifdef WITH_MQTT
class MqttClient;
MqttClient *mqttClient;
#endif
using namespace std; using namespace std;
//Configuration config; //Configuration config;
Pws2mqtt *pws2mqtt; Pws2mqtt *pws2mqtt;
MqttClient *mqttClient;
QHttpServer *httpServer; QHttpServer *httpServer;
BarometerTrend *baro; BarometerTrend *baro;
@@ -54,9 +52,10 @@ int main(int argc, char *argv[])
// Enable logging to journald // Enable logging to journald
qputenv("QT_FORCE_STDERR_LOGGING", QByteArray("0")); qputenv("QT_FORCE_STDERR_LOGGING", QByteArray("0"));
debug(DEBUGMACRO, "declaration of mqttClient", DEBUG); #ifdef WITH_MQTT
debug(DEBUGMACRO, "declaration of mqttClient", INFO);
mqttClient = new MqttClient; mqttClient = new MqttClient;
#endif
httpServer = new QHttpServer; httpServer = new QHttpServer;
//declaration of debug level //declaration of debug level
@@ -65,34 +64,16 @@ int main(int argc, char *argv[])
pws2mqtt->listeningHttp(); pws2mqtt->listeningHttp();
//notify (QString("Program started"), "default");
a.exec(); a.exec();
#ifdef WITH_MQTT
mqttClient->qmqttClient->unsubscribe(mqttClient->topic); mqttClient->qmqttClient->unsubscribe(mqttClient->topic);
mqttClient->qmqttClient->disconnectFromHost(); mqttClient->qmqttClient->disconnectFromHost();
debug(DEBUGMACRO, "exiting", DEBUG); #endif
debug(DEBUGMACRO, "exiting", INFO);
notify ("Program exiting \n", "high"); notify ("Program exiting \n", "high");
//Closing http server
} }
/*QString addValue(QByteArray value)
{
bool ok;
QString str;
value.toFloat(&ok);
if (ok)
{
str = (value);
}else
{
str = ("\"" + value + "\"" );
}
return str;
}*/
void debug(QString debugHeader, QString msg, uint8_t level, QByteArray property) void debug(QString debugHeader, QString msg, uint8_t level, QByteArray property)
{ {
-57
View File
@@ -11,63 +11,6 @@
#define MQTT_TOPIC "pws2mqtt" #define MQTT_TOPIC "pws2mqtt"
/*{128, "Unspecified error: The Server does not wish to reveal the reason for the failure, or none of the other Reason Codes apply."},
{129, "Malformed Packet; Data within the CONNECT packet could not be correctly parsed."},
{130, "Protocol Error: Data in the CONNECT packet does not conform to this specification."},
{131, "Implementation specific error: The CONNECT is valid but is not accepted by this Server."},
{132, "Unsupported Protocol Version: The Server does not support the version of the MQTT protocol requested by the Client."},
{133, "Client Identifier not valid: The Client Identifier is a valid string but is not allowed by the Server."},
{134, "Bad User Name or Password: The Server does not accept the User Name or Password specified by the Client."},
{135, "Not authorized: The Client is not authorized to connect."},
{136, "Server unavailable: The MQTT Server is not available."},
{137, "Server busy: The Server is busy. Try again later."},
{138, "Banned: This Client has been banned by administrative action. Contact the server administrator."},
{140, "Bad authentication method: The authentication method is not supported or does not match the authentication method currently in use."},
{144, "Topic Name invalid: The Will Topic Name is not malformed, but is not accepted by this Server."},
{149, "Packet too large: The CONNECT packet exceeded the maximum permissible size."},
{151, "Quota exceeded: An implementation or administrative imposed limit has been exceeded."},
{153, "Payload format invalid: The Will Payload does not match the specified Payload Format Indicator."},
{154, "Retain not supported: The Server does not support retained messages, and Will Retain was set to 1."},
{155, "QoS not supported: The Server does not support the QoS set in Will QoS."},
{156, "Use another server: The Client should temporarily use another server."},
{157, "Server moved: The Client should permanently use another server."},
{159, "Connection rate exceeded: The connection rate limit has been exceeded."},
QHash <int, QString> mosq_error
{
{MOSQ_ERR_ERRNO, "System return error"},
{MOSQ_ERR_INVAL, "Input parameters were invalid."},
{MOSQ_ERR_NOMEM, "Out of memory condition occurred."},
{MOSQ_ERR_PAYLOAD_SIZE, "Payloadlen is too large."},
{MOSQ_ERR_MALFORMED_UTF8, "The topic is not valid UTF-8."},
{MOSQ_ERR_NOT_SUPPORTED, "Properties is not NULL and the client is not using MQTT v5"},
{MOSQ_ERR_NO_CONN, "if the client isnt connected to a broker."},
{MOSQ_ERR_DUPLICATE_PROPERTY, "A property is duplicated where it is forbidden."},
{MOSQ_ERR_PROTOCOL, "Any property is invalid for use with DISCONNECT."},
{MOSQ_ERR_QOS_NOT_SUPPORTED, "The QoS is greater than that supported by the broker."},
{MOSQ_ERR_OVERSIZE_PACKET, "The resulting packet would be larger than supported by the broker."},
{MOSQ_ERR_CONN_LOST, "The connection to the broker was lost."},
{MOSQ_ERR_PROTOCOL, "There is a protocol error communicating with the broker."},
};
*/
/*class MqttSub : public QMqttSubscription
{
Q_OBJECT;
public:
explicit MqttSub();
~MqttSub();
public slots:
void updateStatus({ , "SubscriptionState state);
};*/
class MqttClient : public QObject class MqttClient : public QObject
{ {
Q_OBJECT Q_OBJECT
+174 -230
View File
@@ -1,25 +1,23 @@
#include "pws2mqtt.h" #include "pws2mqtt.h"
#include "barometertrend.h" #include "barometertrend.h"
#include "mqtt.h" //#include <cstring>
//#include "httpserver.h"
#include <cstring>
#include <unistd.h>
#include <QtGlobal> #include <QtGlobal>
#include <QList> #include <QList>
#include <sys/socket.h>
#include <netinet/in.h>
#include <QtHttpServer/QHttpServer> #include <QtHttpServer/QHttpServer>
#include <QtHttpServer/QHttpServerRequest> #include <QtHttpServer/QHttpServerRequest>
#include <QHttpServerResponse>
#include <curl/curl.h>
#include <QtMath> #include <QtMath>
#include <QImage> #include <QImage>
#include <QTransform> #include <QTransform>
#include <stdio.h> //#include <sys/stat.h>
#include <sys/stat.h> #include "qstringview.h"
#include "utcicalculator.h" #include "utcicalculator.h"
#include <QNetworkAccessManager>
#include <QNetworkReply>
#ifdef WITH_MQTT
#include "mqtt.h"
/extern MqttClient *mqttClient;
#endif
extern MqttClient *mqttClient;
extern Pws2mqtt *pws2mqtt; extern Pws2mqtt *pws2mqtt;
extern QHttpServer *httpServer; extern QHttpServer *httpServer;
extern BarometerTrend *baro; extern BarometerTrend *baro;
@@ -46,7 +44,7 @@ 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"}},
@@ -55,12 +53,12 @@ QMap <QByteArray, QPair<QString, QByteArray>> propertyName
{"dailyrainin", {"Pluie de la journée", " mm"}}, {"dailyrainin", {"Pluie de la journée", " mm"}},
// {"monthlyrainin", {"Pluie du mois", " mm"}}, // {"monthlyrainin", {"Pluie du mois", " mm"}},
// {"yearlyrainin", {"Pluie de l'année", " mm"}}, // {"yearlyrainin", {"Pluie de l'année", " mm"}},
// {"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", {"UV", ""}}
}; };
QList <QList <QVariant>> forceVent QList <QList <QVariant>> forceVent
@@ -91,13 +89,13 @@ Pws2mqtt::~Pws2mqtt()
void Pws2mqtt::init() void Pws2mqtt::init()
{ {
debug(DEBUGMACRO, "init http server", DEBUG); debug(DEBUGMACRO, "init http server", INFO);
httpServer->setMissingHandler(httpServer,[](const QHttpServerRequest &request, QHttpServerResponder &responder) /*httpServer->setMissingHandler([](const QHttpServerRequest &request, QHttpServerResponder &&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)); //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); 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)
{ {
@@ -108,7 +106,7 @@ void Pws2mqtt::init()
{ {
QByteArray data; QByteArray data;
QList<std::pair<QString, QString>> queryList = request.query().queryItems(); QList<std::pair<QString, QString>> queryList = request.query().queryItems();
debug(DEBUGMACRO, "Réception des données", INFO);
//QTextStream result(&data); //QTextStream result(&data);
if (queryList.isEmpty()) if (queryList.isEmpty())
@@ -116,21 +114,59 @@ void Pws2mqtt::init()
debug(DEBUGMACRO, "Request query is empty", WARNING); debug(DEBUGMACRO, "Request query is empty", WARNING);
}else }else
{ {
debug(DEBUGMACRO, "Request query :" + request.query().toString() , DEBUG); debug(DEBUGMACRO, "Request query :" + request.query().toString() , INFO
this->parseData(queryList); );
/* QMetaObject::invokeMethod(this, [this, query = request.query()]() {
this->parseData(query.queryItems());
}, Qt::QueuedConnection);*/
parseData(request.query().queryItems());
debug(DEBUGMACRO, "Returning 'success'", DEBUG); debug(DEBUGMACRO, "Returning 'success'", DEBUG);
} }
//mqttClient.send_message(jsonString); //mqttClient.send_message(jsonString);
return QHttpServerResponse("text/plain", "Requête traitée en arrière-plan\n");
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, "0"));
debug (DEBUGMACRO, "Init " + name + " => " + propertyList[name], DEBUG); debug (DEBUGMACRO, "Init " + name + " => " + propertyList[name], DEBUG);
} }
} }
void notify(QString notif, QString priority, QString inputPath, QString tag)
{
(void) inputPath;
QNetworkAccessManager *manager = new QNetworkAccessManager();
QNetworkRequest request(QUrl("http://localhost:81/Meteo"));
request.setRawHeader("Content-Type", "charset=UTF-8; text/markdown");
if (!tag.isEmpty())
{
request.setRawHeader("Tags", tag.toUtf8());
}
request.setRawHeader("Title", "Météo");
request.setRawHeader("Priority", priority.toUtf8());
request.setRawHeader("Markdown", "yes");
request.setRawHeader("Config", "/etc/ntfy.client.yml");
request.setRawHeader("Firebase", "no");
QNetworkReply *reply = manager->post(request, notif.toUtf8());
QObject::connect(reply, &QNetworkReply::finished, [reply]()
{
if (reply->error() != QNetworkReply::NoError)
{
debug(DEBUGMACRO, "Erreur réseau : " + reply->errorString(), ERROR);
} else
{
debug(DEBUGMACRO, "Notification envoyée", DEBUG);
}
reply->deleteLater();
});
delete(manager);
}
void Pws2mqtt::listeningHttp() void Pws2mqtt::listeningHttp()
{ {
//QByteArray data; //QByteArray data;
@@ -141,20 +177,23 @@ void Pws2mqtt::listeningHttp()
{ {
debug(DEBUGMACRO, "Http Server failed to listen on a port.", ERROR); debug(DEBUGMACRO, "Http Server failed to listen on a port.", ERROR);
} }
debug(DEBUGMACRO, "Listening on port " + QString::number(port)); debug(DEBUGMACRO, "Listening on port " + QString::number(port), INFO);
} }
void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList) void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
{ {
debug(DEBUGMACRO, "Parsing Datas", DEBUG); debug(DEBUGMACRO, "Parsing Datas", DEBUG);
#ifdef WITH_MQTT
QString jsonString = "{"; QString jsonString = "{";
QString deviceString = "\"device\": {\"ieeeAddress\": \"" + mqttClient->macAddress + "\", \"type\": \"" + mqttClient->type + "\", \"powerSource\": \"Battery\""; QString deviceString = "\"device\": {\"ieeeAddress\": \"" + mqttClient->macAddress + "\", \"type\": \"" + mqttClient->type + "\", \"powerSource\": \"Battery\"";
#endif
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; 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;
@@ -174,24 +213,29 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
if(deviceFlag == false) if(deviceFlag == false)
{ {
deviceFlag = true; deviceFlag = true;
}else }
#ifdef WITH_MQTT
else
{ {
deviceString.append(", "); deviceString.append(", ");
} }
deviceString += "\"" + name + "\": "; deviceString += "\"" + name + "\": ";
deviceString += pair.second; deviceString += pair.second;
#endif
}else }else
{ {
if(propertyFlag == false) if(propertyFlag == false)
{ {
propertyFlag = true; propertyFlag = true;
}else }
#ifdef WITH_MQTT
else
{ {
jsonString.append(", "); jsonString.append(", ");
} }
jsonString.append("\"" + name + "\": "); jsonString.append("\"" + name + "\": ");
jsonString.append(pair.second); jsonString.append(pair.second);
#endif
if (name == "tempf") if (name == "tempf")
{ {
static QDateTime timeTemp = QDateTime::currentDateTime().addSecs(-600); static QDateTime timeTemp = QDateTime::currentDateTime().addSecs(-600);
@@ -203,8 +247,15 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
//notif += formatNotifString (propertyName[name].first, propertyName[name].second, QByteArray::number(qPow(propertyValue, 1.0))); //notif += formatNotifString (propertyName[name].first, propertyName[name].second, QByteArray::number(qPow(propertyValue, 1.0)));
//debug (DEBUGMACRO, "", DEBUG); //debug (DEBUGMACRO, "", DEBUG);
timeTemp = timeTemp.currentDateTime().addSecs(300); timeTemp = timeTemp.currentDateTime().addSecs(300);
propertyList[name] = formatNotifString(propertyName[name].first, propertyName[name].second, QByteArray::number(propertyValue)); propertyList[name] = formatNotifString(propertyName[name], QByteArray::number(propertyValue));
propertiesValue[name] = propertyValue; propertiesValue[name] = propertyValue;
if (propertyValue > 35)
{
priority[name] = 4;
}else if (propertyValue > 27)
{
priority[name] = 3;
}
} }
}else if (name == "humidity") }else if (name == "humidity")
{ {
@@ -214,7 +265,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
if (compare (propertiesValue[name], propertyValue, 3)) if (compare (propertiesValue[name], propertyValue, 3))
{ {
//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], QByteArray::number(propertyValue));
propertiesValue[name] = propertyValue; propertiesValue[name] = propertyValue;
} }
}else if (name == "winddir") }else if (name == "winddir")
@@ -222,7 +273,8 @@ 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].first, propertyName[name].second, 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")
{ {
@@ -231,13 +283,13 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
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[name] = round(mphTokmh(value.toFloat()));
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertiesValue["vent"]), DEBUG); debug (DEBUGMACRO, name + " : " + QByteArray::number(propertiesValue[name]), DEBUG);
for (i=0; i<forceVent.size();i++) for (i=0; i<forceVent.size();i++)
{ {
if (propertiesValue["vent"] <= forceVent[i][0].toDouble()) if (propertiesValue[name] <= forceVent[i][0].toDouble())
{ {
msg = forceVent[i][1].toString(); msg = forceVent[i][1].toString();
windPriority = forceVent[i][2].toUInt(); windPriority = forceVent[i][2].toUInt();
@@ -245,7 +297,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
} }
} }
propertyList[name] = formatNotifString ("Vent - " + msg, propertyName[name].second , QByteArray::number(propertiesValue["vent"])); propertyList[name] = "- Vent - " + msg + " : " + QByteArray::number(propertiesValue[name]) + "Km/h" + "\n";
propertiesValue["forcevent"] = i; propertiesValue["forcevent"] = i;
if (i >= 5) if (i >= 5)
{ {
@@ -254,9 +306,9 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
if (propertiesValue["forcevent"] != i) if (propertiesValue["forcevent"] != i)
{ {
priority = qMax(priority, windPriority); priority[name] = qMax(priority[name], windPriority);
} }
debug (DEBUGMACRO, "priority = " + QString::number(priority), DEBUG); debug (DEBUGMACRO, "priority = " + QString::number(priority[name]), DEBUG);
}else if (name == "windgustmph") }else if (name == "windgustmph")
{ {
QString msg = ""; QString msg = "";
@@ -264,15 +316,15 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
propertiesValue[name] = round(mphTokmh(value.toFloat())); propertiesValue[name] = round(mphTokmh(value.toFloat()));
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertiesValue["rafale"]), DEBUG); debug (DEBUGMACRO, name + " : " + QByteArray::number(propertiesValue[name]), DEBUG);
propertyList[name] = formatNotifString (propertyName[name].first, propertyName[name].second , QByteArray::number(propertiesValue[name])); propertyList[name] = formatNotifString (propertyName[name], QByteArray::number(propertiesValue[name]));
if (propertiesValue["rafales"] > 50) if (propertiesValue[name] > 50)
{ {
priority = qMax(priority, (quint8)4); priority[name] = qMax(priority[name], (quint8)4);
} }
debug (DEBUGMACRO, "priority = " + QString::number(priority), DEBUG); debug (DEBUGMACRO, "priority = " + QString::number(priority[name]), DEBUG);
}else if (name == "rainin") }else if (name == "rainin")
{ {
static double ecart; static double ecart;
@@ -289,12 +341,12 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
if (compare (propertiesValue[name], propertyValue, ecart)) if (compare (propertiesValue[name], propertyValue, ecart))
{ {
QString pluviosite = getPluviosite(propertyValue, raininPriority); QString pluviosite = getPluviosite(propertyValue, raininPriority);
priority = setPriority (priority, raininPriority); priority[name] = setPriority (priority[name], raininPriority);
//debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG); //debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
propertyList[name] = formatNotifString(pluviosite, propertyName[name].second, QByteArray::number(propertyValue)); propertyList[name] = formatNotifString(propertyName[name], QByteArray::number(propertyValue));
propertiesValue[name] = propertyValue; propertiesValue[name] = propertyValue;
} }
debug (DEBUGMACRO, "priority = " + QString::number(priority), DEBUG); debug (DEBUGMACRO, "priority = " + QString::number(priority[name]), DEBUG);
}else if (name == "dailyrainin") }else if (name == "dailyrainin")
{ {
static double ecart; static double ecart;
@@ -309,20 +361,19 @@ 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[name] = setPriority (priority[name], 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], QByteArray::number(propertyValue));
propertiesValue[name] = propertyValue; propertiesValue[name] = propertyValue;
} }
debug (DEBUGMACRO, "priority = " + QString::number(priority), DEBUG); debug (DEBUGMACRO, "priority = " + QString::number(priority[name]), 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], QByteArray::number(propertyValue));
propertiesValue[name] = propertyValue; propertiesValue[name] = propertyValue;
static QString prevision; static QString prevision;
@@ -331,13 +382,14 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
prevision = ret.message; prevision = ret.message;
//if (prevision != newPrevision) //if (prevision != newPrevision)
//{ //{
priority = setPriority(priority, ret.urgency); priority[name] = setPriority(priority[name], 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[name]), DEBUG);
}else if (name == "UV") }else if (name == "UV")
{ {
QString msg;
static QDateTime timeUV = QDateTime::currentDateTime().addSecs(-600); static QDateTime timeUV = QDateTime::currentDateTime().addSecs(-600);
propertyValue = pair.second.toUInt(); propertyValue = pair.second.toUInt();
@@ -346,27 +398,30 @@ 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);
if (propertyValue == 5 ) if (propertyValue == 5 )
priority = setPriority (priority, 4); priority[name] = setPriority (priority[name], 4);
if (propertyValue >= 6 ) if (propertyValue >= 6 )
priority = setPriority (priority, 5); priority[name] = setPriority (priority[name], 5);
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] = "- UV - " + QByteArray::number(propertyValue) + "\n";
} }
debug (DEBUGMACRO, "priority = " + QString::number(priority), DEBUG); debug (DEBUGMACRO, "priority = " + QString::number(priority[name]), DEBUG);
}else if (name == "solarradiation") }else if (name == "solarradiation")
{ {
propertyValue = pair.second.toFloat()*100/100;
propertyList[name] = formatNotifString(propertyName[name], QByteArray::number(propertyValue));
propertiesValue[name] = round(pair.second.toFloat()*100/100); propertiesValue[name] = round(pair.second.toFloat()*100/100);
debug (DEBUGMACRO, "SolarRadiations = " + QByteArray::number(propertyValue), DEBUG);
} }
} }
} }
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"], QByteArray::number(propertiesValue["windchill"]));
//windChill(propertiesValue["tempf"], propertiesValue["vent"]); //windChill(propertiesValue["tempf"], propertiesValue["vent"]);
//calculerHumidex(propertiesValue["tempf"], propertiesValue["humidity"]); //calculerHumidex(propertiesValue["tempf"], propertiesValue["humidity"]);
#ifdef WITH_MQTT
if (!jsonString.isEmpty()) if (!jsonString.isEmpty())
{ {
debug(DEBUGMACRO, "json string : " + jsonString, DEBUG); debug(DEBUGMACRO, "json string : " + jsonString, DEBUG);
@@ -376,50 +431,76 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
{ {
debug(DEBUGMACRO, "No values to send", DEBUG); debug(DEBUGMACRO, "No values to send", DEBUG);
} }
#endif
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)) //bool changed = false;
quint8 aPriority= 0;
debug(DEBUGMACRO, "looping to fill notif", DEBUG);
QTime currentTime = QTime::currentTime();
if (currentTime.minute() == 0 or start == false)
{ {
bool changed = false;
timer = QDateTime::currentDateTime(); timer = QDateTime::currentDateTime();
debug(DEBUGMACRO, "looping to fill notif, priority = " + QString::number(priority), DEBUG); start = true;
notif = listProperties2notify (propertyList, priority, 0);
if (precPropertyList.size() == 0) notify (notif, priorityList[aPriority], attachment, tag);
{
changed = true;
}
for (auto [name, value]: propertyList.asKeyValueRange())
{
if (precPropertyList.contains(name))
{
if (precPropertyList[name] != propertyList[name])
{
debug(DEBUGMACRO, "changed = true", DEBUG);
changed = true;
}
}
debug(DEBUGMACRO, "Name = " + name + ", value = " + value, DEBUG);
if (! (name == "prevision"))
{
notif += propertyList[name];
}
}
if (changed)
{
notify (notif, priorityList[priority], attachment, tag);
precPropertyList = propertyList; precPropertyList = propertyList;
} debug(DEBUGMACRO, "calling notify with notif = #" + notif + "#", INFO);
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[aPriority], "", tag);
debug(DEBUGMACRO, "calling notify with notif = #" + notif + "#", DEBUG); debug(DEBUGMACRO, "calling notify with notif = #" + notif + "#", INFO);
}
if (aPriority >= 3)
{
notif = "**ALERTES**\n" + listProperties2notify (propertyList,priority, 3);
precPropertyList = propertyList;
notify (notif, priorityList[aPriority], attachment, tag);
} }
debug(DEBUGMACRO, "parseData: Returning", DEBUG); debug(DEBUGMACRO, "parseData: Returning", DEBUG);
} }
QString listProperties2notify (QMap <QByteArray, QString> propertyList, QHash <QByteArray, quint8> priority, quint8 minAlert)
{
static QHash <QByteArray, quint8> announced = {};
QString notif = "";
for (auto [name, value]: propertyList.asKeyValueRange())
{
if (name != "prevision")
{
//if (precPropertyList.contains(name))
//{
//if (precPropertyList[name] != propertyList[name])
//{
if (minAlert == 0)
{
notif += propertyList[name];
}else if (priority[name] >= minAlert)
{
if (announced.contains(name) and priority.contains(name))
{
if (announced[name] != priority[name])
{
notif += propertyList[name];
announced[name] = priority[name];
}else
{
debug (DEBUGMACRO, name + " : déjà annoncé = " + announced[name] + " nouvelle valeur = " + priority[name], INFO);
}
}
}
//}
//}
debug(DEBUGMACRO, "Name = " + name + ", value = " + value, DEBUG);
}
}
return notif;
}
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));
@@ -506,154 +587,17 @@ bool compare (double value, double currentValue, double ecart)
} }
} }
QString formatNotifString (QString name, QString unit ,QByteArray value) QString formatNotifString (QPair<QString, QByteArray> property ,QByteArray value)
{ {
QString text = "- " + name + " : " + value; QString text = "- " + property.first + " : " + value;
if (!unit.isEmpty()) if (!property.second.isEmpty())
{ {
text += unit; text += property.second;
//"- " + 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) {
FILE *f = (FILE *)stream;
size_t n = fread(ptr, size, nmemb, f);
return n;
}
// Callback for curl library
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, std::string *output)
{
size_t total_size = size * nmemb;
output->append((char*)contents, total_size);
return total_size;
}
void notify(QString notif, QString priority, QString inputPath, QString tag)
{
CURL *curl;
CURLcode res;
std::string readBuffer;
priority = "Priority: " + priority;
debug (DEBUGMACRO, "notifying at priority " + priority + "with tag : " + tag + " - message : " + notif, DEBUG);
// Initialise libcurl
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if (curl)
{
// Définis les en-têtes pour le titre et les priorités
struct curl_slist *headers = NULL;
notif.replace("\\", "\\\\\\'"); // Échappe les apostrophes
if (!tag.isEmpty())
{
headers = curl_slist_append(headers, ("Tags: " + tag).toStdString().c_str());
}
headers = curl_slist_append(headers, "Title: Météo");
headers = curl_slist_append(headers, priority.toStdString().c_str());
headers = curl_slist_append(headers, "Markdown: yes");
// headers = curl_slist_append(headers, "Config: /etc/ntfy.client.yml");
headers = curl_slist_append(headers, "Firebase: no");
// headers = curl_slist_append(headers, "Content-Type: charset=UTF-8; text/markdown"); // Ajout de l'encodage
struct curl_slist *h = headers;
while (h) {
debug(DEBUGMACRO, "Header: " + QString(h->data), DEBUG);
h = h->next;
}
debug(DEBUGMACRO, "Notif: " + notif, DEBUG);
// Configure la requête POST
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:81/Meteo");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, notif.toUtf8().constData());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
// Exécute la requête
res = curl_easy_perform(curl);
// Vérifie les erreurs
if (res != CURLE_OK)
{
debug(DEBUGMACRO, "Erreur libcurl :" + QString(curl_easy_strerror(res)), DEBUG);
} else
{
debug(DEBUGMACRO, "Réponse du serveur: " + QString::fromStdString(readBuffer), DEBUG);
}
// Nettoie les ressources
//curl_mime_free(mime);
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
}
// Nettoie libcurl
curl_global_cleanup();
if (!inputPath.isEmpty())
{
FILE *fd = fopen(inputPath.toStdString().c_str(), "rb");
if (!fd) {
perror("Erreur lors de l'ouverture du fichier");
return;
}
// Initialise libcurl
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if (curl)
{
// Définis les en-têtes pour le titre et les priorités
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Title: Météo");
headers = curl_slist_append(headers, priority.toStdString().c_str());
// headers = curl_slist_append(headers, "Config: /etc/ntfy.client.yml");
headers = curl_slist_append(headers, "Firebase: no");
headers = curl_slist_append(headers, "Content-Type: image/png");
headers = curl_slist_append(headers, "X-Original-Size: true");
headers = curl_slist_append(headers, "X-Filename: fleche.png");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); // Configurer l'URL
curl_easy_setopt(curl, CURLOPT_URL, "localhost:81/Meteo");
// Utiliser la méthode PUT (comme `curl -T`)
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
// Lire le fichier et l'envoyer en tant que body
curl_easy_setopt(curl, CURLOPT_READFUNCTION, ReadFile);
curl_easy_setopt(curl, CURLOPT_READDATA, fd);
// Définir la taille du fichier (optionnel mais recommandé)
struct stat file_info;
fstat(fileno(fd), &file_info);
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size);
// Exécuter la requête
res = curl_easy_perform(curl);
// Vérifie les erreurs
if (res != CURLE_OK)
{
debug(DEBUGMACRO, "Erreur libcurl :" + QString(curl_easy_strerror(res)), DEBUG);
} else
{
debug(DEBUGMACRO, "Notification envoyée avec succès", DEBUG);
}
// Nettoyer
fclose(fd);
curl_easy_cleanup(curl);
}
// Nettoie libcurl
curl_global_cleanup();
}
}
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);
+4 -2
View File
@@ -5,6 +5,7 @@
#include <QObject> #include <QObject>
#include <QtMqtt> #include <QtMqtt>
#include <QtMqtt/QMqttClient> #include <QtMqtt/QMqttClient>
//#include <cstdint>
#define RED "\e[31m" #define RED "\e[31m"
#define GREEN "\e[32m" #define GREEN "\e[32m"
@@ -53,9 +54,8 @@ class Pws2mqtt : public QObject
double fahrenheitToCelsius(double fahrenheit); double fahrenheitToCelsius(double fahrenheit);
double tohPa(double value); double tohPa(double value);
bool compare (double value=0, double testValue=0, double ecart = 0.5); bool compare (double value=0, double testValue=0, double ecart = 0.5);
QString formatNotifString (QString name, QString unit, QByteArray value=""); QString formatNotifString (QPair<QString, QByteArray> property ,QByteArray value);
double mphTokmh (double value); double mphTokmh (double value);
void notify (QString notif, QString priority = "low", QString inputPath = "", QString tag = "");
quint8 setPriority (quint8 currentPriority, quint8 newPriority); quint8 setPriority (quint8 currentPriority, quint8 newPriority);
QString previsionMeteo(double currentPressure, double variation3h, quint8 &priority); QString previsionMeteo(double currentPressure, double variation3h, quint8 &priority);
QString pressureVariation(double currentPressure, quint8 &priority); QString pressureVariation(double currentPressure, quint8 &priority);
@@ -63,4 +63,6 @@ QString getPluviosite(double value, quint8 &priority);
void rotateAndSaveImage(const QString &inputPath, const QString &outputPath, qreal angle=0); void rotateAndSaveImage(const QString &inputPath, const QString &outputPath, qreal angle=0);
double windChill(double airT, double vent); double windChill(double airT, double vent);
double calculerHumidex(double temperature, double humiditeRelative); double calculerHumidex(double temperature, double humiditeRelative);
void notify (QString notif, QString priority = "low", QString inputPath = "", QString tag = "");
QString listProperties2notify (QMap <QByteArray, QString> propertyList, QHash <QByteArray, quint8> priority, quint8 minAlert = 0);
-27
View File
@@ -12,33 +12,6 @@ UtciCalculator::UtciCalculator(QObject *parent)
/*// Loads coefficients from a simple text file containing one coefficient per line or tab-separated. /*// Loads coefficients from a simple text file containing one coefficient per line or tab-separated.
// The expected file is the ESM_3 coefficients table exported to a plain text file where the coefficients // The expected file is the ESM_3 coefficients table exported to a plain text file where the coefficients
// appear in the same order as in the official table (210 coefficients). // appear in the same order as in the official table (210 coefficients).
bool UtciCalculator::loadCoefficientsFromFile(const QString &path)
{
QFile f(path);
if (!f.open(QIODevice::ReadOnly | QIODevice::Text))
return false;
QTextStream in(&f);
QVector<double> coeffs;
coeffs.reserve(300);
while (!in.atEnd()) {
QString line = in.readLine().trimmed();
if (line.isEmpty()) continue;
// Allow lines with comments or 'term coefficient' headings:
// We try to extract numbers from the line.
QStringList parts = line.split(QRegularExpression("[\\s,\\t]+"), Qt::SkipEmptyParts);
for (const QString &p : parts) {
bool ok = false;
double val = p.toDouble(&ok);
if (ok) coeffs.append(val);
}
}
if (coeffs.isEmpty()) return false;
m_coeffs = coeffs;
return true;
}
*/ */
// Magnus formula to estimate saturation vapour pressure (hPa) then return pa in kPa // Magnus formula to estimate saturation vapour pressure (hPa) then return pa in kPa
double UtciCalculator::vapourPressureFromRH(double Ta, double rh) double UtciCalculator::vapourPressureFromRH(double Ta, double rh)