added windchill calculation
This commit is contained in:
2
main.cpp
2
main.cpp
@@ -20,6 +20,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include "utcicalculator.h"
|
||||||
|
|
||||||
#define CLIENT_ID "Client_ID"
|
#define CLIENT_ID "Client_ID"
|
||||||
#define BROKER_ADDRESS "localhost"
|
#define BROKER_ADDRESS "localhost"
|
||||||
@@ -62,7 +63,6 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
pws2mqtt->listeningHttp();
|
pws2mqtt->listeningHttp();
|
||||||
//notify (QString("Program started"), "default");
|
//notify (QString("Program started"), "default");
|
||||||
|
|
||||||
a.exec();
|
a.exec();
|
||||||
|
|
||||||
mqttClient->qmqttClient->unsubscribe(mqttClient->topic);
|
mqttClient->qmqttClient->unsubscribe(mqttClient->topic);
|
||||||
|
|||||||
133
pws2mqtt.cpp
133
pws2mqtt.cpp
@@ -15,10 +15,13 @@
|
|||||||
#include <QTransform>
|
#include <QTransform>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include "utcicalculator.h"
|
||||||
|
|
||||||
extern MqttClient *mqttClient;
|
extern MqttClient *mqttClient;
|
||||||
extern Pws2mqtt *pws2mqtt;
|
extern Pws2mqtt *pws2mqtt;
|
||||||
extern QHttpServer *httpServer;
|
extern QHttpServer *httpServer;
|
||||||
|
UtciCalculator calc;
|
||||||
|
|
||||||
QStringList previsionList
|
QStringList previsionList
|
||||||
{
|
{
|
||||||
"Temps variable (incertain).", \
|
"Temps variable (incertain).", \
|
||||||
@@ -39,16 +42,18 @@ static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *use
|
|||||||
return size * nmemb; // On ne traite pas les données reçues
|
return size * nmemb; // On ne traite pas les données reçues
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QMap <QByteArray, QString> propertyList;
|
QMap <QByteArray, QString> propertyList;
|
||||||
|
QMap <QByteArray, QString> precPropertyList;
|
||||||
QMap <QByteArray, double> propertiesValue;
|
QMap <QByteArray, double> propertiesValue;
|
||||||
QMap <QByteArray, QPair<QString, QByteArray>> propertyName
|
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"}},
|
||||||
{"windchillf", {"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"}},
|
||||||
@@ -57,7 +62,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", ""}}
|
||||||
};
|
};
|
||||||
@@ -144,17 +149,15 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
debug(DEBUGMACRO, "Parsing Datas", DEBUG);
|
debug(DEBUGMACRO, "Parsing Datas", DEBUG);
|
||||||
|
|
||||||
QString jsonString = "{";
|
QString jsonString = "{";
|
||||||
bool propertyFlag = false;
|
|
||||||
bool deviceFlag = false;
|
|
||||||
// QString topic;
|
|
||||||
QString deviceString = "\"device\": {\"ieeeAddress\": \"" + mqttClient->macAddress + "\", \"type\": \"" + mqttClient->type + "\", \"powerSource\": \"Battery\"";
|
QString deviceString = "\"device\": {\"ieeeAddress\": \"" + mqttClient->macAddress + "\", \"type\": \"" + mqttClient->type + "\", \"powerSource\": \"Battery\"";
|
||||||
QString notif = "";
|
QString notif = "";
|
||||||
double propertyValue = 0;
|
|
||||||
QStringList priorityList {"", "min", "low", "default", "High", "urgent"};
|
QStringList priorityList {"", "min", "low", "default", "High", "urgent"};
|
||||||
quint8 priority = 2;
|
|
||||||
//static qreal winddir = 0;
|
|
||||||
QString attachment = "";
|
QString attachment = "";
|
||||||
static QDateTime timer;
|
quint8 priority = 2;
|
||||||
|
double propertyValue = 0;
|
||||||
|
bool propertyFlag = false;
|
||||||
|
bool deviceFlag = false;
|
||||||
|
static QDateTime timer = QDateTime::currentDateTime().addSecs(-2000);
|
||||||
|
|
||||||
debug(DEBUGMACRO, "looping list of query", DEBUG);
|
debug(DEBUGMACRO, "looping list of query", DEBUG);
|
||||||
|
|
||||||
@@ -212,8 +215,8 @@ 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 == "windchillf")
|
/*}else if (name == "windchillf")
|
||||||
{
|
{
|
||||||
static QDateTime timeWindchill = QDateTime::currentDateTime().addSecs(-600);
|
static QDateTime timeWindchill = QDateTime::currentDateTime().addSecs(-600);
|
||||||
propertyValue = round(fahrenheitToCelsius(value.toFloat()));
|
propertyValue = round(fahrenheitToCelsius(value.toFloat()));
|
||||||
@@ -225,16 +228,15 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
timeWindchill = timeWindchill.currentDateTime().addSecs(300);
|
timeWindchill = timeWindchill.currentDateTime().addSecs(300);
|
||||||
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" or name == "windgustmph")
|
||||||
}else if (name == "windspeedmph" or name == "windgustmph")
|
|
||||||
{
|
{
|
||||||
QString msg = "";
|
QString msg = "";
|
||||||
static QDateTime timeWind = QDateTime::currentDateTime().addSecs(-600);
|
static QDateTime timeWind = QDateTime::currentDateTime().addSecs(-600);
|
||||||
@@ -242,10 +244,11 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
//static QString msgNotif;
|
//static QString msgNotif;
|
||||||
|
|
||||||
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
|
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
|
||||||
propertyValue = round(mphTokmh(value.toFloat()));
|
propertiesValue["vent"] = round(mphTokmh(value.toFloat()));
|
||||||
|
|
||||||
for (quint8 i=0; i<forceVent.size();i++)
|
for (quint8 i=0; i<forceVent.size();i++)
|
||||||
{
|
{
|
||||||
if (propertyValue <= 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();
|
||||||
@@ -258,8 +261,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
if (name == "windspeedmph")
|
if (name == "windspeedmph")
|
||||||
{
|
{
|
||||||
//propertyList["forcevent"] = msg;
|
//propertyList["forcevent"] = msg;
|
||||||
msg.prepend("Vent - ");
|
propertyList[name] = formatNotifString ("Vent - " + msg, propertyName[name].second , QByteArray::number(propertyValue));
|
||||||
propertyList[name] = formatNotifString (msg, propertyName[name].second , QByteArray::number(propertyValue));
|
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
propertyList[name] = formatNotifString (propertyName[name].first, propertyName[name].second , QByteArray::number(propertyValue));
|
propertyList[name] = formatNotifString (propertyName[name].first, propertyName[name].second , QByteArray::number(propertyValue));
|
||||||
@@ -354,9 +356,17 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
propertiesValue[name] = propertyValue;
|
propertiesValue[name] = propertyValue;
|
||||||
debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
|
debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
|
||||||
}
|
}
|
||||||
}
|
}else if (name == "solarradiation")
|
||||||
|
{
|
||||||
|
propertiesValue[name] = round(pair.second.toFloat()*100/100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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"]));
|
||||||
|
windChill(propertiesValue["tempf"], propertiesValue["vent"]);
|
||||||
|
calculerHumidex(propertiesValue["tempf"], propertiesValue["humidity"]);
|
||||||
|
|
||||||
if (!jsonString.isEmpty())
|
if (!jsonString.isEmpty())
|
||||||
{
|
{
|
||||||
debug(DEBUGMACRO, "json string : " + jsonString, DEBUG);
|
debug(DEBUGMACRO, "json string : " + jsonString, DEBUG);
|
||||||
@@ -369,21 +379,88 @@ 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(900))
|
if (priority > 3 or QDateTime::currentDateTime() > timer.addSecs(1800))
|
||||||
{
|
{
|
||||||
timer = QDateTime::currentDateTime();
|
bool changed = false;
|
||||||
debug(DEBUGMACRO, "looping to fill notif, priority = " + QString::number(priority), DEBUG);
|
timer = QDateTime::currentDateTime();
|
||||||
|
debug(DEBUGMACRO, "looping to fill notif, priority = " + QString::number(priority), DEBUG);
|
||||||
|
|
||||||
|
if (precPropertyList.size() == 0)
|
||||||
|
{
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
for (auto [name, value]: propertyList.asKeyValueRange())
|
for (auto [name, value]: propertyList.asKeyValueRange())
|
||||||
{
|
{
|
||||||
debug(DEBUGMACRO, "Name = " + name + ", value = " + value, DEBUG);
|
if (precPropertyList.contains(name))
|
||||||
notif += propertyList[name];
|
{
|
||||||
|
if (precPropertyList[name] != propertyList[name])
|
||||||
|
{
|
||||||
|
debug(DEBUGMACRO, "changed = true", DEBUG);
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
debug(DEBUGMACRO, "Name = " + name + ", value = " + value, DEBUG);
|
||||||
|
notif += propertyList[name];
|
||||||
}
|
}
|
||||||
debug(DEBUGMACRO, "calling notify with notif = #" + notif + "#", DEBUG);
|
debug(DEBUGMACRO, "calling notify with notif = #" + notif + "#", DEBUG);
|
||||||
notify (notif, priorityList[priority], attachment);
|
if (changed)
|
||||||
}
|
{
|
||||||
|
notify (notif, priorityList[priority], attachment);
|
||||||
|
precPropertyList = propertyList;
|
||||||
|
}
|
||||||
|
}
|
||||||
debug(DEBUGMACRO, "parseData: Returning", DEBUG);
|
debug(DEBUGMACRO, "parseData: Returning", DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double calculerUTCI(double temperature, double humiditeRelative, double vitesseVent, double rayonnement)
|
||||||
|
{
|
||||||
|
double e = (humiditeRelative / 100.0) * 6.105 * exp((17.27 * temperature) / (237.7 + temperature));
|
||||||
|
debug(DEBUGMACRO, "UTCI => e = " + QString::number(e), DEBUG);
|
||||||
|
double V = vitesseVent * 5.0 / 18.0; // Vitesse du vent en m/s
|
||||||
|
debug(DEBUGMACRO, "UTCI => V = " + QString::number(V), DEBUG);
|
||||||
|
|
||||||
|
double utci = temperature +
|
||||||
|
(0.607562 + 0.022437 * e + 7.3869e-4 * temperature * e - 3.5582e-6 * temperature * temperature * e) +
|
||||||
|
(-11.4 + 0.11 * temperature + 0.55 * V) +
|
||||||
|
(0.0023 * temperature * temperature - 0.118 * V - 0.0014 * temperature * V);
|
||||||
|
debug(DEBUGMACRO, "UTCI = " + QString::number(utci), DEBUG);
|
||||||
|
|
||||||
|
// Ajustement simplifié pour le rayonnement
|
||||||
|
double ref = 200.0; // Rayonnement de référence (W/m²)
|
||||||
|
double k = 0.02; // Coefficient empirique
|
||||||
|
utci = utci + k * (rayonnement - ref);
|
||||||
|
debug(DEBUGMACRO, "UTCI = " + QString::number(utci), DEBUG);
|
||||||
|
return round(utci * 100) / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
double windChill(double airT, double vent)
|
||||||
|
{
|
||||||
|
double w = 0;
|
||||||
|
|
||||||
|
if (airT > 10 or vent < 4.8)
|
||||||
|
{
|
||||||
|
return airT;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
w = 13.12 + 0.6215 * airT - 11.37 * pow(vent, 0.16) + 0.3965 * airT * pow(vent, 0.16);
|
||||||
|
debug(DEBUGMACRO, "windChill = " + QString::number(w), DEBUG);
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double calculerHumidex(double temperature, double humiditeRelative)
|
||||||
|
{
|
||||||
|
// Calcul de la température du point de rosée (T_rosée)
|
||||||
|
double T_rosee = (243.04 * (log(humiditeRelative / 100.0) + (17.625 * temperature) / (243.04 + temperature))) / (17.625 - (log(humiditeRelative / 100.0) + (17.625 * temperature) / (243.04 + temperature)));
|
||||||
|
|
||||||
|
// Calcul de l'Humidex (H)
|
||||||
|
double H = temperature + 0.5555 * (6.11 * exp(5417.7530 * (1.0 / 273.16 - 1.0 / (273.15 + T_rosee))) - 10.0);
|
||||||
|
debug(DEBUGMACRO, "humidex = " + QString::number(H), DEBUG);
|
||||||
|
|
||||||
|
return H;
|
||||||
|
}
|
||||||
|
|
||||||
QString getPluviosite(double value, quint8 &priority)
|
QString getPluviosite(double value, quint8 &priority)
|
||||||
{
|
{
|
||||||
if (value < 1)
|
if (value < 1)
|
||||||
|
|||||||
@@ -62,5 +62,7 @@ QString previsionMeteo(double currentPressure, double variation3h, quint8 &prior
|
|||||||
QString pressureVariation(double currentPressure, quint8 &priority);
|
QString pressureVariation(double currentPressure, quint8 &priority);
|
||||||
QString getPluviosite(double value, quint8 &priority);
|
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 calculerHumidex(double temperature, double humiditeRelative);
|
||||||
|
|
||||||
#endif // PWS2MQTT_H
|
#endif // PWS2MQTT_H
|
||||||
|
|||||||
Reference in New Issue
Block a user