67 lines
2.1 KiB
C++
67 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <QString>
|
|
#include <QByteArray>
|
|
#include <QObject>
|
|
#include <QtMqtt>
|
|
#include <QtMqtt/QMqttClient>
|
|
|
|
#define RED "\e[31m"
|
|
#define GREEN "\e[32m"
|
|
#define BLUE "\e[94m"
|
|
#define ORANGE "\e[33m"
|
|
#define NORMAL "\e[0m"
|
|
|
|
#define DEBUG 16 // => 16
|
|
#define INFO 1 // => 1
|
|
#define NOTICE 2 // => 2
|
|
#define WARNING 4 // => 4
|
|
#define ERROR 8 // => 8
|
|
#define ALERT 32
|
|
#define ALL DEBUG | INFO | NOTICE | WARNING | ERROR | ALERT
|
|
#define DEBUGMACRO QString(__FILE__) + ": " + QString::number(__LINE__) + " -> "
|
|
|
|
void debug(QString debugHeader, QString msg, uint8_t level=ALL, QByteArray value="");
|
|
//QString addValue(QByteArray value);
|
|
|
|
class Pws2mqtt : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
Pws2mqtt();
|
|
~Pws2mqtt();
|
|
|
|
QString ProcName = "pws2mqtt"; // name of the proceesus in ps, top, pstree, ...;
|
|
FILE * logFh = nullptr;
|
|
QString listenHost = "0.0.0.0";
|
|
uint listenPort = 5000;
|
|
int sockfd = 0;
|
|
int newsockfd = 0;
|
|
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"
|
|
};
|
|
|
|
void init();
|
|
void listeningHttp();
|
|
void parseData(QList<std::pair<QString, QString>> queryList);
|
|
};
|
|
|
|
double fahrenheitToCelsius(double fahrenheit);
|
|
double tohPa(double value);
|
|
bool compare (double value=0, double testValue=0, double ecart = 0.5);
|
|
QString formatNotifString (QString name, QString unit, QByteArray value="");
|
|
double mphTokmh (double value);
|
|
void notify (QString notif, QString priority = "low", QString inputPath = "", QString tag = "");
|
|
quint8 setPriority (quint8 currentPriority, quint8 newPriority);
|
|
QString previsionMeteo(double currentPressure, double variation3h, quint8 &priority);
|
|
QString pressureVariation(double currentPressure, quint8 &priority);
|
|
QString getPluviosite(double value, quint8 &priority);
|
|
void rotateAndSaveImage(const QString &inputPath, const QString &outputPath, qreal angle=0);
|
|
double windChill(double airT, double vent);
|
|
double calculerHumidex(double temperature, double humiditeRelative);
|
|
|