mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
add unique id
Zeroconf TXT record is missing
This commit is contained in:
parent
a7f72a7bf2
commit
91c7637a2b
@ -181,6 +181,9 @@ public:
|
|||||||
|
|
||||||
QJsonObject getConfig() { return _qjsonConfig; };
|
QJsonObject getConfig() { return _qjsonConfig; };
|
||||||
|
|
||||||
|
/// unique id per instance
|
||||||
|
QString id;
|
||||||
|
|
||||||
int getLatchTime() const;
|
int getLatchTime() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -8,17 +8,19 @@
|
|||||||
|
|
||||||
// hyperion includes
|
// hyperion includes
|
||||||
#include <utils/Logger.h>
|
#include <utils/Logger.h>
|
||||||
|
#include <hyperion/Hyperion.h>
|
||||||
|
|
||||||
class Stats : public QObject
|
class Stats : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Stats();
|
Stats();
|
||||||
~Stats();
|
~Stats();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Logger* _log;
|
Logger* _log;
|
||||||
|
Hyperion* _hyperion;
|
||||||
QString _hash = "";
|
QString _hash = "";
|
||||||
QByteArray _ba;
|
QByteArray _ba;
|
||||||
QNetworkRequest _req;
|
QNetworkRequest _req;
|
||||||
@ -27,6 +29,7 @@ private:
|
|||||||
bool trigger(bool set = false);
|
bool trigger(bool set = false);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void initialExec();
|
||||||
void sendHTTP();
|
void sendHTTP();
|
||||||
void sendHTTPp();
|
void sendHTTPp();
|
||||||
void resolveReply(QNetworkReply *reply);
|
void resolveReply(QNetworkReply *reply);
|
||||||
|
@ -588,6 +588,7 @@ void JsonClientConnection::handleSysInfoCommand(const QJsonObject&, const QStrin
|
|||||||
hyperion["version" ] = QString(HYPERION_VERSION);
|
hyperion["version" ] = QString(HYPERION_VERSION);
|
||||||
hyperion["build" ] = QString(HYPERION_BUILD_ID);
|
hyperion["build" ] = QString(HYPERION_BUILD_ID);
|
||||||
hyperion["time" ] = QString(__DATE__ " " __TIME__);
|
hyperion["time" ] = QString(__DATE__ " " __TIME__);
|
||||||
|
hyperion["id" ] = _hyperion->id;
|
||||||
info["hyperion"] = hyperion;
|
info["hyperion"] = hyperion;
|
||||||
|
|
||||||
// send the result
|
// send the result
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#include <utils/SysInfo.h>
|
#include <utils/SysInfo.h>
|
||||||
#include <HyperionConfig.h>
|
#include <HyperionConfig.h>
|
||||||
#include <leddevice/LedDevice.h>
|
#include <leddevice/LedDevice.h>
|
||||||
#include <hyperion/Hyperion.h>
|
|
||||||
|
|
||||||
// qt includes
|
// qt includes
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
@ -17,26 +16,30 @@
|
|||||||
Stats::Stats()
|
Stats::Stats()
|
||||||
: QObject()
|
: QObject()
|
||||||
, _log(Logger::getInstance("STATS"))
|
, _log(Logger::getInstance("STATS"))
|
||||||
|
, _hyperion(Hyperion::getInstance())
|
||||||
{
|
{
|
||||||
// generate hash
|
// generate hash
|
||||||
foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces())
|
foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces())
|
||||||
{
|
{
|
||||||
if (!(interface.flags() & QNetworkInterface::IsLoopBack))
|
if (!(interface.flags() & QNetworkInterface::IsLoopBack))
|
||||||
{
|
{
|
||||||
|
_hyperion->id = QString(QCryptographicHash::hash(interface.hardwareAddress().toLocal8Bit().append(_hyperion->getConfigFile().toLocal8Bit()),QCryptographicHash::Sha1).toHex());
|
||||||
_hash = QString(QCryptographicHash::hash(interface.hardwareAddress().toLocal8Bit(),QCryptographicHash::Sha1).toHex());
|
_hash = QString(QCryptographicHash::hash(interface.hardwareAddress().toLocal8Bit(),QCryptographicHash::Sha1).toHex());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop reporting if not found
|
// stop reporting if not found
|
||||||
if(_hash.isEmpty())
|
if(_hash.isEmpty())
|
||||||
{
|
{
|
||||||
Warning(_log, "No interface found, abort");
|
Warning(_log, "No interface found, abort");
|
||||||
|
// fallback id
|
||||||
|
_hyperion->id = QString(QCryptographicHash::hash(_hyperion->getConfigFile().toLocal8Bit(),QCryptographicHash::Sha1).toHex());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare content
|
// prepare content
|
||||||
QJsonObject config = Hyperion::getInstance()->getConfig();
|
QJsonObject config = _hyperion->getConfig();
|
||||||
SysInfo::HyperionSysInfo data = SysInfo::get();
|
SysInfo::HyperionSysInfo data = SysInfo::get();
|
||||||
|
|
||||||
QJsonObject system;
|
QJsonObject system;
|
||||||
@ -47,7 +50,8 @@ Stats::Stats()
|
|||||||
system["pName" ] = data.prettyName;
|
system["pName" ] = data.prettyName;
|
||||||
system["version" ] = QString(HYPERION_VERSION);
|
system["version" ] = QString(HYPERION_VERSION);
|
||||||
system["device" ] = LedDevice::activeDevice();
|
system["device" ] = LedDevice::activeDevice();
|
||||||
system["id" ] = _hash;
|
system["id" ] = _hyperion->id;
|
||||||
|
system["hw_id" ] = _hash;
|
||||||
system["ledCount" ] = QString::number(Hyperion::getInstance()->getLedCount());
|
system["ledCount" ] = QString::number(Hyperion::getInstance()->getLedCount());
|
||||||
system["comp_sm" ] = config["smoothing"].toObject().take("enable");
|
system["comp_sm" ] = config["smoothing"].toObject().take("enable");
|
||||||
system["comp_bb" ] = config["blackborderdetector"].toObject().take("enable");
|
system["comp_bb" ] = config["blackborderdetector"].toObject().take("enable");
|
||||||
@ -59,23 +63,20 @@ Stats::Stats()
|
|||||||
|
|
||||||
QJsonDocument doc(system);
|
QJsonDocument doc(system);
|
||||||
_ba = doc.toJson();
|
_ba = doc.toJson();
|
||||||
|
|
||||||
// QNetworkRequest Header
|
// QNetworkRequest Header
|
||||||
_req.setRawHeader("Content-Type", "application/json");
|
_req.setRawHeader("Content-Type", "application/json");
|
||||||
_req.setRawHeader("Authorization", "Basic SHlwZXJpb25YbDQ5MlZrcXA6ZDQxZDhjZDk4ZjAwYjIw");
|
_req.setRawHeader("Authorization", "Basic SHlwZXJpb25YbDQ5MlZrcXA6ZDQxZDhjZDk4ZjAwYjIw");
|
||||||
|
|
||||||
connect(&_mgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(resolveReply(QNetworkReply*)));
|
connect(&_mgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(resolveReply(QNetworkReply*)));
|
||||||
|
|
||||||
// 7 days interval
|
// 7 days interval
|
||||||
QTimer *timer = new QTimer(this);
|
QTimer *timer = new QTimer(this);
|
||||||
connect(timer, SIGNAL(timeout()), this, SLOT(sendHTTP()));
|
connect(timer, SIGNAL(timeout()), this, SLOT(sendHTTP()));
|
||||||
timer->start(604800000);
|
timer->start(604800000);
|
||||||
|
|
||||||
// check instant execution required
|
//delay initial check
|
||||||
if(trigger())
|
QTimer::singleShot(60000, this, SLOT(initialExec()));
|
||||||
{
|
|
||||||
QTimer::singleShot(0,this, SLOT(sendHTTP()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Stats::~Stats()
|
Stats::~Stats()
|
||||||
@ -83,6 +84,14 @@ Stats::~Stats()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Stats::initialExec()
|
||||||
|
{
|
||||||
|
if(trigger())
|
||||||
|
{
|
||||||
|
QTimer::singleShot(0,this, SLOT(sendHTTP()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Stats::sendHTTP()
|
void Stats::sendHTTP()
|
||||||
{
|
{
|
||||||
_req.setUrl(QUrl("https://api.hyperion-project.org/api/stats"));
|
_req.setUrl(QUrl("https://api.hyperion-project.org/api/stats"));
|
||||||
@ -90,8 +99,8 @@ void Stats::sendHTTP()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Stats::sendHTTPp()
|
void Stats::sendHTTPp()
|
||||||
{
|
{
|
||||||
_req.setUrl(QUrl("https://api.hyperion-project.org/api/stats/"+_hash));
|
_req.setUrl(QUrl("https://api.hyperion-project.org/api/stats/"+_hyperion->id));
|
||||||
_mgr.put(_req,_ba);
|
_mgr.put(_req,_ba);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +122,7 @@ bool Stats::trigger(bool set)
|
|||||||
{
|
{
|
||||||
QString path = QDir::homePath()+"/.hyperion/misc/";
|
QString path = QDir::homePath()+"/.hyperion/misc/";
|
||||||
QDir dir;
|
QDir dir;
|
||||||
QFile file(path + "ts");
|
QFile file(path + _hyperion->id);
|
||||||
|
|
||||||
if(set && file.open(QIODevice::ReadWrite) )
|
if(set && file.open(QIODevice::ReadWrite) )
|
||||||
{
|
{
|
||||||
@ -130,7 +139,7 @@ bool Stats::trigger(bool set)
|
|||||||
if (!file.exists())
|
if (!file.exists())
|
||||||
{
|
{
|
||||||
if(file.open(QIODevice::ReadWrite))
|
if(file.open(QIODevice::ReadWrite))
|
||||||
{
|
{
|
||||||
file.close();
|
file.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user