diff --git a/fleche.png b/fleche.png new file mode 100644 index 0000000..2d633fe Binary files /dev/null and b/fleche.png differ diff --git a/main.cpp b/main.cpp index 843b110..ede206e 100644 --- a/main.cpp +++ b/main.cpp @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) pws2mqtt = new Pws2mqtt; pws2mqtt->listeningHttp(); - notify (QString("Program started"), "default"); + //notify (QString("Program started"), "default"); a.exec(); diff --git a/pws2mqtt-qt.pro b/pws2mqtt-qt.pro deleted file mode 100644 index c346d13..0000000 --- a/pws2mqtt-qt.pro +++ /dev/null @@ -1,31 +0,0 @@ -QT = gui -QT += network -QT += core -QT += mqtt -QT += httpserver - -LIBS += -lcurl - -CONFIG += c++17 console -CONFIG -= app_bundle - -# You can make your code fail to compile if it uses deprecated APIs. -# In order to do so, uncomment the following line. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -SOURCES += \ -main.cpp \ -mqtt.cpp \ -pws2mqtt.cpp - -# Default rules for deployment. -qnx: target.path = /tmp/$${TARGET}/bin -else: unix:!android: target.path = /opt/$${TARGET}/bin -!isEmpty(target.path): INSTALLS += target - -HEADERS += \ -httpserver.h \ -mqtt.h \ -pws2mqtt.h \ -version.h - diff --git a/pws2mqtt-qt.pro.user b/pws2mqtt-qt.pro.user deleted file mode 100644 index c8d942e..0000000 --- a/pws2mqtt-qt.pro.user +++ /dev/null @@ -1,404 +0,0 @@ - - - - - - EnvironmentId - {db2284ae-177e-4753-8e1e-1e0e73c52ae1} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - false - true - false - 0 - true - true - 0 - 8 - true - false - 1 - true - true - true - *.md, *.MD, Makefile - false - true - true - - - - ProjectExplorer.Project.PluginSettings - - - true - false - true - true - true - true - - - 0 - true - - true - true - Builtin.DefaultTidyAndClazy - 1 - - - - true - - - true - - - - - ProjectExplorer.Project.Target.0 - - Desktop - Qt 6.4.1 (qt6) - Qt 6.4.1 (qt6) - {17b0ba8e-e6fe-4c71-98eb-9b4d3bcc4307} - 0 - 0 - 0 - - 1 - /home/daniel/develop/pws2mqtt-qt/build/debug - /home/daniel/develop/pws2mqtt-qt/build/debug - - - true - -x versioning -s 1 - bash - %{ActiveProject:NativePath} - ProjectExplorer.ProcessStep - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 3 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - 1 - - - /home/daniel/develop/pws2mqtt-qt/build/Release - /home/daniel/develop/pws2mqtt-qt/build/Release - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - 2 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - true - true - true - - 2 - - Qt4ProjectManager.Qt4RunConfiguration:/home/daniel/develop/pws2mqtt-qt/pws2mqtt-qt.pro - /home/daniel/develop/pws2mqtt-qt/pws2mqtt-qt.pro - false - true - true - false - true - false - /home/daniel/develop/pws2mqtt-qt/build/debug - - 1 - - - - ProjectExplorer.Project.Target.1 - - Desktop - Desktop - Desktop - {96ba01cf-98b6-46f1-b1a8-6cf5d7804e77} - 0 - 0 - 0 - - 0 - /home/daniel/develop/pws2mqtt-qt/../build-pws2mqtt-qt-Desktop-Debug - /home/daniel/develop/build-pws2mqtt-qt-Desktop-Debug - - - true - -s 1 - versioning - %{buildDir} - ProjectExplorer.ProcessStep - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 3 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - - - /home/daniel/develop/pws2mqtt-qt/../build-pws2mqtt-qt-Desktop-Release - /home/daniel/develop/build-pws2mqtt-qt-Desktop-Release - - - true - QtProjectManager.QMakeBuildStep - true - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - - 0 - /home/daniel/develop/pws2mqtt-qt/../build-pws2mqtt-qt-Desktop-Profile - /home/daniel/develop/build-pws2mqtt-qt-Desktop-Profile - - - true - QtProjectManager.QMakeBuildStep - true - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - true - true - true - - 2 - - Qt4ProjectManager.Qt4RunConfiguration:/home/daniel/develop/pws2mqtt-qt/pws2mqtt-qt.pro - /home/daniel/develop/pws2mqtt-qt/pws2mqtt-qt.pro - false - true - true - false - true - - 1 - - - - ProjectExplorer.Project.TargetCount - 2 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/pws2mqtt.cpp b/pws2mqtt.cpp index 554b3a9..1dc875a 100644 --- a/pws2mqtt.cpp +++ b/pws2mqtt.cpp @@ -39,7 +39,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 propertyList; +QMap propertyList; QMap propertiesValue; QMap > propertyName { @@ -146,15 +146,15 @@ void Pws2mqtt::parseData(QList> queryList) QString jsonString = "{"; bool propertyFlag = false; bool deviceFlag = false; -// QString topic; + // QString topic; QString deviceString = "\"device\": {\"ieeeAddress\": \"" + mqttClient->macAddress + "\", \"type\": \"" + mqttClient->type + "\", \"powerSource\": \"Battery\""; QString notif = ""; double propertyValue = 0; QStringList priorityList {"", "min", "low", "default", "High", "urgent"}; quint8 priority = 2; - static qreal winddir = 0; + //static qreal winddir = 0; QString attachment = ""; - bool changed = false; + static QDateTime timer; debug(DEBUGMACRO, "looping list of query", DEBUG); @@ -199,21 +199,9 @@ void Pws2mqtt::parseData(QList> queryList) //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; + propertyList[name] = formatNotifString(propertyName[name].first, propertyName[name].second, QByteArray::number(propertyValue)); propertiesValue[name] = propertyValue; - changed = true; } - /*}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))); - debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG); - timeIndoorTemp = timeIndoorTemp.currentDateTime().addSecs(300); - propertyList[name] = propertyValue; - }*/ }else if (name == "humidity") { propertyValue = value.toFloat(); @@ -222,9 +210,8 @@ void Pws2mqtt::parseData(QList> queryList) if (compare (propertiesValue[name], propertyValue, 3)) { //notif += formatNotifString (propertyName[name].first, propertyName[name].second , value); - propertyList[name] = propertyValue; + propertyList[name] = formatNotifString(propertyName[name].first, propertyName[name].second, QByteArray::number(propertyValue)); propertiesValue[name] = propertyValue; - changed = true; } }else if (name == "windchillf") { @@ -236,22 +223,23 @@ void Pws2mqtt::parseData(QList> queryList) //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; + propertyList[name] = formatNotifString(propertyName[name].first, propertyName[name].second, QByteArray::number(propertyValue)); propertiesValue[name] = propertyValue; - changed = true; } }else if (name == "winddir") { - winddir = value.toFloat(); - rotateAndSaveImage(this->inputPath, this->outputPath, (qreal)winddir); + propertyValue = value.toFloat(); + rotateAndSaveImage(this->inputPath, this->outputPath, (qreal)propertyValue); debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG); + propertyList[name] = formatNotifString(propertyName[name].first, propertyName[name].second, QByteArray::number(propertyValue)); + propertiesValue[name] = propertyValue; }else if (name == "windspeedmph" or name == "windgustmph") { QString msg = ""; static QDateTime timeWind = QDateTime::currentDateTime().addSecs(-600); quint8 windPriority = 1; - static QString msgNotif; + //static QString msgNotif; debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG); propertyValue = round(mphTokmh(value.toFloat())); @@ -260,57 +248,31 @@ void Pws2mqtt::parseData(QList> queryList) if (propertyValue <= forceVent[i][0].toDouble()) { msg = forceVent[i][1].toString(); - windPriority = forceVent[i][1].toUInt(); + windPriority = forceVent[i][2].toUInt(); break; } } - if (propertyList["forcevent"].toString() != msg or propertyList["rafales"].toString() != msg) + if (propertyList["forcevent"] != msg or propertyList["rafales"] != msg) { if (name == "windspeedmph") { - propertyList["forcevent"] = msg; + //propertyList["forcevent"] = msg; msg.prepend("Vent - "); + propertyList[name] = formatNotifString (msg, propertyName[name].second , QByteArray::number(propertyValue)); }else { - propertyList["rafales"] = msg; - msg.prepend("Rafales - "); + propertyList[name] = formatNotifString (propertyName[name].first, propertyName[name].second , QByteArray::number(propertyValue)); } - msgNotif = formatNotifString (msg, propertyName[name].second , QByteArray::number(propertyValue)); setPriority(priority, windPriority); - propertyList["winddir"] = winddir; attachment = this->outputPath; - if (priority > 3) - { - notify(msgNotif, priorityList[priority], attachment); - }else if (timeWind < QDateTime::currentDateTime() or propertyValue > 20) - { - timeWind = timeWind.currentDateTime().addSecs(300); - changed = true; - } - - debug (DEBUGMACRO, "Notif = *" + notif + "*", DEBUG); } - notif += msgNotif; - - /*}else if (name == "windgustmph") - { - propertyValue = round(mphTokmh(pair.second.toFloat())); - if (compare (propertyList[name], propertyValue, 5) and propertyValue > 20) - { - notif += formatNotifString (propertyName[name].first, propertyName[name].second , QByteArray::number(propertyValue)); - if (propertyValue > 40) - priority = setPriority (priority, 4); - if (propertyValue > 60) - priority = setPriority (priority, 5); - propertyList[name] = propertyValue; - debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG); - }*/ }else if (name == "rainin") { static double ecart; - propertyValue = pair.second.toFloat(); + quint8 raininPriority = 1; + propertyValue = round(pair.second.toFloat()*100)/100; if (propertyValue == 0) { ecart = 0.0001; @@ -321,18 +283,16 @@ void Pws2mqtt::parseData(QList> queryList) debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG); if (compare (propertiesValue[name], propertyValue, ecart)) { - //notif += formatNotifString (propertyName[name].first, propertyName[name].second , value); - QString pluviosite = getPluviosite(propertyValue); - priority = setPriority (priority, 4); + QString pluviosite = getPluviosite(propertyValue, raininPriority); + priority = setPriority (priority, raininPriority); //debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG); - propertyList[name] = pluviosite + " : " + QString::number(round(propertyValue*100)/100); + propertyList[name] = formatNotifString(pluviosite + " : ", propertyName[name].second, QByteArray::number(propertyValue)); propertiesValue[name] = propertyValue; - changed = true; } }else if (name == "dailyrainin") { static double ecart; - propertyValue = pair.second.toFloat(); + propertyValue = round(pair.second.toFloat()*100)/100; if (propertyValue == 0) { ecart = 0.0001; @@ -345,9 +305,8 @@ void Pws2mqtt::parseData(QList> queryList) { priority = setPriority (priority, 3); //debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG); - propertyList[name] = propertyValue; + propertyList[name] = formatNotifString(propertyName[name].first, propertyName[name].second, QByteArray::number(propertyValue)); propertiesValue[name] = propertyValue; - changed = true; } }else if (name == "baromin") { @@ -359,27 +318,24 @@ void Pws2mqtt::parseData(QList> queryList) { //notif += formatNotifString (propertyName[name].first, propertyName[name].second , QByteArray::number(propertyValue)); //debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG); - propertyList[name] = propertyValue; + propertyList[name] = formatNotifString(propertyName[name].first, "", QByteArray::number(propertyValue)); propertiesValue[name] = propertyValue; - changed = true; } static QString prevision; - QString ret = pressureVariation(propertyValue, priority); + quint8 prevPriority = 0; + QString ret = pressureVariation(propertyValue, prevPriority); if (!ret.isEmpty()) { debug (DEBUGMACRO, "baromin ret not empty : " + ret, DEBUG); QString newPrevision = ret; - priority = setPriority(priority, priority); + priority = setPriority(priority, prevPriority); if (prevision != newPrevision) { prevision = newPrevision; - propertyList["prevision"] = prevision; - //debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG); - //changed = true; + propertyList["prevision"] = "- " + prevision + " \n"; } } - notif += prevision + " \n"; }else if (name == "UV") { static QDateTime timeUV = QDateTime::currentDateTime().addSecs(-600); @@ -390,26 +346,15 @@ void Pws2mqtt::parseData(QList> queryList) { //notif += formatNotifString (propertyName[name].first, propertyName[name].second , value); if (propertyValue == 5 ) - priority = setPriority (priority, 3); - if (propertyValue >= 6 ) priority = setPriority (priority, 4); + if (propertyValue >= 6 ) + priority = setPriority (priority, 5); timeUV = timeUV.currentDateTime().addSecs(300); - propertyList[name] = propertyValue; + propertyList[name] = formatNotifString(propertyName[name].first, "", QByteArray::number(propertyValue)); propertiesValue[name] = propertyValue; debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG); } - }/*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); - priority = setPriority (priority, 4); - timeLowBat = timeLowBat.currentDateTime().addSecs(3600); - propertyList[name] = propertyValue; - } - }*/ + } } } if (!jsonString.isEmpty()) @@ -422,39 +367,16 @@ void Pws2mqtt::parseData(QList> queryList) debug(DEBUGMACRO, "No values to send", DEBUG); } - if (changed) + debug(DEBUGMACRO, "current datetime : " + QDateTime::currentDateTime().toString() + ", timer = " + timer.toString(), DEBUG); + + if (priority > 3 or QDateTime::currentDateTime() > timer.addSecs(900)) { - debug(DEBUGMACRO, "looping to fill notif", DEBUG); + timer = QDateTime::currentDateTime(); + debug(DEBUGMACRO, "looping to fill notif, priority = " + QString::number(priority), 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(round(value.toFloat()*100)/100); - }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, "Name = " + name + ", value = " + value, DEBUG); + notif += propertyList[name]; } debug(DEBUGMACRO, "calling notify with notif = #" + notif + "#", DEBUG); notify (notif, priorityList[priority], attachment); @@ -462,7 +384,7 @@ void Pws2mqtt::parseData(QList> queryList) debug(DEBUGMACRO, "parseData: Returning", DEBUG); } -QString getPluviosite(double value) +QString getPluviosite(double value, quint8 &priority) { if (value < 1) { @@ -470,15 +392,18 @@ QString getPluviosite(double value) }else if (value < 5) { return "Pluie Modérée"; - }else if (value < 15) + }else if (value < 10) { + priority = 4; return "Pluie forte"; - }else if (value > 30) + }else if (value < 30) { - return "Évènement extrème"; - }else if (value > 15) + priority = 5; + return "Pluie Très forte, risque d'inondation"; + }else { - return "Forte pluie"; + priority = 5; + return "Pluie diluvienne, risque élevé d'inondations, crues"; } } diff --git a/pws2mqtt.h b/pws2mqtt.h index c36392d..0188d80 100644 --- a/pws2mqtt.h +++ b/pws2mqtt.h @@ -60,7 +60,7 @@ void notify (QString notif, QString priority = "low", QString inputPath = ""); quint8 setPriority (quint8 currentPriority, quint8 newPriority); QString previsionMeteo(double currentPressure, double variation3h, quint8 &priority); QString pressureVariation(double currentPressure, quint8 &priority); -QString getPluviosite(double value); +QString getPluviosite(double value, quint8 &priority); void rotateAndSaveImage(const QString &inputPath, const QString &outputPath, qreal angle=0); #endif // PWS2MQTT_H diff --git a/version.h b/version.h index c2d4ea3..065e7e6 100644 --- a/version.h +++ b/version.h @@ -3,6 +3,6 @@ #include -std::string version = "1.0.42"; +std::string version = "1.0.54"; #endif // VERSION_H