- cleaning, optimization\- added lowbat detection
This commit is contained in:
1 parent
5e4712503b
commit
798407fbf5
2 files changed
+41
-27
No files matched your search
+40
-22
@@ -38,9 +38,7 @@ QStringList previsionList
|
|||||||
"Temps stable"
|
"Temps stable"
|
||||||
};
|
};
|
||||||
|
|
||||||
QMap <QByteArray, QString> propertyList;
|
|
||||||
QMap <QByteArray, QString> precPropertyList;
|
QMap <QByteArray, QString> precPropertyList;
|
||||||
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"}},
|
||||||
@@ -146,11 +144,11 @@ void Pws2mqtt::init()
|
|||||||
//return QHttpServerResponse("text/plain", "Success\n");
|
//return QHttpServerResponse("text/plain", "Success\n");
|
||||||
});
|
});
|
||||||
|
|
||||||
for (auto [name, pair]: propertyName.asKeyValueRange())
|
/* for (auto [name, pair]: propertyName.asKeyValueRange())
|
||||||
{
|
{
|
||||||
propertyList[name].append(formatNotifString(pair, "0"));
|
propertyList[name].append(formatNotifString(pair, "0"));
|
||||||
debug (DEBUGMACRO, "Init " + name + " => " + propertyList[name], DEBUG);
|
debug (DEBUGMACRO, "Init " + name + " => " + propertyList[name], DEBUG);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void notify(QString notif, QString priority, QString inputPath, QString tag)
|
void notify(QString notif, QString priority, QString inputPath, QString tag)
|
||||||
@@ -228,6 +226,8 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
#endif
|
#endif
|
||||||
QString notif = "";
|
QString notif = "";
|
||||||
QStringList priorityList {"", "min", "low", "default", "High", "urgent"};
|
QStringList priorityList {"", "min", "low", "default", "High", "urgent"};
|
||||||
|
QMap <QByteArray, QString> propertyList;
|
||||||
|
QMap <QByteArray, double> propertiesValue;
|
||||||
QString attachment = "";
|
QString attachment = "";
|
||||||
QString tag = "";
|
QString tag = "";
|
||||||
double propertyValue = 0;
|
double propertyValue = 0;
|
||||||
@@ -351,7 +351,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
QString msg = "";
|
QString msg = "";
|
||||||
static QDateTime timeWind = QDateTime::currentDateTime().addSecs(-600);
|
static QDateTime timeWind = QDateTime::currentDateTime().addSecs(-600);
|
||||||
|
|
||||||
propertiesValue[name] = round(mphTokmh(value.toFloat()) );
|
propertiesValue[name] = round(mphTokmh(value.toFloat()));
|
||||||
|
|
||||||
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertiesValue[name]) + " km/h", DEBUG);
|
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertiesValue[name]) + " km/h", DEBUG);
|
||||||
|
|
||||||
@@ -365,7 +365,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
}else if (name == "rainin")
|
}else if (name == "rainin")
|
||||||
{
|
{
|
||||||
static double ecart;
|
static double ecart;
|
||||||
quint8 raininPriority = 1;
|
quint8 raininPriority;
|
||||||
propertyValue = round(pair.second.toFloat()*100)/100.0;
|
propertyValue = round(pair.second.toFloat()*100)/100.0;
|
||||||
if (propertyValue <= 0.01)
|
if (propertyValue <= 0.01)
|
||||||
{
|
{
|
||||||
@@ -373,7 +373,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
ecart = 0.0001;
|
ecart = 0.0001;
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
raininPriority = 3;
|
raininPriority = 5;
|
||||||
ecart = 0.01;
|
ecart = 0.01;
|
||||||
}
|
}
|
||||||
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
|
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
|
||||||
@@ -442,16 +442,25 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
priority[name] = setPriority (priority[name], 5);
|
priority[name] = setPriority (priority[name], 5);
|
||||||
timeUV = timeUV.currentDateTime().addSecs(300);
|
timeUV = timeUV.currentDateTime().addSecs(300);
|
||||||
propertiesValue[name] = propertyValue;
|
propertiesValue[name] = propertyValue;
|
||||||
debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
|
//debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
|
||||||
propertyList[name] = "- UV - " + QByteArray::number(propertyValue) + "\n";
|
propertyList[name] = "- UV - " + QByteArray::number(propertyValue) + "\n";
|
||||||
}
|
}
|
||||||
debug (DEBUGMACRO, "priority = " + QString::number(priority[name]), DEBUG);
|
debug (DEBUGMACRO, "priority = " + QString::number(priority[name]), DEBUG);
|
||||||
}else if (name == "solarradiation")
|
}else if (name == "solarradiation")
|
||||||
{
|
{
|
||||||
propertyValue = pair.second.toFloat()*100/100;
|
propertyValue = round(pair.second.toFloat()*100)/100.0;
|
||||||
propertyList[name] = formatNotifString(propertyName[name], QByteArray::number(propertyValue));
|
propertyList[name] = formatNotifString(propertyName[name], QByteArray::number(propertyValue));
|
||||||
propertiesValue[name] = round(pair.second.toFloat()*100/100);
|
propertiesValue[name] = propertyValue;
|
||||||
debug (DEBUGMACRO, "solarradiations : " + QByteArray::number(propertyValue), DEBUG);
|
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
|
||||||
|
}else if (name == "lowbat")
|
||||||
|
{
|
||||||
|
if (pair.second.toUInt() != 0)
|
||||||
|
{
|
||||||
|
priority[name] = 5;
|
||||||
|
propertyList[name] = formatNotifString(propertyName[name], QByteArray::number(propertyValue));
|
||||||
|
propertiesValue[name] = propertyValue;
|
||||||
|
debug (DEBUGMACRO, name + " : " + QByteArray::number(propertyValue), DEBUG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
debug(DEBUGMACRO, "propertyList[name] = " + propertyList[name], DEBUG);
|
debug(DEBUGMACRO, "propertyList[name] = " + propertyList[name], DEBUG);
|
||||||
@@ -491,7 +500,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
{
|
{
|
||||||
timer = QDateTime::currentDateTime();
|
timer = QDateTime::currentDateTime();
|
||||||
start = true;
|
start = true;
|
||||||
notif = listProperties2notify (propertyList, priority, 0);
|
notif = listProperties2notify (precPropertyList, propertyList, priority, 0);
|
||||||
notify (notif, priorityList[aPriority], attachment, tag);
|
notify (notif, priorityList[aPriority], attachment, tag);
|
||||||
precPropertyList = propertyList;
|
precPropertyList = propertyList;
|
||||||
debug(DEBUGMACRO, "calling notify with notif = #" + notif + "#", INFO);
|
debug(DEBUGMACRO, "calling notify with notif = #" + notif + "#", INFO);
|
||||||
@@ -502,24 +511,24 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
}
|
}
|
||||||
if (aPriority >= 3)
|
if (aPriority >= 3)
|
||||||
{
|
{
|
||||||
notif = "**ALERTES**\n" + listProperties2notify (propertyList, priority, 3);
|
notif = "**ALERTES**\n" + listProperties2notify (precPropertyList, propertyList, priority, 3);
|
||||||
precPropertyList = propertyList;
|
precPropertyList = propertyList;
|
||||||
notify (notif, priorityList[aPriority], attachment, tag);
|
notify (notif, priorityList[aPriority], attachment, tag);
|
||||||
}
|
}
|
||||||
debug(DEBUGMACRO, "parseData: Returning", DEBUG);
|
debug(DEBUGMACRO, "parseData: Returning", DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString listProperties2notify (const QMap <QByteArray, QString> &propertyList, QHash <QByteArray, quint8> priority, quint8 minAlert)
|
QString listProperties2notify (const QMap <QByteArray, QString> &precPropertyList, const QMap <QByteArray, QString> &propertyList, QHash <QByteArray, quint8> priority, quint8 minAlert)
|
||||||
{
|
{
|
||||||
static QHash <QByteArray, quint8> announced = {};
|
static QHash <QByteArray, quint8> announced = {};
|
||||||
QString notif = "";
|
QString notif = "";
|
||||||
for (auto [name, value]: propertyList.asKeyValueRange())
|
for (auto [name, value]: propertyName.asKeyValueRange())
|
||||||
{
|
{
|
||||||
debug(DEBUGMACRO, "property : " + name + " value : " + value, DEBUG);
|
debug(DEBUGMACRO, "property : " + name, DEBUG);
|
||||||
if (name != "prevision")
|
//if (name != "prevision")
|
||||||
{
|
|
||||||
//if (precPropertyList.contains(name))
|
|
||||||
//{
|
//{
|
||||||
|
if (propertyList.contains(name))
|
||||||
|
{
|
||||||
//if (precPropertyList[name] != propertyList[name])
|
//if (precPropertyList[name] != propertyList[name])
|
||||||
//{
|
//{
|
||||||
if (minAlert == 0)
|
if (minAlert == 0)
|
||||||
@@ -542,11 +551,20 @@ QString listProperties2notify (const QMap <QByteArray, QString> &propertyList,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//}
|
//}
|
||||||
|
}else if (precPropertyList.contains(name))
|
||||||
|
{
|
||||||
|
notif += precPropertyList[name];
|
||||||
|
debug(DEBUGMACRO, "notif : " + notif, DEBUG);
|
||||||
|
}
|
||||||
//}
|
//}
|
||||||
|
|
||||||
debug(DEBUGMACRO, "Name = " + name + ", value = " + value, DEBUG);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
/* if (propertyList.contains("prevision"))
|
||||||
|
{
|
||||||
|
notif += propertyList["prevision"];
|
||||||
|
}else if (precPropertyList.contains("prevision"))
|
||||||
|
{
|
||||||
|
notif += precPropertyList["prevision"];
|
||||||
|
}*/
|
||||||
return notif;
|
return notif;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-5
@@ -45,10 +45,6 @@ class Pws2mqtt : public QObject
|
|||||||
int newsockfd = 0;
|
int newsockfd = 0;
|
||||||
QString inputPath = "/usr/local/share/pws2mqtt/fleche.png";
|
QString inputPath = "/usr/local/share/pws2mqtt/fleche.png";
|
||||||
QString outputPath = "/tmp/pws2mqttFleche.png";
|
QString outputPath = "/tmp/pws2mqttFleche.png";
|
||||||
QList <QString> deviceProperties =
|
|
||||||
{
|
|
||||||
"ieeeAddress", "type", "dateutc", "softwaretype", "action", "realtime", "freq", "wh65batt", "wh25batt", "runtime"
|
|
||||||
};
|
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void listeningHttp();
|
void listeningHttp();
|
||||||
@@ -68,5 +64,5 @@ void rotateAndSaveImage(const QString &inputPath, const QString &outputPath, qre
|
|||||||
double windChill(double airT, double vent);
|
double windChill(double airT, double vent);
|
||||||
double calculerHumidex(double temperature, double humiditeRelative);
|
double calculerHumidex(double temperature, double humiditeRelative);
|
||||||
void notify (QString notif, QString priority = "low", QString inputPath = "", QString tag = "");
|
void notify (QString notif, QString priority = "low", QString inputPath = "", QString tag = "");
|
||||||
QString listProperties2notify (const QMap<QByteArray, QString> &propertyList, QHash <QByteArray, quint8> priority, quint8 minAlert = 0);
|
QString listProperties2notify (const QMap<QByteArray, QString> &precPropertyList, const QMap<QByteArray, QString> &propertyList, QHash <QByteArray, quint8> priority, quint8 minAlert = 0);
|
||||||
|
|
||||||
Reference in new issue
Block a user