modif notifications une seule notification avec tous les paramètres\ndebug

This commit is contained in:
2025-10-04 23:05:36 +02:00
parent 33a9fb517e
commit 1f00d24154
6 changed files with 275 additions and 154 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

View File

@@ -91,9 +91,10 @@ int main(int argc, char *argv[])
void debug(QString debugHeader, QString msg, uint8_t level, QByteArray property)
{
msg.replace("\n", "\\n");
if ((debugLevel & level) == 1)
{
qInfo("%s%sINFO: %s%s", debugHeader.toStdString().c_str(), GREEN, ("'" + msg.toStdString() + "'").c_str(), NORMAL);
qInfo("%s%sINFO: %s%s", debugHeader.toStdString().c_str(), GREEN, msg.toStdString().c_str(), NORMAL);
}
if ((debugLevel & level) == 2)
{

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 9.0.1, 2024-09-10T18:21:21. -->
<!-- Written by QtCreator 9.0.1, 2025-10-03T23:36:59. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
@@ -85,6 +85,97 @@
</data>
<data>
<variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap">
<value type="QString" key="DeviceType">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Qt 6.4.1 (qt6)</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Qt 6.4.1 (qt6)</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{17b0ba8e-e6fe-4c71-98eb-9b4d3bcc4307}</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="int" key="EnableQmlDebugging">0</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/daniel/develop/build-pws2mqtt-qt-Desktop-Debug</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">/home/daniel/develop/build-pws2mqtt-qt-Desktop-Debug</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProcessStep.Arguments"> -x versioning -s 1</value>
<value type="QString" key="ProjectExplorer.ProcessStep.Command">bash</value>
<value type="QString" key="ProjectExplorer.ProcessStep.WorkingDirectory">%{ActiveProject:NativePath}</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.ProcessStep</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.2">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">3</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/daniel/develop/pws2mqtt-qt/pws2mqtt-qt.pro</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">/home/daniel/develop/pws2mqtt-qt/pws2mqtt-qt.pro</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseTerminal">false</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">/home/daniel/develop/build-pws2mqtt-qt-Desktop-Debug</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.Target.1</variable>
<valuemap type="QVariantMap">
<value type="QString" key="DeviceType">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
@@ -99,16 +190,23 @@
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">/home/daniel/develop/build-pws2mqtt-qt-Desktop-Debug</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProcessStep.Arguments">-s 1</value>
<value type="QString" key="ProjectExplorer.ProcessStep.Command">versioning</value>
<value type="QString" key="ProjectExplorer.ProcessStep.WorkingDirectory">%{buildDir}</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.ProcessStep</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.2">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">3</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
@@ -243,88 +341,6 @@
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">/home/daniel/develop/build-pws2mqtt-qt-Desktop-Debug</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.Target.1</variable>
<valuemap type="QVariantMap">
<value type="QString" key="DeviceType">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Qt 6.4.1 (qt6)</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Qt 6.4.1 (qt6)</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{17b0ba8e-e6fe-4c71-98eb-9b4d3bcc4307}</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="int" key="EnableQmlDebugging">0</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/daniel/develop/build-pws2mqtt-qt-Desktop-Debug</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">/home/daniel/develop/build-pws2mqtt-qt-Desktop-Debug</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">true</value>
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>

View File

@@ -33,7 +33,7 @@ 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
}
QMap <QByteArray, double> propertyList;
QMap <QByteArray, QVariant> propertyList;
QMap <QByteArray, QPair<QString, QByteArray>> propertyName
{
{"tempf", {"Température extérieure", "°C"}},
@@ -41,12 +41,12 @@ QMap <QByteArray, QPair<QString, QByteArray>> propertyName
{"dewptf", {"Point de rosée", "°C"}},
{"windchillf", {"Température ressentie", "°C"}},
{"winddir", {"Direction du vent", "°"}},
{"windspeedmph", {"vitesse du vent", "km/h"}},
{"windgustmph", {"Rafales", "km/h"}},
{"rainin", {"Pluie", "mm/h"}},
{"dailyrainin", {"Pluie de la journée", "mm"}},
{"monthlyrainin", {"Pluie du mois", "mm"}},
{"yearlyrainin", {"Pluie de l'année", "mm"}},
{"windspeedmph", {"vitesse du vent", " km/h"}},
{"windgustmph", {"Rafales", " km/h"}},
{"rainin", {"Pluie", " mm/h"}},
{"dailyrainin", {"Pluie de la journée", " mm"}},
{"monthlyrainin", {"Pluie du mois", " mm"}},
{"yearlyrainin", {"Pluie de l'année", " mm"}},
{"solarradiation", {"Énergie solaire", " W/m²"}},
{"indoortempf", {"Température intérieure", "°C"}},
{"indoorhumidity", {"Humidité intérieure", "%"}},
@@ -55,6 +55,22 @@ QMap <QByteArray, QPair<QString, QByteArray>> propertyName
{"UV", {"Alerte UV", ""}}
};
QList <QList <QVariant>> forceVent
{
// { max wind speed, name, priority}
{1, "Temps calme", 1},
{5, "Très légère brise", 1},
{11, "Légère brise", 1},
{19, "Petite brise", 1},
{28, "Jolie brise", 1},
{38, "Bonne brise", 1},
{49, "Vent frais", 3},
{61, "Grand vent", 4},
{74, "Vent fort", 5},
{88, "Vent violent", 5},
{117, "Tempête", 5},
{1000, "Ouragan", 5}
};
Pws2mqtt::Pws2mqtt()
{
@@ -129,8 +145,9 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
double propertyValue = 0;
QStringList priorityList {"", "min", "low", "default", "High", "urgent"};
quint8 priority = 2;
QPair <QByteArray, QByteArray> winddir = {"", 0};
static qreal winddir = 0;
QString attachment = "";
bool changed = false;
debug(DEBUGMACRO, "looping list of query", DEBUG);
@@ -139,6 +156,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
debug(DEBUGMACRO, pair.first + " = " + pair.second, DEBUG);
QByteArray name = pair.first.toLatin1();
QByteArray value = pair.second.toLatin1();
float fValue = value.toDouble();
if (this->deviceProperties.contains(name))
{
@@ -166,75 +184,105 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
if (name == "tempf")
{
static QDateTime timeTemp = QDateTime::currentDateTime().addSecs(-600);
propertyValue = round(fahrenheitToCelsius(pair.second.toFloat()));
propertyValue = round(fahrenheitToCelsius(fValue));
debug (DEBUGMACRO, "timeTemp = " + timeTemp.time().toString() + " - current :" + QDateTime::currentDateTime().toString() , DEBUG);
if (compare (propertyList[name], propertyValue, 1) and timeTemp < QDateTime::currentDateTime())
if (compare (propertyList[name].toDouble(), propertyValue, 1) and timeTemp < QDateTime::currentDateTime())
{
notif += formatNotifString (propertyName[name].first, propertyName[name].second, QByteArray::number(qPow(propertyValue, 1.0)));
debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
//notif += formatNotifString (propertyName[name].first, propertyName[name].second, QByteArray::number(qPow(propertyValue, 1.0)));
//debug (DEBUGMACRO, "", DEBUG);
timeTemp = timeTemp.currentDateTime().addSecs(300);
propertyList[name] = propertyValue;
changed = true;
}
}else if (name == "indoortempf")
/*}else if (name == "indoortempf")
{
static QDateTime timeIndoorTemp = QDateTime::currentDateTime().addSecs(-600);
propertyValue = round(fahrenheitToCelsius(pair.second.toFloat()));
if (compare (propertyList[name], propertyValue, 1) and timeIndoorTemp < QDateTime::currentDateTime())
{
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, "Notif = #" + notif + "#", DEBUG);
timeIndoorTemp = timeIndoorTemp.currentDateTime().addSecs(300);
propertyList[name] = propertyValue;
}
}*/
}else if (name == "humidity")
{
propertyValue = pair.second.toFloat();
if (compare (propertyList[name], propertyValue, 3))
propertyValue = value.toFloat();
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
if (compare (propertyList[name].toFloat(), propertyValue, 3))
{
notif += formatNotifString (propertyName[name].first, propertyName[name].second , value);
debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
//notif += formatNotifString (propertyName[name].first, propertyName[name].second , value);
propertyList[name] = propertyValue;
changed = true;
}
}else if (name == "windchillf")
{
static QDateTime timeWindchill = QDateTime::currentDateTime().addSecs(-600);
propertyValue = round(fahrenheitToCelsius(pair.second.toFloat()));
if (compare (propertyList[name], propertyValue, 1) and timeWindchill < QDateTime::currentDateTime())
propertyValue = round(fahrenheitToCelsius(value.toFloat()));
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
if (compare (propertyList[name].toFloat(), propertyValue, 1) and timeWindchill < QDateTime::currentDateTime())
{
notif += formatNotifString (propertyName[name].first, propertyName[name].second , QByteArray::number(qPow(propertyValue, 1.0)));
debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
//notif += formatNotifString (propertyName[name].first, propertyName[name].second , QByteArray::number(qPow(propertyValue, 1.0)));
//debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
timeWindchill = timeWindchill.currentDateTime().addSecs(300);
propertyList[name] = propertyValue;
changed = true;
}
}else if (name == "winddir")
{
winddir.first = name;
winddir.second = value;
}else if (name == "windspeedmph")
winddir = value.toFloat();
rotateAndSaveImage(this->inputPath, this->outputPath, (qreal)winddir);
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
}else if (name == "windspeedmph" or name == "windgustmph")
{
propertyValue = round(mphTokmh(pair.second.toFloat()));
if (compare (propertyList[name], propertyValue, 5))
QString msg = "";
static QDateTime timeWind = QDateTime::currentDateTime().addSecs(-600);
quint8 windPriority = 1;
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
propertyValue = round(mphTokmh(value.toFloat()));
for (quint8 i=0; i<forceVent.size();i++)
{
if (propertyValue > 10)
if (propertyValue <= forceVent[i][0].toDouble())
{
priority = setPriority (priority, 2);
notif += formatNotifString (propertyName[name].first, propertyName[name].second , QByteArray::number(propertyValue));
notif += formatNotifString (winddir.first, winddir.second);
//TODO attache fleche
debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
if (propertyValue > 30)
priority = setPriority (priority, 4);
if (propertyValue > 50)
priority = setPriority (priority, 5);
propertyList[name] = propertyValue;
attachment = this->inputPath;
debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
msg = forceVent[i][1].toString();
windPriority = forceVent[i][1].toUInt();
break;
}
}
}else if (name == "windgustmph")
if (propertyList["forcevent"].toString() != msg or propertyList["rafales"].toString() != msg)
{
if (name == "windspeedmph")
{
propertyList["forcevent"] = msg;
msg.prepend("Vent - ");
}else
{
propertyList["rafales"] = msg;
msg.prepend("Rafales - ");
}
QString msgNotif = formatNotifString (msg, propertyName[name].second , QByteArray::number(propertyValue));
notif += msgNotif;
setPriority(priority, windPriority);
propertyList["winddir"] = winddir;
attachment = this->outputPath;
if (priority > 3)
{
notify(msgNotif, priorityList[priority], attachment);
}else if (timeWind < QDateTime::currentDateTime())
{
timeWind = timeWind.currentDateTime().addSecs(300);
changed = true;
}
debug (DEBUGMACRO, "Notif = *" + notif + "*", DEBUG);
}
/*}else if (name == "windgustmph")
{
propertyValue = round(mphTokmh(pair.second.toFloat()));
if (compare (propertyList[name], propertyValue, 5) and propertyValue > 20)
@@ -246,7 +294,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
priority = setPriority (priority, 5);
propertyList[name] = propertyValue;
debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
}
}*/
}else if (name == "rainin")
{
static double ecart;
@@ -258,31 +306,51 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
{
ecart = 0.01;
}
if (compare (propertyList[name], propertyValue, ecart))
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
if (compare (propertyList[name].toFloat(), propertyValue, ecart))
{
notif += formatNotifString (propertyName[name].first, propertyName[name].second , value);
//notif += formatNotifString (propertyName[name].first, propertyName[name].second , value);
priority = setPriority (priority, 4);
debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
//debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
propertyList[name] = propertyValue;
changed = true;
}
}else if (name == "baromin")
{
propertyValue = tohPa(pair.second.toFloat());
debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
if (compare (propertyList[name], propertyValue, 5))
debug (DEBUGMACRO, "Barometre en hPa : " + QByteArray::number(propertyValue), DEBUG);
if (compare (propertyList[name].toFloat(), propertyValue, 0.5))
{
pressureVariation(propertyValue);
notif += formatNotifString (propertyName[name].first, propertyName[name].second , QByteArray::number(propertyValue));
//notif += formatNotifString (propertyName[name].first, propertyName[name].second , QByteArray::number(propertyValue));
//debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
propertyList[name] = propertyValue;
changed = true;
}
static double prevision;
QString ret = pressureVariation(propertyValue);
if (!ret.isEmpty())
{
debug (DEBUGMACRO, "baromin ret not empty : " + QByteArray::number(propertyValue), DEBUG);
QStringList liste = ret.split(",");
double newPrevision = liste[1].toInt();
if (prevision != newPrevision)
{
prevision = newPrevision;
propertyList["prevision"] = prevision;
//notif += prevision + " \n";
//debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
changed = true;
}
}
}else if (name == "UV")
{
{
static QDateTime timeUV = QDateTime::currentDateTime().addSecs(-600);
propertyValue = pair.second.toFloat();
if (compare (propertyList[name], propertyValue, 1) and timeUV < QDateTime::currentDateTime())
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
if (compare (propertyList[name].toFloat(), propertyValue, 1) and timeUV < QDateTime::currentDateTime())
{
notif += formatNotifString (propertyName[name].first, propertyName[name].second , value);
//notif += formatNotifString (propertyName[name].first, propertyName[name].second , value);
if (propertyValue == 5 )
priority = setPriority (priority, 3);
if (propertyValue >= 6 )
@@ -291,22 +359,23 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
propertyList[name] = propertyValue;
debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
}
}else if (name == "lowbat")
}/*else if (name == "lowbat")
{
static QDateTime timeLowBat = QDateTime::currentDateTime().addSecs(-4000);
if (pair.second.toInt() == 0 and timeLowBat < QDateTime::currentDateTime())
{
notif += formatNotifString (propertyName[name].first, propertyName[name].second );
debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
//notif += formatNotifString (propertyName[name].first, propertyName[name].second );
//debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
priority = setPriority (priority, 4);
timeLowBat = timeLowBat.currentDateTime().addSecs(3600);
propertyList[name] = propertyValue;
}
}
}*/
}
}
if (!jsonString.isEmpty())
{
debug(DEBUGMACRO, "json string : " + jsonString, DEBUG);
jsonString = jsonString +", " + deviceString + "}}";
mqttClient->send_message(jsonString);
}else
@@ -314,16 +383,49 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
debug(DEBUGMACRO, "No values to send", DEBUG);
}
if (!notif.isEmpty())
if (changed)
{
debug(DEBUGMACRO, "looping to fill notif", DEBUG);
for (auto [name, value]: propertyList.asKeyValueRange())
{
QString unit;
QByteArray valueBA;
debug(DEBUGMACRO, "Name = " + name + ", value = " + QString::number(value.toUInt()), DEBUG);
if (! propertyName.contains(name))
{
unit = "";
debug(DEBUGMACRO, "unit is empty ", DEBUG);
}else
{
unit = propertyName[name].second;
debug(DEBUGMACRO, "unit : " + unit, DEBUG);
QString dataType = value.typeName();
debug(DEBUGMACRO, "datatype is : " + dataType, DEBUG);
if (dataType == "double")
{
debug(DEBUGMACRO, "datatype is 'double'", DEBUG);
valueBA = QByteArray::number(value.toFloat());
}else if (dataType == "QString")
{
debug(DEBUGMACRO, "datatype is 'QString'" + value.toString(), DEBUG);
valueBA = value.toByteArray();
}else
{
debug(DEBUGMACRO, "datatype is null" + QString::number(value.toUInt()), DEBUG);
valueBA = value.toByteArray();
}
notif += formatNotifString(propertyName[name].first, unit, valueBA);
}
}
debug(DEBUGMACRO, "calling notify with notif = #" + notif + "#", DEBUG);
notify (notif, priorityList[priority]);
notify (notif, priorityList[priority], attachment);
}
debug(DEBUGMACRO, "parseData: Returning", DEBUG);
}
quint8 previsionMeteo(double currentPressure, double variation3h)
{
debug (DEBUGMACRO, "begin", DEBUG);
if (currentPressure > 1020.0 && variation3h >= 0.0)
{
return 0;
@@ -386,8 +488,10 @@ QString pressureVariation(double currentPressure)
{
priority = "urgent";
}
return previsionList[prevision] + "," + priority;
debug(DEBUGMACRO, "ending pressureVariation with result", DEBUG);
return QByteArray::number(prevision) + "," + priority;
}
debug(DEBUGMACRO, "ending pressureVariation no result", DEBUG);
return "";
}
@@ -409,7 +513,7 @@ double fahrenheitToCelsius (double fahrenheit)
double tohPa (double value)
{
return value * 33.8639;
return round(value * 33.8639 * 100) / 100;
}
double mphTokmh (double value)

View File

@@ -20,7 +20,7 @@
#define ERROR 8 // => 8
#define ALERT 32
#define ALL DEBUG | INFO | NOTICE | WARNING | ERROR | ALERT
#define DEBUGMACRO QString(__FILE__) + ": " + QString::number(__LINE__) + " -> " + QString(Q_FUNC_INFO)
#define DEBUGMACRO QString(__FILE__) + ": " + QString::number(__LINE__) + " -> "
void debug(QString debugHeader, QString msg, uint8_t level=ALL, QByteArray value="");
//QString addValue(QByteArray value);
@@ -39,8 +39,8 @@ class Pws2mqtt : public QObject
uint listenPort = 5000;
int sockfd = 0;
int newsockfd = 0;
QString inputPath = "./fleche.png";
QString outpuPath = "/tmp/pws2mqttFleche.png";
QString inputPath = "/usr/local/share/pws2mqtt/fleche.png";
QString outputPath = "/tmp/pws2mqttFleche.png";
QList <QString> deviceProperties =
{
"ieeeAddress", "type", "dateutc", "softwaretype", "action", "realtime", "freq", "wh65batt", "wh25batt", "runtime"

View File

@@ -3,6 +3,6 @@
#include <string>
std::string version = "1.0.39";
std::string version = "1.0.69";
#endif // VERSION_H