Skip to content

Commit

Permalink
Merge pull request #8 from DanielR92/patch-2
Browse files Browse the repository at this point in the history
Update powermeter.h
  • Loading branch information
tictrick authored Apr 4, 2024
2 parents 208c0f7 + ce0d747 commit 0a58f57
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions src/plugins/zeroExport/powermeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@

#include <AsyncJson.h>
#include <HTTPClient.h>
#include "config/settings.h"

#if defined(ZEROEXPORT_POWERMETER_TIBBER)
#include <base64.h>
#include <string.h>

#include <list>
#endif

#include "config/settings.h"
#if defined(ZEROEXPORT_POWERMETER_TIBBER)
#include "plugins/zeroExport/lib/sml.h"
#endif

#if defined(ZEROEXPORT_POWERMETER_TIBBER)
typedef struct {
const unsigned char OBIS[6];
void (*Fn)(double &);
Expand Down Expand Up @@ -83,6 +78,7 @@ class powermeter {
#if defined(ZEROEXPORT_POWERMETER_TIBBER)
case zeroExportPowermeterType_t::Tibber:
power = getPowermeterWattsTibber(*mLog, group);
mPreviousTsp += 2000; // Zusätzliche Pause
break;
#endif
#if defined(ZEROEXPORT_POWERMETER_SHRDZM)
Expand Down Expand Up @@ -121,6 +117,18 @@ class powermeter {
}

private:

// set HTTPClient header
void setHeader(HTTPClient* h) {
h->setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
h->setUserAgent("Ahoy-Agent");
// TODO: Ahoy-0.8.850024-zero
h->setConnectTimeout(500);
h->setTimeout(1000);
h->addHeader("Content-Type", "application/json");
h->addHeader("Accept", "application/json");
}

#if defined(ZEROEXPORT_POWERMETER_SHELLY)
/** getPowermeterWattsShelly
* ...
Expand Down Expand Up @@ -455,18 +463,21 @@ class powermeter {

logObj["mod"] = "getPowermeterWattsTibber";

HTTPClient http;
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
http.setUserAgent("Ahoy-Agent");
// TODO: Ahoy-0.8.850024-zero
http.setConnectTimeout(500);
http.setTimeout(1000);
http.addHeader("Content-Type", "application/json");
http.addHeader("Accept", "application/json");
String auth;
if(strlen(mCfg->groups[group].pm_user) > 0 && strlen(mCfg->groups[group].pm_pass) > 0) {
auth = base64::encode(String(mCfg->groups[group].pm_user) + String(":") + String(mCfg->groups[group].pm_pass));
snprintf(mCfg->groups[group].pm_user, ZEROEXPORT_GROUP_MAX_LEN_PM_USER, "%s", DEF_ZEXPORT);
snprintf(mCfg->groups[group].pm_pass, ZEROEXPORT_GROUP_MAX_LEN_PM_PASS, "%s", auth.c_str());
//@TODO:mApp->saveSettings(false);
}
else
{
auth = mCfg->groups[group].pm_pass;
}

String url = String("http://") + mCfg->groups[group].pm_url + String("/") + String(mCfg->groups[group].pm_jsonPath);
String auth = base64::encode(String(mCfg->groups[group].pm_user) + String(":") + String(mCfg->groups[group].pm_pass));

setHeader(&http);
http.begin(url);
http.addHeader("Authorization", "Basic " + auth);

Expand Down Expand Up @@ -526,15 +537,8 @@ class powermeter {

logObj["mod"] = "getPowermeterWattsShrdzm";

HTTPClient http;
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
http.setUserAgent("Ahoy-Agent");
// TODO: Ahoy-0.8.850024-zero
http.setConnectTimeout(500);
http.setTimeout(1000);
http.addHeader("Content-Type", "application/json");
http.addHeader("Accept", "application/json");

setHeader(&http);

String url =
String("http://") + String(mCfg->groups[group].pm_url) +
String("/") + String(mCfg->groups[group].pm_jsonPath +
Expand Down Expand Up @@ -573,6 +577,8 @@ class powermeter {
if (mPowermeterBufferPos[group] >= 5) mPowermeterBufferPos[group] = 0;
}

HTTPClient http;

zeroExport_t *mCfg;
JsonObject *mLog;

Expand Down

0 comments on commit 0a58f57

Please sign in to comment.