#include #include //#include #include #include #include #include #include #include #include #include #include #include #include #include #include "pws2mqtt.h" #include "mqtt.h" //#include "version.h" #include #include #include #define CLIENT_ID "Client_ID" #define BROKER_ADDRESS "localhost" #define MQTT_PORT 1883; uint debugLevel = ALL; QByteArray toFollow; //class MqttClient; using namespace std; //Configuration config; Pws2mqtt *pws2mqtt; MqttClient *mqttClient; QHttpServer *httpServer; int main(int argc, char *argv[]) { debug(DEBUGMACRO, "QcoreApplication", DEBUG); QCoreApplication a(argc, argv); // Enable logging to journald qputenv("QT_FORCE_STDERR_LOGGING", QByteArray("0")); debug(DEBUGMACRO, "declaration of mqttClient", DEBUG); mqttClient = new MqttClient; httpServer = new QHttpServer; // declaration of debug level pws2mqtt = new Pws2mqtt; pws2mqtt->listeningHttp(); a.exec(); mqttClient->qmqttClient->unsubscribe(mqttClient->topic); mqttClient->qmqttClient->disconnectFromHost(); debug(DEBUGMACRO, "exiting", DEBUG); //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) { if ((debugLevel & level) == 1) { qInfo("%s%sINFO: %s%s", debugHeader.toStdString().c_str(), GREEN, msg.toStdString().c_str(), NORMAL); } if ((debugLevel & level) == 2) { qInfo("%s%s NOTICE: %s%s", debugHeader.toStdString().c_str(), GREEN, msg.toStdString().c_str(), NORMAL); } if ((debugLevel & level) == 4) { qInfo("%s%s WARNING: %s%s", debugHeader.toStdString().c_str(), ORANGE, msg.toStdString().c_str(), NORMAL); } if ((debugLevel & level) == 8) { qInfo("%s%s ERROR: %s%s", debugHeader.toStdString().c_str(), RED, msg.toStdString().c_str(), NORMAL); exit(1); } if ((debugLevel & level) == 16) { qInfo("%s%s DEBUG: %s%s", debugHeader.toStdString().c_str(), GREEN, msg.toStdString().c_str(), NORMAL); } if ((debugLevel & level) == 32) { qInfo("%s%s ALERT: %s%s", debugHeader.toStdString().c_str(), RED, msg.toStdString().c_str(), NORMAL); exit(2); } if (toFollow == property and !toFollow.isEmpty()) { qInfo("%s%s FOLLOWING %s => %s%s", debugHeader.toStdString().c_str(), GREEN, property.toStdString().c_str(), msg.toStdString().c_str(), NORMAL); } }