diff --git a/fleche.png b/fleche.png deleted file mode 100644 index eca26ea..0000000 Binary files a/fleche.png and /dev/null differ diff --git a/main.cpp b/main.cpp index ad887c1..16cb376 100644 --- a/main.cpp +++ b/main.cpp @@ -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) { diff --git a/pws2mqtt-qt.pro.user b/pws2mqtt-qt.pro.user index ca68089..58670d4 100644 --- a/pws2mqtt-qt.pro.user +++ b/pws2mqtt-qt.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -85,6 +85,97 @@ ProjectExplorer.Project.Target.0 + + Desktop + Qt 6.4.1 (qt6) + Qt 6.4.1 (qt6) + {17b0ba8e-e6fe-4c71-98eb-9b4d3bcc4307} + 0 + 0 + 0 + + 0 + /home/daniel/develop/build-pws2mqtt-qt-Desktop-Debug + /home/daniel/develop/build-pws2mqtt-qt-Desktop-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 + + + 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/build-pws2mqtt-qt-Desktop-Debug + + 1 + + + + ProjectExplorer.Project.Target.1 Desktop Desktop @@ -99,16 +190,23 @@ /home/daniel/develop/build-pws2mqtt-qt-Desktop-Debug + true + -s 1 + versioning + %{buildDir} + ProjectExplorer.ProcessStep + + true QtProjectManager.QMakeBuildStep false - + true Qt4ProjectManager.MakeStep - 2 + 3 Build Build ProjectExplorer.BuildSteps.Build @@ -243,88 +341,6 @@ true false true - /home/daniel/develop/build-pws2mqtt-qt-Desktop-Debug - - 1 - - - - ProjectExplorer.Project.Target.1 - - Desktop - Qt 6.4.1 (qt6) - Qt 6.4.1 (qt6) - {17b0ba8e-e6fe-4c71-98eb-9b4d3bcc4307} - 0 - 0 - 0 - - 0 - /home/daniel/develop/build-pws2mqtt-qt-Desktop-Debug - /home/daniel/develop/build-pws2mqtt-qt-Desktop-Debug - - - 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 - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - - 1 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - true - true - true - - 2 - - ProjectExplorer.CustomExecutableRunConfiguration - - false - true - false - true 1 diff --git a/pws2mqtt.cpp b/pws2mqtt.cpp index 613a61c..39026c4 100644 --- a/pws2mqtt.cpp +++ b/pws2mqtt.cpp @@ -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 propertyList; +QMap propertyList; QMap > propertyName { {"tempf", {"Température extérieure", "°C"}}, @@ -41,12 +41,12 @@ QMap > 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 > propertyName {"UV", {"Alerte UV", ""}} }; +QList > 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> queryList) double propertyValue = 0; QStringList priorityList {"", "min", "low", "default", "High", "urgent"}; quint8 priority = 2; - QPair 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> 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> 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 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> 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> 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> 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> 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) diff --git a/pws2mqtt.h b/pws2mqtt.h index 4631d69..ffe9944 100644 --- a/pws2mqtt.h +++ b/pws2mqtt.h @@ -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 deviceProperties = { "ieeeAddress", "type", "dateutc", "softwaretype", "action", "realtime", "freq", "wh65batt", "wh25batt", "runtime" diff --git a/version.h b/version.h index 2baadc4..a6bac64 100644 --- a/version.h +++ b/version.h @@ -3,6 +3,6 @@ #include -std::string version = "1.0.39"; +std::string version = "1.0.69"; #endif // VERSION_H