Skip to content

Commit d28b666

Browse files
authored
Merge branch 'ze_v140' into zero-export
2 parents 82d75bd + ef5dcbb commit d28b666

File tree

5 files changed

+24
-16
lines changed

5 files changed

+24
-16
lines changed

src/config/settings.h

+2
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ typedef struct {
228228
#define ZEROEXPORT_GROUP_MAX_LEN_PM_JSONPATH 100
229229
#define ZEROEXPORT_GROUP_MAX_LEN_PM_USER 25
230230
#define ZEROEXPORT_GROUP_MAX_LEN_PM_PASS 25
231+
#define ZEROEXPORT_GROUP_MAX_LEN_PM_CRED 25
231232
#define ZEROEXPORT_GROUP_MAX_LEN_BATT_TOPIC 100
232233
#define ZEROEXPORT_GROUP_MAX_INVERTERS 3
233234
#define ZEROEXPORT_POWERMETER_MAX_ERRORS 5
@@ -310,6 +311,7 @@ typedef struct {
310311
char pm_jsonPath[ZEROEXPORT_GROUP_MAX_LEN_PM_JSONPATH];
311312
char pm_user[ZEROEXPORT_GROUP_MAX_LEN_PM_USER];
312313
char pm_pass[ZEROEXPORT_GROUP_MAX_LEN_PM_PASS];
314+
char pm_cred[ZEROEXPORT_GROUP_MAX_LEN_PM_CRED];
313315
uint8_t pm_target;
314316
// Inverters
315317
zeroExportGroupInverter_t inverters[ZEROEXPORT_GROUP_MAX_INVERTERS];

src/plugins/zeroExport/powermeter.h

+16-9
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,19 @@ class powermeter {
315315
*/
316316
void setHeader(HTTPClient *h, String auth = "", u8_t realm = 0) {
317317
h->setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
318-
/// h->setUserAgent("Ahoy-Agent");
319318
/// // TODO: Ahoy-0.8.850024-zero
320319
h->setUserAgent(mApp->getVersion());
321320
h->setConnectTimeout(500);
322321
h->setTimeout(1000);
323322
h->addHeader("Content-Type", "application/json");
324323
h->addHeader("Accept", "application/json");
325324

325+
if (auth != NULL && realm) {
326+
// h->addHeader("WWW-Authenticate", "Digest qop=\"auth\", realm=\"" + "shellypro4pm-f008d1d8b8b8" + "\\", nonce=\"60dc59c6\", algorithm=SHA-256");
327+
} else if (!auth.isEmpty()) {
328+
h->addHeader("Authorization", "Basic " + auth);
329+
}
330+
326331
/*
327332
Shelly PM Mini Gen3
328333
Shelly Plus 1PM
@@ -343,11 +348,6 @@ class powermeter {
343348
Shelly 3EM
344349
Shelly EM + 120A Clamp
345350
346-
*/
347-
348-
/*if (auth != NULL && realm) http.addHeader("WWW-Authenticate", "Digest qop=\"auth\", realm=\"" + shellypro4pm-f008d1d8b8b8 + "\", nonce=\"60dc59c6\", algorithm=SHA-256");
349-
else if (auth != NULL) http.addHeader("Authorization", "Basic " + auth);*/
350-
/*
351351
All Required:
352352
realm: string, device_id of the Shelly device.
353353
username: string, must be set to admin.
@@ -596,10 +596,11 @@ class powermeter {
596596
bool result = false;
597597
mLog->addProperty("mod", "getPowermeterWattsTibber");
598598

599-
String auth = mCfg->groups[group].pm_pass;
600-
String url = String("http://") + mCfg->groups[group].pm_src + String("/") + String(mCfg->groups[group].pm_jsonPath);
599+
String url = String("http://");
600+
url += String(mCfg->groups[group].pm_user) + ":" + String(mCfg->groups[group].pm_pass) + "@";
601+
url += String(mCfg->groups[group].pm_src) + "/" + String(mCfg->groups[group].pm_jsonPath);
601602

602-
setHeader(&http, auth);
603+
setHeader(&http, mCfg->groups[group].pm_cred);
603604
http.begin(url);
604605

605606
if (http.GET() == HTTP_CODE_OK && http.getSize() > 0) {
@@ -629,6 +630,12 @@ class powermeter {
629630
}
630631
}
631632
}
633+
else if (http.GET() != HTTP_CODE_OK || http.getSize() <= 0)
634+
{
635+
DBGPRINT("http-error: "); DBGPRINTLN(String(http.GET()));
636+
DBGPRINT("http-error size: "); DBGPRINTLN(String(http.getSize()));
637+
result = false;
638+
}
632639

633640
http.end();
634641
return result;

src/web/RestApi.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -1310,11 +1310,12 @@ class RestApi {
13101310
snprintf(mConfig->plugin.zeroExport.groups[group].pm_jsonPath, ZEROEXPORT_GROUP_MAX_LEN_PM_JSONPATH, "%s", jsonIn[F("pm_jsonPath")].as<const char*>());
13111311

13121312

1313-
if (jsonIn[F("pm_pass")] != F("****"))
1313+
if (strcmp(jsonIn[F("pm_pass")], "****") != 0)
13141314
{
13151315
String auth = base64::encode(String(jsonIn[F("pm_user")]) + String(":") + String(jsonIn[F("pm_pass")]));
13161316
snprintf(mConfig->plugin.zeroExport.groups[group].pm_user, ZEROEXPORT_GROUP_MAX_LEN_PM_USER, "%s", String(jsonIn[F("pm_user")]).c_str());
1317-
snprintf(mConfig->plugin.zeroExport.groups[group].pm_pass, ZEROEXPORT_GROUP_MAX_LEN_PM_PASS, "%s", auth.c_str());
1317+
snprintf(mConfig->plugin.zeroExport.groups[group].pm_pass, ZEROEXPORT_GROUP_MAX_LEN_PM_USER, "%s", String(jsonIn[F("pm_pass")]).c_str());
1318+
snprintf(mConfig->plugin.zeroExport.groups[group].pm_cred, ZEROEXPORT_GROUP_MAX_LEN_PM_CRED, "%s", auth.c_str());
13181319
}
13191320

13201321
mConfig->plugin.zeroExport.groups[group].pm_target = jsonIn[F("pm_target")];

src/web/html/setup.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -1669,9 +1669,9 @@
16691669
divsToHide.childNodes[5].style.display = 'none';
16701670
divsToHide.childNodes[6].style.display = 'none';
16711671
}
1672-
else if(value == "Tibber") {
1673-
divsToHide.childNodes[4].style.display = 'none';
1674-
}
1672+
//else if(value == "Tibber") {
1673+
//divsToHide.childNodes[4].style.display = 'none';
1674+
//}
16751675
else if(value == "Shrdzm") {
16761676
divsToHide.childNodes[1].style.display = 'none';
16771677
divsToHide.childNodes[2].style.display = 'none';

src/web/html/visualization.html

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
<div id="content">
1212
<div id="live"></div>
1313
<p>{#EVERY} <span id="refresh"></span> {#UPDATE_SECS}</p>
14-
<div id="zero_export"></div>
15-
<p>Every <span id="refresh"></span> seconds the values are updated</p>
1614
</div>
1715
</div>
1816
{#HTML_FOOTER}

0 commit comments

Comments
 (0)