Skip to content

Commit

Permalink
Merge branch 'ze_v140' into zero-export
Browse files Browse the repository at this point in the history
  • Loading branch information
tictrick committed Aug 16, 2024
2 parents 82d75bd + ef5dcbb commit d28b666
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/config/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ typedef struct {
#define ZEROEXPORT_GROUP_MAX_LEN_PM_JSONPATH 100
#define ZEROEXPORT_GROUP_MAX_LEN_PM_USER 25
#define ZEROEXPORT_GROUP_MAX_LEN_PM_PASS 25
#define ZEROEXPORT_GROUP_MAX_LEN_PM_CRED 25
#define ZEROEXPORT_GROUP_MAX_LEN_BATT_TOPIC 100
#define ZEROEXPORT_GROUP_MAX_INVERTERS 3
#define ZEROEXPORT_POWERMETER_MAX_ERRORS 5
Expand Down Expand Up @@ -310,6 +311,7 @@ typedef struct {
char pm_jsonPath[ZEROEXPORT_GROUP_MAX_LEN_PM_JSONPATH];
char pm_user[ZEROEXPORT_GROUP_MAX_LEN_PM_USER];
char pm_pass[ZEROEXPORT_GROUP_MAX_LEN_PM_PASS];
char pm_cred[ZEROEXPORT_GROUP_MAX_LEN_PM_CRED];
uint8_t pm_target;
// Inverters
zeroExportGroupInverter_t inverters[ZEROEXPORT_GROUP_MAX_INVERTERS];
Expand Down
25 changes: 16 additions & 9 deletions src/plugins/zeroExport/powermeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,19 @@ class powermeter {
*/
void setHeader(HTTPClient *h, String auth = "", u8_t realm = 0) {
h->setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
/// h->setUserAgent("Ahoy-Agent");
/// // TODO: Ahoy-0.8.850024-zero
h->setUserAgent(mApp->getVersion());
h->setConnectTimeout(500);
h->setTimeout(1000);
h->addHeader("Content-Type", "application/json");
h->addHeader("Accept", "application/json");

if (auth != NULL && realm) {
// h->addHeader("WWW-Authenticate", "Digest qop=\"auth\", realm=\"" + "shellypro4pm-f008d1d8b8b8" + "\\", nonce=\"60dc59c6\", algorithm=SHA-256");
} else if (!auth.isEmpty()) {
h->addHeader("Authorization", "Basic " + auth);
}

/*
Shelly PM Mini Gen3
Shelly Plus 1PM
Expand All @@ -343,11 +348,6 @@ class powermeter {
Shelly 3EM
Shelly EM + 120A Clamp
*/

/*if (auth != NULL && realm) http.addHeader("WWW-Authenticate", "Digest qop=\"auth\", realm=\"" + shellypro4pm-f008d1d8b8b8 + "\", nonce=\"60dc59c6\", algorithm=SHA-256");
else if (auth != NULL) http.addHeader("Authorization", "Basic " + auth);*/
/*
All Required:
realm: string, device_id of the Shelly device.
username: string, must be set to admin.
Expand Down Expand Up @@ -596,10 +596,11 @@ class powermeter {
bool result = false;
mLog->addProperty("mod", "getPowermeterWattsTibber");

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

setHeader(&http, auth);
setHeader(&http, mCfg->groups[group].pm_cred);
http.begin(url);

if (http.GET() == HTTP_CODE_OK && http.getSize() > 0) {
Expand Down Expand Up @@ -629,6 +630,12 @@ class powermeter {
}
}
}
else if (http.GET() != HTTP_CODE_OK || http.getSize() <= 0)
{
DBGPRINT("http-error: "); DBGPRINTLN(String(http.GET()));
DBGPRINT("http-error size: "); DBGPRINTLN(String(http.getSize()));
result = false;
}

http.end();
return result;
Expand Down
5 changes: 3 additions & 2 deletions src/web/RestApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1310,11 +1310,12 @@ class RestApi {
snprintf(mConfig->plugin.zeroExport.groups[group].pm_jsonPath, ZEROEXPORT_GROUP_MAX_LEN_PM_JSONPATH, "%s", jsonIn[F("pm_jsonPath")].as<const char*>());


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

mConfig->plugin.zeroExport.groups[group].pm_target = jsonIn[F("pm_target")];
Expand Down
6 changes: 3 additions & 3 deletions src/web/html/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -1669,9 +1669,9 @@
divsToHide.childNodes[5].style.display = 'none';
divsToHide.childNodes[6].style.display = 'none';
}
else if(value == "Tibber") {
divsToHide.childNodes[4].style.display = 'none';
}
//else if(value == "Tibber") {
//divsToHide.childNodes[4].style.display = 'none';
//}
else if(value == "Shrdzm") {
divsToHide.childNodes[1].style.display = 'none';
divsToHide.childNodes[2].style.display = 'none';
Expand Down
2 changes: 0 additions & 2 deletions src/web/html/visualization.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
<div id="content">
<div id="live"></div>
<p>{#EVERY} <span id="refresh"></span> {#UPDATE_SECS}</p>
<div id="zero_export"></div>
<p>Every <span id="refresh"></span> seconds the values are updated</p>
</div>
</div>
{#HTML_FOOTER}
Expand Down

0 comments on commit d28b666

Please sign in to comment.