Skip to content

Commit

Permalink
Merge pull request #13 from DanielR92/zero-export
Browse files Browse the repository at this point in the history
Tibber changes
  • Loading branch information
tictrick authored May 12, 2024
2 parents e363422 + d1535ea commit def77f1
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 99 deletions.
46 changes: 30 additions & 16 deletions src/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ build_flags =
build_unflags =
-std=gnu++11


[env:esp8266-minimal]
platform = espressif8266
board = esp12e
Expand Down Expand Up @@ -148,15 +147,15 @@ monitor_filters =
esp8266_exception_decoder

[env:esp32-wroom32-minimal]
platform = espressif32@6.5.0
platform = espressif32@6.6.0
board = lolin_d32
build_flags = ${env.build_flags}
-DUSE_HSPI_FOR_EPD
monitor_filters =
esp32_exception_decoder

[env:esp32-wroom32]
platform = espressif32@6.5.0
platform = espressif32@6.6.0
board = lolin_d32
build_flags = ${env:esp32-wroom32-minimal.build_flags}
-DENABLE_MQTT
Expand All @@ -167,23 +166,23 @@ monitor_filters =
esp32_exception_decoder

[env:esp32-wroom32-de]
platform = espressif32@6.5.0
platform = espressif32@6.6.0
board = lolin_d32
build_flags = ${env:esp32-wroom32.build_flags}
-DLANG_DE
monitor_filters =
esp32_exception_decoder

[env:esp32-wroom32-prometheus]
platform = espressif32@6.5.0
platform = espressif32@6.6.0
board = lolin_d32
build_flags = ${env:esp32-wroom32.build_flags}
-DENABLE_PROMETHEUS_EP
monitor_filters =
esp32_exception_decoder

[env:esp32-wroom32-prometheus-de]
platform = espressif32@6.5.0
platform = espressif32@6.6.0
board = lolin_d32
build_flags = ${env:esp32-wroom32-prometheus.build_flags}
-DLANG_DE
Expand Down Expand Up @@ -219,7 +218,7 @@ monitor_filters =
esp32_exception_decoder

[env:esp32-s2-mini]
platform = espressif32@6.5.0
platform = espressif32@6.6.0
board = lolin_s2_mini
build_flags = ${env.build_flags}
-DUSE_HSPI_FOR_EPD
Expand All @@ -242,15 +241,15 @@ monitor_filters =
esp32_exception_decoder

[env:esp32-s2-mini-de]
platform = espressif32@6.5.0
platform = espressif32@6.6.0
board = lolin_s2_mini
build_flags = ${env:esp32-s2-mini.build_flags}
-DLANG_DE
monitor_filters =
esp32_exception_decoder

[env:esp32-c3-mini]
platform = espressif32@6.5.0
platform = espressif32@6.6.0
board = lolin_c3_mini
build_flags = ${env.build_flags}
-DUSE_HSPI_FOR_EPD
Expand All @@ -273,15 +272,15 @@ monitor_filters =
esp32_exception_decoder

[env:esp32-c3-mini-de]
platform = espressif32@6.5.0
platform = espressif32@6.6.0
board = lolin_c3_mini
build_flags = ${env:esp32-c3-mini.build_flags}
-DLANG_DE
monitor_filters =
esp32_exception_decoder

[env:opendtufusion-minimal]
platform = espressif32@6.5.0
platform = espressif32@6.6.0
board = esp32-s3-devkitc-1
upload_protocol = esp-builtin
build_flags = ${env.build_flags}
Expand All @@ -306,28 +305,43 @@ monitor_filters =
esp32_exception_decoder, colorize

[env:opendtufusion]
platform = espressif32@6.5.0
platform = espressif32@6.6.0
board = esp32-s3-devkitc-1
upload_protocol = esp-builtin
build_flags = ${env:opendtufusion-minimal.build_flags}
-DENABLE_MQTT
-DPLUGIN_DISPLAY
-DENABLE_HISTORY
-DPLUGIN_ZEROEXPORT
monitor_filters =
esp32_exception_decoder, colorize

[env:opendtufusion-de]
platform = espressif32@6.5.0
platform = espressif32@6.6.0
board = esp32-s3-devkitc-1
upload_protocol = esp-builtin
build_flags = ${env:opendtufusion.build_flags}
-DLANG_DE
monitor_filters =
esp32_exception_decoder, colorize

[env:opendtufusion-zero_export]
platform = [email protected]
board = esp32-s3-devkitc-1
upload_protocol = esp-builtin
build_flags = ${env:opendtufusion.build_flags}
-DPLUGIN_ZEROEXPORT
monitor_filters =
esp32_exception_decoder, colorize

[env:opendtufusion-zero_export-de]
platform = [email protected]
board = esp32-s3-devkitc-1
upload_protocol = esp-builtin
build_flags = ${env:opendtufusion-zero_export.build_flags}
-DLANG_DE

[env:opendtufusion-ethernet]
platform = espressif32@6.5.0
platform = espressif32@6.6.0
board = esp32-s3-devkitc-1
upload_protocol = esp-builtin
build_flags = ${env:opendtufusion-minimal.build_flags}
Expand All @@ -347,7 +361,7 @@ monitor_filters =
esp32_exception_decoder, colorize

[env:opendtufusion-ethernet-de]
platform = espressif32@6.5.0
platform = espressif32@6.6.0
board = esp32-s3-devkitc-1
upload_protocol = esp-builtin
build_flags = ${env:opendtufusion-ethernet.build_flags}
Expand Down
19 changes: 7 additions & 12 deletions src/plugins/zeroExport/powermeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "config/settings.h"

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

#include <list>
Expand Down Expand Up @@ -98,6 +97,11 @@ class powermeter {
break;
#endif
#if defined(ZEROEXPORT_POWERMETER_TIBBER)
/* Anscheinend nutzt bei mir Tibber auch diese Freq.
862.75 MHz - keine Verbindung
863.00 MHz - geht (standard) jedoch hat Tibber dann Probleme... => 4 & 5 Balken
863.25 MHz - geht (ohne Tibber Probleme) => 3 & 4 Balken
*/
case zeroExportPowermeterType_t::Tibber:
result = getPowermeterWattsTibber(*mLog, group, &power);
mPreviousTsp += 2000; // Zusätzliche Pause
Expand Down Expand Up @@ -254,7 +258,7 @@ class powermeter {
PubMqttType *mMqtt = nullptr;
JsonObject *mLog;

unsigned long mPreviousTsp = 0;
unsigned long mPreviousTsp = millis();

float mPowermeterBuffer[ZEROEXPORT_MAX_GROUPS][5] = {0};
short mPowermeterBufferPos[ZEROEXPORT_MAX_GROUPS] = {0};
Expand Down Expand Up @@ -495,16 +499,7 @@ class powermeter {

logObj["mod"] = "getPowermeterWattsTibber";

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 auth = mCfg->groups[group].pm_pass;
String url = String("http://") + mCfg->groups[group].pm_url + String("/") + String(mCfg->groups[group].pm_jsonPath);

setHeader(&http);
Expand Down
107 changes: 39 additions & 68 deletions src/plugins/zeroExport/zeroExport.h
Original file line number Diff line number Diff line change
Expand Up @@ -637,40 +637,28 @@ class ZeroExport {

if (obj["path"] == "ctrl" && obj["cmd"] == "zero") {
int8_t topicGroup = getGroupFromTopic(topic.c_str());
if (topicGroup != -1)
mLog["g"] = topicGroup;
int8_t topicInverter = getInverterFromTopic(topic.c_str());
if (topicInverter == -1)
mLog["i"] = topicInverter;

if (topicGroup != -1) mLog["g"] = topicGroup;
if (topicInverter == -1) mLog["i"] = topicInverter;

mLog["k"] = topic;

// "topic":"ctrl/zero/enabled"
if (topic.indexOf("ctrl/zero/enabled") != -1) {
mCfg->enabled = (bool)obj["val"];
mLog["k"] = "ctrl/zero/enabled";
mLog["v"] = mCfg->enabled;
}
if (topic.indexOf("ctrl/zero/enabled") != -1) mCfg->enabled = mLog["v"] = (bool)obj["val"];

// "topic":"ctrl/zero/sleep"
if (topic.indexOf("ctrl/zero/sleep") != -1) {
mCfg->sleep = (bool)obj["val"];
mLog["k"] = "ctrl/zero/sleep";
mLog["v"] = mCfg->sleep;
}
else if (topic.indexOf("ctrl/zero/sleep") != -1) mCfg->sleep = mLog["v"] = (bool)obj["val"];

else if ((topicGroup >= 0) && (topicGroup < ZEROEXPORT_MAX_GROUPS))
{
String stopicGroup = String(topicGroup);

if ((topicGroup >= 0) && (topicGroup < ZEROEXPORT_MAX_GROUPS)) {
// "topic":"ctrl/zero/groups/+/enabled"
if (topic.indexOf("ctrl/zero/groups/" + String(topicGroup) + "/enabled") != -1) {
mCfg->groups[topicGroup].enabled = (bool)obj["val"];
mLog["k"] = "ctrl/zero/groups/" + String(topicGroup) + "/enabled";
mLog["v"] = mCfg->groups[topicGroup].enabled;
}
if (topic.endsWith("/enabled")) mCfg->groups[topicGroup].enabled = mLog["v"] = (bool)obj["val"];

// "topic":"ctrl/zero/groups/+/sleep"
if (topic.indexOf("ctrl/zero/groups/" + String(topicGroup) + "/sleep") != -1) {
mCfg->groups[topicGroup].sleep = (bool)obj["val"];
mLog["k"] = "ctrl/zero/groups/" + String(topicGroup) + "/sleep";
mLog["v"] = mCfg->groups[topicGroup].sleep;
}
else if (topic.endsWith("/sleep")) mCfg->groups[topicGroup].sleep = mLog["v"] = (bool)obj["val"];

// Auf Eis gelegt, dafür 2 Gruppen mehr
// 0.8.103008.2
Expand All @@ -695,55 +683,37 @@ class ZeroExport {
// }

// "topic":"ctrl/zero/groups/+/battery/switch"
if (topic.indexOf("ctrl/zero/groups/" + String(topicGroup) + "/battery/switch") != -1) {
mCfg->groups[topicGroup].battSwitch = (bool)obj["val"];
mLog["k"] = "ctrl/zero/groups/" + String(topicGroup) + "/battery/switch";
mLog["v"] = mCfg->groups[topicGroup].battSwitch;
}
else if (topic.endsWith("/battery/switch")) mCfg->groups[topicGroup].battSwitch = mLog["v"] = (bool)obj["val"];

// "topic":"ctrl/zero/groups/+/advanced/setPoint"
if (topic.indexOf("ctrl/zero/groups/" + String(topicGroup) + "/advanced/setPoint") != -1) {
mCfg->groups[topicGroup].setPoint = (int16_t)obj["val"];
mLog["k"] = "ctrl/zero/groups/" + String(topicGroup) + "/advanced/setPoint";
mLog["v"] = mCfg->groups[topicGroup].setPoint;
}
else if (topic.indexOf("/advanced/") != -1)
{
// "topic":"ctrl/zero/groups/+/advanced/setPoint"
if (topic.endsWith("/setPoint")) mCfg->groups[topicGroup].setPoint = mLog["v"] = (int16_t)obj["val"];

// "topic":"ctrl/zero/groups/+/advanced/powerTolerance"
if (topic.indexOf("ctrl/zero/groups/" + String(topicGroup) + "/advanced/powerTolerance") != -1) {
mCfg->groups[topicGroup].powerTolerance = (uint8_t)obj["val"];
mLog["k"] = "ctrl/zero/groups/" + String(topicGroup) + "/advanced/powerTolerance";
mLog["v"] = mCfg->groups[topicGroup].powerTolerance;
}
// "topic":"ctrl/zero/groups/+/advanced/powerTolerance"
else if (topic.endsWith("/powerTolerance")) mCfg->groups[topicGroup].powerTolerance = mLog["v"] = (uint8_t)obj["val"];

// "topic":"ctrl/zero/groups/+/advanced/powerMax"
if (topic.indexOf("ctrl/zero/groups/" + String(topicGroup) + "/advanced/powerMax") != -1) {
mCfg->groups[topicGroup].powerMax = (uint16_t)obj["val"];
mLog["k"] = "ctrl/zero/groups/" + String(topicGroup) + "/advanced/powerMax";
mLog["v"] = mCfg->groups[topicGroup].powerMax;
// "topic":"ctrl/zero/groups/+/advanced/powerMax"
else if (topic.endsWith("/powerMax")) mCfg->groups[topicGroup].powerMax = mLog["v"] = (uint16_t)obj["val"];
}

if ((topicInverter >= 0) && (topicInverter < ZEROEXPORT_GROUP_MAX_INVERTERS)) {
// "topic":"ctrl/zero/groups/+/inverter/+/enabled"
if (topic.indexOf("ctrl/zero/groups/" + String(topicGroup) + "/inverter/" + String(topicInverter) + "/enabled") != -1) {
mCfg->groups[topicGroup].inverters[topicInverter].enabled = (bool)obj["val"];
mLog["k"] = "ctrl/zero/groups/" + String(topicGroup) + "/inverter/" + String(topicInverter) + "/enabled";
mLog["v"] = mCfg->groups[topicGroup].inverters[topicInverter].enabled;
}

// "topic":"ctrl/zero/groups/+/inverter/+/powerMin"
if (topic.indexOf("ctrl/zero/groups/" + String(topicGroup) + "/inverter/" + String(topicInverter) + "/powerMin") != -1) {
mCfg->groups[topicGroup].inverters[topicInverter].powerMin = (uint16_t)obj["val"];
mLog["k"] = "ctrl/zero/groups/" + String(topicGroup) + "/inverter/" + String(topicInverter) + "/powerMin";
mLog["v"] = mCfg->groups[topicGroup].inverters[topicInverter].powerMin;
}

// "topic":"ctrl/zero/groups/+/inverter/+/powerMax"
if (topic.indexOf("ctrl/zero/groups/" + String(topicGroup) + "/inverter/" + String(topicInverter) + "/powerMax") != -1) {
mCfg->groups[topicGroup].inverters[topicInverter].powerMax = (uint16_t)obj["val"];
mLog["k"] = "ctrl/zero/groups/" + String(topicGroup) + "/inverter/" + String(topicInverter) + "/powerMax";
mLog["v"] = mCfg->groups[topicGroup].inverters[topicInverter].powerMax;
else if (topic.indexOf("/inverter/") != -1)
{
if ((topicInverter >= 0) && (topicInverter < ZEROEXPORT_GROUP_MAX_INVERTERS))
{
// "topic":"ctrl/zero/groups/+/inverter/+/enabled"
if (topic.endsWith("/enabled")) mCfg->groups[topicGroup].inverters[topicInverter].enabled = mLog["v"] = (bool)obj["val"];

// "topic":"ctrl/zero/groups/+/inverter/+/powerMin"
else if (topic.endsWith("/powerMin")) mCfg->groups[topicGroup].inverters[topicInverter].powerMin = mLog["v"] = (uint16_t)obj["val"];

// "topic":"ctrl/zero/groups/+/inverter/+/powerMax"
else if (topic.endsWith("/powerMax")) mCfg->groups[topicGroup].inverters[topicInverter].powerMax = mLog["v"] = (uint16_t)obj["val"];
else mLog["k"] = "error";
}
}
else {
mLog["k"] = "error";
}
}
}

Expand Down Expand Up @@ -791,6 +761,7 @@ class ZeroExport {
while (*pGroupSection != '/' && digitsCopied < 2) strGroup[digitsCopied++] = *pGroupSection++;
strGroup[digitsCopied] = '\0';
int8_t group = atoi(strGroup);
mLog["getGroupFromTopic"] = group;
return group;
}

Expand Down
12 changes: 10 additions & 2 deletions src/web/RestApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "ESPAsyncWebServer.h"

#include "plugins/history.h"
#include <base64.h>

#if defined(F) && defined(ESP32)
#undef F
Expand Down Expand Up @@ -1161,8 +1162,15 @@ class RestApi {
mConfig->plugin.zeroExport.groups[group].pm_type = jsonIn[F("pm_type")];
snprintf(mConfig->plugin.zeroExport.groups[group].pm_url, ZEROEXPORT_GROUP_MAX_LEN_PM_URL, "%s", jsonIn[F("pm_url")].as<const char*>());
snprintf(mConfig->plugin.zeroExport.groups[group].pm_jsonPath, ZEROEXPORT_GROUP_MAX_LEN_PM_JSONPATH, "%s", jsonIn[F("pm_jsonPath")].as<const char*>());
snprintf(mConfig->plugin.zeroExport.groups[group].pm_user, ZEROEXPORT_GROUP_MAX_LEN_PM_USER, "%s", jsonIn[F("pm_user")].as<const char*>());
snprintf(mConfig->plugin.zeroExport.groups[group].pm_pass, ZEROEXPORT_GROUP_MAX_LEN_PM_PASS, "%s", jsonIn[F("pm_pass")].as<const char*>());


if (jsonIn[F("pm_pass")] != F("****"))
{
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());
}

mConfig->plugin.zeroExport.groups[group].pm_target = jsonIn[F("pm_target")];
// Inverters
for(uint8_t inv = 0; inv < ZEROEXPORT_GROUP_MAX_INVERTERS; inv++) {
Expand Down
2 changes: 1 addition & 1 deletion src/web/html/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@
ml("input", {name: "pm_jsonPath", class: "text", type: "text", value: obj.pm_jsonPath}, null),
]),
divRow("{#ZE_GROUP_TAB_POWERMETER_USER}",
ml("input", {name: "pm_user", class: "text", type: "text", value: "" }, null),
ml("input", {name: "pm_user", class: "text", type: "text", value: obj.pm_user }, null),
),
divRow("{#ZE_GROUP_TAB_POWERMETER_PASS}",
ml("input", {name: "pm_pass", class: "text", type: "password", value: "****"}, null),
Expand Down

0 comments on commit def77f1

Please sign in to comment.