diff --git a/fleche.xcf b/fleche.xcf new file mode 100644 index 0000000..409ef3a Binary files /dev/null and b/fleche.xcf differ diff --git a/main.cpp b/main.cpp index a6c082b..843b110 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").toUtf8(), "default"); + notify (QString("Program started"), "default"); a.exec(); diff --git a/pws2mqtt-qt.pro.user b/pws2mqtt-qt.pro.user index df2be5c..c8d942e 100644 --- a/pws2mqtt-qt.pro.user +++ b/pws2mqtt-qt.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -81,6 +81,9 @@ true + + true + @@ -94,7 +97,7 @@ 0 0 - 0 + 1 /home/daniel/develop/pws2mqtt-qt/build/debug /home/daniel/develop/pws2mqtt-qt/build/debug @@ -139,6 +142,7 @@ Debug Qt4ProjectManager.Qt4BuildConfiguration 2 + 1 /home/daniel/develop/pws2mqtt-qt/build/Release diff --git a/pws2mqtt.cpp b/pws2mqtt.cpp index 03114f6..554b3a9 100644 --- a/pws2mqtt.cpp +++ b/pws2mqtt.cpp @@ -13,6 +13,8 @@ #include #include #include +#include +#include extern MqttClient *mqttClient; extern Pws2mqtt *pws2mqtt; @@ -38,6 +40,7 @@ static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *use } QMap propertyList; +QMap propertiesValue; QMap > propertyName { {"tempf", {"Température extérieure", "°C"}}, @@ -191,12 +194,13 @@ void Pws2mqtt::parseData(QList> queryList) propertyValue = round(fahrenheitToCelsius(fValue)); debug (DEBUGMACRO, "timeTemp = " + timeTemp.time().toString() + " - current :" + QDateTime::currentDateTime().toString() , DEBUG); - if (compare (propertyList[name].toDouble(), propertyValue, 1) and timeTemp < QDateTime::currentDateTime()) + if (compare (propertiesValue[name], propertyValue, 1) and timeTemp < QDateTime::currentDateTime()) { //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; + propertiesValue[name] = propertyValue; changed = true; } /*}else if (name == "indoortempf") @@ -215,10 +219,11 @@ void Pws2mqtt::parseData(QList> queryList) propertyValue = value.toFloat(); debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG); - if (compare (propertyList[name].toFloat(), propertyValue, 3)) + if (compare (propertiesValue[name], propertyValue, 3)) { //notif += formatNotifString (propertyName[name].first, propertyName[name].second , value); propertyList[name] = propertyValue; + propertiesValue[name] = propertyValue; changed = true; } }else if (name == "windchillf") @@ -226,12 +231,13 @@ void Pws2mqtt::parseData(QList> queryList) static QDateTime timeWindchill = QDateTime::currentDateTime().addSecs(-600); propertyValue = round(fahrenheitToCelsius(value.toFloat())); debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG); - if (compare (propertyList[name].toFloat(), propertyValue, 1) and timeWindchill < QDateTime::currentDateTime()) + if (compare (propertiesValue[name], 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); timeWindchill = timeWindchill.currentDateTime().addSecs(300); propertyList[name] = propertyValue; + propertiesValue[name] = propertyValue; changed = true; } }else if (name == "winddir") @@ -313,13 +319,34 @@ void Pws2mqtt::parseData(QList> queryList) ecart = 0.01; } debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG); - if (compare (propertyList[name].toFloat(), propertyValue, ecart)) + if (compare (propertiesValue[name], propertyValue, ecart)) { //notif += formatNotifString (propertyName[name].first, propertyName[name].second , value); QString pluviosite = getPluviosite(propertyValue); priority = setPriority (priority, 4); //debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG); propertyList[name] = pluviosite + " : " + QString::number(round(propertyValue*100)/100); + propertiesValue[name] = propertyValue; + changed = true; + } + }else if (name == "dailyrainin") + { + static double ecart; + propertyValue = pair.second.toFloat(); + if (propertyValue == 0) + { + ecart = 0.0001; + }else + { + ecart = 0.01; + } + debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG); + if (compare (propertiesValue[name], propertyValue, ecart)) + { + priority = setPriority (priority, 3); + //debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG); + propertyList[name] = propertyValue; + propertiesValue[name] = propertyValue; changed = true; } }else if (name == "baromin") @@ -328,11 +355,12 @@ void Pws2mqtt::parseData(QList> queryList) propertyValue = tohPa(pair.second.toFloat()); debug (DEBUGMACRO, "Barometre en hPa : " + QByteArray::number(propertyValue), DEBUG); - if (compare (propertyList[name].toFloat(), propertyValue, 0.5)) + if (compare (propertiesValue[name], propertyValue, 0.5)) { //notif += formatNotifString (propertyName[name].first, propertyName[name].second , QByteArray::number(propertyValue)); //debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG); propertyList[name] = propertyValue; + propertiesValue[name] = propertyValue; changed = true; } @@ -358,7 +386,7 @@ void Pws2mqtt::parseData(QList> queryList) propertyValue = pair.second.toFloat(); debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG); - if (compare (propertyList[name].toFloat(), propertyValue, 1) and timeUV < QDateTime::currentDateTime()) + if (compare (propertiesValue[name], propertyValue, 1) and timeUV < QDateTime::currentDateTime()) { //notif += formatNotifString (propertyName[name].first, propertyName[name].second , value); if (propertyValue == 5 ) @@ -367,6 +395,7 @@ void Pws2mqtt::parseData(QList> queryList) priority = setPriority (priority, 4); timeUV = timeUV.currentDateTime().addSecs(300); propertyList[name] = propertyValue; + propertiesValue[name] = propertyValue; debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG); } }/*else if (name == "lowbat") @@ -414,7 +443,7 @@ void Pws2mqtt::parseData(QList> queryList) if (dataType == "double") { debug(DEBUGMACRO, "datatype is 'double'", DEBUG); - valueBA = QByteArray::number(value.toFloat()); + valueBA = QByteArray::number(round(value.toFloat()*100)/100); }else if (dataType == "QString") { debug(DEBUGMACRO, "datatype is 'QString'" + value.toString(), DEBUG); @@ -594,6 +623,12 @@ QString formatNotifString (QString name, QString unit ,QByteArray value) 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; +} + void notify(QString notif, QString priority, QString inputPath) { CURL *curl; @@ -616,7 +651,7 @@ void notify(QString notif, QString priority, QString inputPath) headers = curl_slist_append(headers, "Config: /etc/ntfy.client.yml"); headers = curl_slist_append(headers, "Firebase: no"); - curl_mime *mime; + /*curl_mime *mime; curl_mimepart *part; // Initialise la structure mime @@ -626,13 +661,7 @@ void notify(QString notif, QString priority, QString inputPath) part = curl_mime_addpart(mime); curl_mime_name(part, "message"); curl_mime_data(part, notif.toUtf8().constData(), CURL_ZERO_TERMINATED); - - // Ajoute le fichier en pièce jointe - part = curl_mime_addpart(mime); - curl_mime_name(part, "attach"); - curl_mime_filedata(part, inputPath.toStdString().c_str()); - curl_mime_filename(part, QFileInfo(inputPath).fileName().toStdString().c_str()); - +*/ // Configure la requête POST curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:81/Meteo"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); @@ -653,12 +682,68 @@ void notify(QString notif, QString priority, QString inputPath) } // Nettoie les ressources - curl_mime_free(mime); + //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) diff --git a/version.h b/version.h index 64a4129..c2d4ea3 100644 --- a/version.h +++ b/version.h @@ -3,6 +3,6 @@ #include -std::string version = "1.0.33"; +std::string version = "1.0.42"; #endif // VERSION_H