66 lines
1.9 KiB
C++
66 lines
1.9 KiB
C++
#ifndef PWS2MQTT_H
|
|
#define PWS2MQTT_H
|
|
|
|
#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__) + " -> " + QString(Q_FUNC_INFO)
|
|
|
|
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 = "./fleche.png";
|
|
QString outpuPath = "/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 = "");
|
|
quint8 setPriority (quint8 currentPriority, quint8 newPriority);
|
|
quint8 previsionMeteo(double currentPressure, double variation3h);
|
|
QString pressureVariation(double currentPressure);
|
|
void rotateAndSaveImage(const QString &inputPath, const QString &outputPath, qreal angle=0);
|
|
|
|
#endif // PWS2MQTT_H
|