62 lines
1.7 KiB
C++
62 lines
1.7 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;
|
|
int newsockfd;
|
|
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);
|
|
qfloat16 tohPa(qfloat16 value);
|
|
bool compare (qfloat16 value, qfloat16 testValue, qfloat16 ecart = 0.5);
|
|
QString formatNotifString (QPair<QString, QString> pair, QByteArray value);
|
|
qfloat16 mphTokmh (qfloat16 value);
|
|
void notify (QString notif, QString priority = "low");
|
|
quint8 setPriority (quint8 currentPriority, quint8 newPriority);
|
|
quint8 previsionMeteo(double currentPressure, double variation3h);
|
|
void pressureVariation(qfloat16 currentPressure);
|
|
|
|
#endif // PWS2MQTT_H
|