fixed Fronius plug-in

pull/1/head
Boernsman 2020-06-17 16:46:36 +02:00
parent 68e38a1eaf
commit 604ff0e454
4 changed files with 10 additions and 38 deletions

View File

@ -49,18 +49,6 @@ QUrl FroniusLogger::updateUrl()
return requestUrl; return requestUrl;
} }
QUrl FroniusLogger::updateRelayStateUrl()
{
QUrl requestUrl;
requestUrl.setScheme("http");
requestUrl.setHost(hostAddress());
requestUrl.setPath("/status/emrs/");
return requestUrl;
}
void FroniusLogger::updateThingInfo(const QByteArray &data) void FroniusLogger::updateThingInfo(const QByteArray &data)
{ {
// Convert the rawdata to a json document // Convert the rawdata to a json document

View File

@ -45,7 +45,6 @@ public:
explicit FroniusLogger(Thing *thing, QObject *parent = 0); explicit FroniusLogger(Thing *thing, QObject *parent = 0);
QUrl updateUrl(); QUrl updateUrl();
QUrl updateRelayStateUrl();
void updateThingInfo(const QByteArray &data); void updateThingInfo(const QByteArray &data);
void updatePowerRelayState(const QByteArray &data); void updatePowerRelayState(const QByteArray &data);

View File

@ -73,12 +73,11 @@ void FroniusMeter::updateThingInfo(const QByteArray &data)
return; return;
} }
qCDebug(dcFronius()) << "FroniusMeter: ThingInfo received:" << qUtf8Printable(data);
// Parse the data and update the states of our thing // Parse the data and update the states of our thing
QVariantMap dataMap = jsonDoc.toVariant().toMap().value("Body").toMap().value("Data").toMap(); QVariantMap dataMap = jsonDoc.toVariant().toMap().value("Body").toMap().value("Data").toMap();
//QVariantMap headMap = jsonDoc.toVariant().toMap().value("Head").toMap(); //QVariantMap headMap = jsonDoc.toVariant().toMap().value("Head").toMap();
//Request from Gerald Aigner, add Smart meter with following states: „PowerReal_P_Sum“, „EnergyReal_WAC_Sum_Produced“, „EnergyReal_WAC_Sum_Consumed“ //Add Smart meter with following states: „PowerReal_P_Sum“, „EnergyReal_WAC_Sum_Produced“, „EnergyReal_WAC_Sum_Consumed“
// Set the inverter thing state // Set the inverter thing state
if (dataMap.contains("PowerReal_P_Sum")) { if (dataMap.contains("PowerReal_P_Sum")) {

View File

@ -76,7 +76,7 @@ void IntegrationPluginFronius::setupThing(ThingSetupInfo *info)
QByteArray data = reply->readAll(); QByteArray data = reply->readAll();
if (reply->error() != QNetworkReply::NoError) { if (reply->error() != QNetworkReply::NoError) {
qCWarning(dcFronius()) << "Fronius: Network request error:" << reply->error() << reply->errorString(); qCWarning(dcFronius()) << "Fronius: Network request error:" << reply->error() << reply->errorString() << reply->url();
info->finish(Thing::ThingErrorHardwareNotAvailable, tr("Device not reachable")); info->finish(Thing::ThingErrorHardwareNotAvailable, tr("Device not reachable"));
return; return;
} }
@ -383,7 +383,7 @@ void IntegrationPluginFronius::updateThingStates(Thing *thing)
connect(reply, &QNetworkReply::finished, [this, thing, reply]() { connect(reply, &QNetworkReply::finished, [this, thing, reply]() {
if (reply->error() != QNetworkReply::NoError) { if (reply->error() != QNetworkReply::NoError) {
qCWarning(dcFronius()) << "Network request error:" << reply->error() << reply->errorString(); qCWarning(dcFronius()) << "Network request error:" << reply->error() << reply->errorString() << reply->request().url();
return; return;
} }
QByteArray data = reply->readAll(); QByteArray data = reply->readAll();
@ -395,7 +395,7 @@ void IntegrationPluginFronius::updateThingStates(Thing *thing)
connect(next_reply, &QNetworkReply::finished, next_reply, &QNetworkReply::deleteLater); connect(next_reply, &QNetworkReply::finished, next_reply, &QNetworkReply::deleteLater);
connect(next_reply, &QNetworkReply::finished, [this, thing, next_reply]() { connect(next_reply, &QNetworkReply::finished, [this, thing, next_reply]() {
if (next_reply->error() != QNetworkReply::NoError) { if (next_reply->error() != QNetworkReply::NoError) {
qCWarning(dcFronius()) << "Network request error:" << next_reply->error() << next_reply->errorString(); qCWarning(dcFronius()) << "Network request error:" << next_reply->error() << next_reply->errorString() << next_reply->request().url();
return; return;
} }
QByteArray data = next_reply->readAll(); QByteArray data = next_reply->readAll();
@ -409,7 +409,7 @@ void IntegrationPluginFronius::updateThingStates(Thing *thing)
connect(reply, &QNetworkReply::finished, [this, thing, reply]() { connect(reply, &QNetworkReply::finished, [this, thing, reply]() {
if (reply->error() != QNetworkReply::NoError) { if (reply->error() != QNetworkReply::NoError) {
qCWarning(dcFronius()) << "Network request error:" << reply->error() << reply->errorString(); qCWarning(dcFronius()) << "Network request error:" << reply->error() << reply->errorString() << reply->request().url();
return; return;
} }
QByteArray data = reply->readAll(); QByteArray data = reply->readAll();
@ -418,26 +418,12 @@ void IntegrationPluginFronius::updateThingStates(Thing *thing)
} }
}); });
reply = hardwareManager()->networkManager()->get(QNetworkRequest(m_froniusLoggers.key(thing)->updateRelayStateUrl()));
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
connect(reply, &QNetworkReply::finished, [this, thing, reply]() {
if (reply->error() != QNetworkReply::NoError) {
qCWarning(dcFronius()) << "Network request error:" << reply->error() << reply->errorString();
return;
}
QByteArray data = reply->readAll();
if(m_froniusLoggers.values().contains(thing)){ // check if thing was not removed before reply was received
m_froniusLoggers.key(thing)->updatePowerRelayState(data);
}
});
} else if (thing->thingClassId() == meterThingClassId) { } else if (thing->thingClassId() == meterThingClassId) {
QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(m_froniusMeters.key(thing)->updateUrl())); QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(m_froniusMeters.key(thing)->updateUrl()));
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater); connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
connect(reply, &QNetworkReply::finished, [this, thing, reply]() { connect(reply, &QNetworkReply::finished, [this, thing, reply]() {
if (reply->error() != QNetworkReply::NoError) { if (reply->error() != QNetworkReply::NoError) {
qCWarning(dcFronius()) << "Network request error:" << reply->error() << reply->errorString(); qCWarning(dcFronius()) << "Network request error:" << reply->error() << reply->errorString() << reply->request().url();
return; return;
} }
QByteArray data = reply->readAll(); QByteArray data = reply->readAll();
@ -450,7 +436,7 @@ void IntegrationPluginFronius::updateThingStates(Thing *thing)
connect(next_reply, &QNetworkReply::finished, [this, thing, next_reply]() { connect(next_reply, &QNetworkReply::finished, [this, thing, next_reply]() {
if (next_reply->error() != QNetworkReply::NoError) { if (next_reply->error() != QNetworkReply::NoError) {
qCWarning(dcFronius()) << "Network request error:" << next_reply->error() << next_reply->errorString(); qCWarning(dcFronius()) << "Network request error:" << next_reply->error() << next_reply->errorString() << next_reply->request().url();
return; return;
} }
QByteArray data = next_reply->readAll(); QByteArray data = next_reply->readAll();
@ -464,7 +450,7 @@ void IntegrationPluginFronius::updateThingStates(Thing *thing)
connect(reply, &QNetworkReply::finished, [this, thing, reply]() { connect(reply, &QNetworkReply::finished, [this, thing, reply]() {
if (reply->error() != QNetworkReply::NoError) { if (reply->error() != QNetworkReply::NoError) {
qCWarning(dcFronius()) << "Network request error:" << reply->error() << reply->errorString(); qCWarning(dcFronius()) << "Network request error:" << reply->error() << reply->errorString() << reply->request().url();
return; return;
} }
QByteArray data = reply->readAll(); QByteArray data = reply->readAll();
@ -477,7 +463,7 @@ void IntegrationPluginFronius::updateThingStates(Thing *thing)
connect(next_reply, &QNetworkReply::finished, [this, thing, next_reply]() { connect(next_reply, &QNetworkReply::finished, [this, thing, next_reply]() {
next_reply->deleteLater(); next_reply->deleteLater();
if (next_reply->error() != QNetworkReply::NoError) { if (next_reply->error() != QNetworkReply::NoError) {
qCWarning(dcFronius()) << "Network request error:" << next_reply->error() << next_reply->errorString(); qCWarning(dcFronius()) << "Network request error:" << next_reply->error() << next_reply->errorString() << next_reply->request().url();
return; return;
} }
QByteArray data = next_reply->readAll(); QByteArray data = next_reply->readAll();
@ -509,7 +495,7 @@ void IntegrationPluginFronius::searchNewThings(FroniusLogger *logger)
connect(reply, &QNetworkReply::finished, [this, logger, reply]() { connect(reply, &QNetworkReply::finished, [this, logger, reply]() {
if (reply->error() != QNetworkReply::NoError) { if (reply->error() != QNetworkReply::NoError) {
qCWarning(dcFronius()) << "Network request error:" << reply->error() << reply->errorString(); qCWarning(dcFronius()) << "Network request error:" << reply->error() << reply->errorString() << reply->request().url();
return; return;
} }