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