move mqtt in compilation's option
This commit is contained in:
1 parent
ada4d7ed99
commit
d4a6942ec4
3 files changed
+49
-85
No files matched your search
+24
-40
@@ -1,41 +1,42 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
//#include <QObject>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
//#include <QtMqtt>
|
|
||||||
//#include <QtMqtt/QMqttClient>
|
|
||||||
//#include <QtMqtt/QMqttMessage>
|
|
||||||
//#include <QtMqtt/QMqttSubscription>
|
|
||||||
#include <qhttpserver.h>
|
#include <qhttpserver.h>
|
||||||
#include <QHttpServerResponse>
|
#include <QHttpServerResponse>
|
||||||
#include "pws2mqtt.h"
|
#include "pws2mqtt.h"
|
||||||
//#include "mqtt.h"
|
#ifdef WITH_MQTT
|
||||||
|
#include "mqtt.h"
|
||||||
|
#endif
|
||||||
#include "src/barometertrend.h"
|
#include "src/barometertrend.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include <curl/curl.h>
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#ifdef WITH_MQTT
|
||||||
|
#include <QtMqtt>
|
||||||
|
#include <QtMqtt/QMqttClient>
|
||||||
|
#include <QtMqtt/QMqttMessage>
|
||||||
|
#include <QtMqtt/QMqttSubscription>
|
||||||
|
#endif
|
||||||
#define CLIENT_ID "Client_ID"
|
#define CLIENT_ID "Client_ID"
|
||||||
//#define BROKER_ADDRESS "localhost"
|
|
||||||
//#define MQTT_PORT 1883;
|
|
||||||
|
|
||||||
uint debugLevel = ERROR | ALERT;
|
uint debugLevel = INFO | ERROR | ALERT;
|
||||||
QByteArray toFollow;
|
QByteArray toFollow;
|
||||||
|
|
||||||
//class MqttClient;
|
#ifdef WITH_MQTT
|
||||||
|
class MqttClient;
|
||||||
|
MqttClient *mqttClient;
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
//Configuration config;
|
//Configuration config;
|
||||||
Pws2mqtt *pws2mqtt;
|
Pws2mqtt *pws2mqtt;
|
||||||
//MqttClient *mqttClient;
|
|
||||||
QHttpServer *httpServer;
|
QHttpServer *httpServer;
|
||||||
BarometerTrend *baro;
|
BarometerTrend *baro;
|
||||||
|
|
||||||
@@ -51,12 +52,13 @@ int main(int argc, char *argv[])
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Enable logging to ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••journald
|
// Enable logging to journald
|
||||||
qputenv("QT_FORCE_STDERR_LOGGING", QByteArray("0"));
|
qputenv("QT_FORCE_STDERR_LOGGING", QByteArray("0"));
|
||||||
|
|
||||||
debug(DEBUGMACRO, "declaration of mqttClient", DEBUG);
|
debug(DEBUGMACRO, "declaration of mqttClient", INFO);
|
||||||
//mqttClient = new MqttClient;
|
#ifdef WITH_MQTT
|
||||||
|
mqttClient = new MqttClient;
|
||||||
|
#endif
|
||||||
httpServer = new QHttpServer;
|
httpServer = new QHttpServer;
|
||||||
|
|
||||||
//declaration of debug level
|
//declaration of debug level
|
||||||
@@ -65,34 +67,16 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
pws2mqtt->listeningHttp();
|
pws2mqtt->listeningHttp();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//notify (QString("Program started"), "default");
|
|
||||||
a.exec();
|
a.exec();
|
||||||
|
|
||||||
//mqttClient->qmqttClient->unsubscribe(mqttClient->topic);
|
#ifdef WITH_MQTT
|
||||||
//mqttClient->qmqttClient->disconnectFromHost();
|
mqttClient->qmqttClient->unsubscribe(mqttClient->topic);
|
||||||
debug(DEBUGMACRO, "exiting", DEBUG);
|
mqttClient->qmqttClient->disconnectFromHost();
|
||||||
|
#endif
|
||||||
|
debug(DEBUGMACRO, "exiting", INFO);
|
||||||
notify ("Program exiting \n", "high");
|
notify ("Program exiting \n", "high");
|
||||||
//Closing http server
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*QString addValue(QByteArray value)
|
|
||||||
{
|
|
||||||
bool ok;
|
|
||||||
QString str;
|
|
||||||
|
|
||||||
value.toFloat(&ok);
|
|
||||||
if (ok)
|
|
||||||
{
|
|
||||||
str = (value);
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
str = ("\"" + value + "\"" );
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
void debug(QString debugHeader, QString msg, uint8_t level, QByteArray property)
|
void debug(QString debugHeader, QString msg, uint8_t level, QByteArray property)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
+25
-18
@@ -1,27 +1,24 @@
|
|||||||
#include "pws2mqtt.h"
|
#include "pws2mqtt.h"
|
||||||
#include "barometertrend.h"
|
#include "barometertrend.h"
|
||||||
//#include "mqtt.h"
|
|
||||||
//#include "httpserver.h"
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
//#include <unistd.h>
|
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
//#include <sys/socket.h>
|
|
||||||
//#include <netinet/in.h>
|
|
||||||
#include <QtHttpServer/QHttpServer>
|
#include <QtHttpServer/QHttpServer>
|
||||||
#include <QtHttpServer/QHttpServerRequest>
|
#include <QtHttpServer/QHttpServerRequest>
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QTransform>
|
#include <QTransform>
|
||||||
//#include <stdio.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include "utcicalculator.h"
|
#include "utcicalculator.h"
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
#ifdef WITH_MQTT
|
||||||
|
#include "mqtt.h"
|
||||||
|
/extern MqttClient *mqttClient;
|
||||||
|
#endif
|
||||||
|
|
||||||
//extern MqttClient *mqttClient;
|
|
||||||
extern Pws2mqtt *pws2mqtt;
|
extern Pws2mqtt *pws2mqtt;
|
||||||
extern QHttpServer *httpServer;
|
extern QHttpServer *httpServer;
|
||||||
extern BarometerTrend *baro;
|
extern BarometerTrend *baro;
|
||||||
@@ -57,7 +54,7 @@ QMap <QByteArray, QPair<QString, QByteArray>> propertyName
|
|||||||
{"dailyrainin", {"Pluie de la journée", " mm"}},
|
{"dailyrainin", {"Pluie de la journée", " mm"}},
|
||||||
// {"monthlyrainin", {"Pluie du mois", " mm"}},
|
// {"monthlyrainin", {"Pluie du mois", " mm"}},
|
||||||
// {"yearlyrainin", {"Pluie de l'année", " mm"}},
|
// {"yearlyrainin", {"Pluie de l'année", " mm"}},
|
||||||
// {"solarradiation", {"Énergie solaire", " W/m²"}},
|
{"solarradiation", {"Énergie solaire", " W/m²"}},
|
||||||
// {"indoortempf", {"Température intérieure", "°C"}},
|
// {"indoortempf", {"Température intérieure", "°C"}},
|
||||||
// {"indoorhumidity", {"Humidité intérieure", "%"}},
|
// {"indoorhumidity", {"Humidité intérieure", "%"}},
|
||||||
{"baromin", {"Pression atmosphérique", " hPa"}},
|
{"baromin", {"Pression atmosphérique", " hPa"}},
|
||||||
@@ -93,7 +90,7 @@ Pws2mqtt::~Pws2mqtt()
|
|||||||
|
|
||||||
void Pws2mqtt::init()
|
void Pws2mqtt::init()
|
||||||
{
|
{
|
||||||
debug(DEBUGMACRO, "init http server", DEBUG);
|
debug(DEBUGMACRO, "init http server", INFO);
|
||||||
httpServer->setMissingHandler([](const QHttpServerRequest &request, QHttpServerResponder &&responder)
|
httpServer->setMissingHandler([](const QHttpServerRequest &request, QHttpServerResponder &&responder)
|
||||||
{
|
{
|
||||||
(void) responder;
|
(void) responder;
|
||||||
@@ -141,6 +138,7 @@ void Pws2mqtt::init()
|
|||||||
|
|
||||||
void notify(QString notif, QString priority, QString inputPath, QString tag)
|
void notify(QString notif, QString priority, QString inputPath, QString tag)
|
||||||
{
|
{
|
||||||
|
(void) inputPath;
|
||||||
QNetworkAccessManager *manager = new QNetworkAccessManager(pws2mqtt);
|
QNetworkAccessManager *manager = new QNetworkAccessManager(pws2mqtt);
|
||||||
QNetworkRequest request(QUrl("http://localhost:81/Meteo"));
|
QNetworkRequest request(QUrl("http://localhost:81/Meteo"));
|
||||||
request.setRawHeader("Content-Type", "charset=UTF-8; text/markdown");
|
request.setRawHeader("Content-Type", "charset=UTF-8; text/markdown");
|
||||||
@@ -148,7 +146,7 @@ void notify(QString notif, QString priority, QString inputPath, QString tag)
|
|||||||
{
|
{
|
||||||
request.setRawHeader("Tags", tag.toUtf8());
|
request.setRawHeader("Tags", tag.toUtf8());
|
||||||
}
|
}
|
||||||
request.setRawHeader("Title", "Vidéo");
|
request.setRawHeader("Title", "Météo");
|
||||||
request.setRawHeader("Priority", priority.toUtf8());
|
request.setRawHeader("Priority", priority.toUtf8());
|
||||||
request.setRawHeader("Markdown", "yes");
|
request.setRawHeader("Markdown", "yes");
|
||||||
request.setRawHeader("Config", "/etc/ntfy.client.yml");
|
request.setRawHeader("Config", "/etc/ntfy.client.yml");
|
||||||
@@ -177,15 +175,17 @@ void Pws2mqtt::listeningHttp()
|
|||||||
{
|
{
|
||||||
debug(DEBUGMACRO, "Http Server failed to listen on a port.", ERROR);
|
debug(DEBUGMACRO, "Http Server failed to listen on a port.", ERROR);
|
||||||
}
|
}
|
||||||
debug(DEBUGMACRO, "Listening on port " + QString::number(port));
|
debug(DEBUGMACRO, "Listening on port " + QString::number(port), INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
||||||
{
|
{
|
||||||
debug(DEBUGMACRO, "Parsing Datas", DEBUG);
|
debug(DEBUGMACRO, "Parsing Datas", DEBUG);
|
||||||
|
|
||||||
|
#ifdef WITH_MQTT
|
||||||
QString jsonString = "{";
|
QString jsonString = "{";
|
||||||
//QString deviceString = "\"device\": {\"ieeeAddress\": \"" + mqttClient->macAddress + "\", \"type\": \"" + mqttClient->type + "\", \"powerSource\": \"Battery\"";
|
QString deviceString = "\"device\": {\"ieeeAddress\": \"" + mqttClient->macAddress + "\", \"type\": \"" + mqttClient->type + "\", \"powerSource\": \"Battery\"";
|
||||||
|
#endif
|
||||||
QString notif = "";
|
QString notif = "";
|
||||||
QStringList priorityList {"", "min", "low", "default", "High", "urgent"};
|
QStringList priorityList {"", "min", "low", "default", "High", "urgent"};
|
||||||
QString attachment = "";
|
QString attachment = "";
|
||||||
@@ -212,24 +212,29 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
if(deviceFlag == false)
|
if(deviceFlag == false)
|
||||||
{
|
{
|
||||||
deviceFlag = true;
|
deviceFlag = true;
|
||||||
}/*else
|
}
|
||||||
|
#ifdef WITH_MQTT
|
||||||
|
else
|
||||||
{
|
{
|
||||||
deviceString.append(", ");
|
deviceString.append(", ");
|
||||||
}
|
}
|
||||||
deviceString += "\"" + name + "\": ";
|
deviceString += "\"" + name + "\": ";
|
||||||
deviceString += pair.second;*/
|
deviceString += pair.second;
|
||||||
|
#endif
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
if(propertyFlag == false)
|
if(propertyFlag == false)
|
||||||
{
|
{
|
||||||
propertyFlag = true;
|
propertyFlag = true;
|
||||||
}else
|
}
|
||||||
|
#ifdef WITH_MQTT
|
||||||
|
else
|
||||||
{
|
{
|
||||||
jsonString.append(", ");
|
jsonString.append(", ");
|
||||||
}
|
}
|
||||||
jsonString.append("\"" + name + "\": ");
|
jsonString.append("\"" + name + "\": ");
|
||||||
jsonString.append(pair.second);
|
jsonString.append(pair.second);
|
||||||
|
#endif
|
||||||
if (name == "tempf")
|
if (name == "tempf")
|
||||||
{
|
{
|
||||||
static QDateTime timeTemp = QDateTime::currentDateTime().addSecs(-600);
|
static QDateTime timeTemp = QDateTime::currentDateTime().addSecs(-600);
|
||||||
@@ -412,7 +417,8 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
//windChill(propertiesValue["tempf"], propertiesValue["vent"]);
|
//windChill(propertiesValue["tempf"], propertiesValue["vent"]);
|
||||||
//calculerHumidex(propertiesValue["tempf"], propertiesValue["humidity"]);
|
//calculerHumidex(propertiesValue["tempf"], propertiesValue["humidity"]);
|
||||||
|
|
||||||
/*if (!jsonString.isEmpty())
|
#ifdef WITH_MQTT
|
||||||
|
if (!jsonString.isEmpty())
|
||||||
{
|
{
|
||||||
debug(DEBUGMACRO, "json string : " + jsonString, DEBUG);
|
debug(DEBUGMACRO, "json string : " + jsonString, DEBUG);
|
||||||
jsonString = jsonString +", " + deviceString + "}}";
|
jsonString = jsonString +", " + deviceString + "}}";
|
||||||
@@ -420,7 +426,8 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
debug(DEBUGMACRO, "No values to send", DEBUG);
|
debug(DEBUGMACRO, "No values to send", DEBUG);
|
||||||
}*/
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
debug(DEBUGMACRO, "current datetime : " + QDateTime::currentDateTime().toString() + ", timer = " + timer.toString(), DEBUG);
|
debug(DEBUGMACRO, "current datetime : " + QDateTime::currentDateTime().toString() + ", timer = " + timer.toString(), DEBUG);
|
||||||
|
|
||||||
|
|||||||
@@ -12,33 +12,6 @@ UtciCalculator::UtciCalculator(QObject *parent)
|
|||||||
/*// Loads coefficients from a simple text file containing one coefficient per line or tab-separated.
|
/*// Loads coefficients from a simple text file containing one coefficient per line or tab-separated.
|
||||||
// The expected file is the ESM_3 coefficients table exported to a plain text file where the coefficients
|
// The expected file is the ESM_3 coefficients table exported to a plain text file where the coefficients
|
||||||
// appear in the same order as in the official table (210 coefficients).
|
// appear in the same order as in the official table (210 coefficients).
|
||||||
bool UtciCalculator::loadCoefficientsFromFile(const QString &path)
|
|
||||||
{
|
|
||||||
QFile f(path);
|
|
||||||
if (!f.open(QIODevice::ReadOnly | QIODevice::Text))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
QTextStream in(&f);
|
|
||||||
QVector<double> coeffs;
|
|
||||||
coeffs.reserve(300);
|
|
||||||
|
|
||||||
while (!in.atEnd()) {
|
|
||||||
QString line = in.readLine().trimmed();
|
|
||||||
if (line.isEmpty()) continue;
|
|
||||||
// Allow lines with comments or 'term coefficient' headings:
|
|
||||||
// We try to extract numbers from the line.
|
|
||||||
QStringList parts = line.split(QRegularExpression("[\\s,\\t]+"), Qt::SkipEmptyParts);
|
|
||||||
for (const QString &p : parts) {
|
|
||||||
bool ok = false;
|
|
||||||
double val = p.toDouble(&ok);
|
|
||||||
if (ok) coeffs.append(val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (coeffs.isEmpty()) return false;
|
|
||||||
|
|
||||||
m_coeffs = coeffs;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
// Magnus formula to estimate saturation vapour pressure (hPa) then return pa in kPa
|
// Magnus formula to estimate saturation vapour pressure (hPa) then return pa in kPa
|
||||||
double UtciCalculator::vapourPressureFromRH(double Ta, double rh)
|
double UtciCalculator::vapourPressureFromRH(double Ta, double rh)
|
||||||
|
|||||||
Reference in new issue
Block a user