Browse Source

Merge branch 'zero-export' of https://github.com/tictrick/ahoy into zero-export

pull/1638/head
Patrick Amrhein 9 months ago
parent
commit
5e78719e17
  1. 46
      src/platformio.ini
  2. 21
      src/plugins/zeroExport/powermeter.h
  3. 91
      src/plugins/zeroExport/zeroExport.h
  4. 12
      src/web/RestApi.h
  5. 2
      src/web/html/setup.html

46
src/platformio.ini

@ -40,7 +40,6 @@ build_flags =
build_unflags =
-std=gnu++11
[env:esp8266-minimal]
platform = espressif8266
board = esp12e
@ -148,7 +147,7 @@ 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
@ -156,7 +155,7 @@ 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
@ -167,7 +166,7 @@ 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
@ -175,7 +174,7 @@ 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
@ -183,7 +182,7 @@ 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
@ -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
@ -242,7 +241,7 @@ 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
@ -250,7 +249,7 @@ 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
@ -273,7 +272,7 @@ 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
@ -281,7 +280,7 @@ 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}
@ -306,19 +305,18 @@ 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}
@ -326,8 +324,24 @@ build_flags = ${env:opendtufusion.build_flags}
monitor_filters =
esp32_exception_decoder, colorize
[env:opendtufusion-zero_export]
platform = espressif32@6.6.0
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 = espressif32@6.6.0
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}
@ -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}

21
src/plugins/zeroExport/powermeter.h

@ -14,7 +14,6 @@
#include "config/settings.h"
#if defined(ZEROEXPORT_POWERMETER_TIBBER)
#include <base64.h>
#include <string.h>
#include <list>
@ -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
@ -240,7 +244,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};
@ -481,17 +485,8 @@ 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 url = String("http://") + mCfg->groups[group].pm_src + String("/") + String(mCfg->groups[group].pm_jsonPath);
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);
http.begin(url);

91
src/plugins/zeroExport/zeroExport.h

@ -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
@ -695,54 +683,36 @@ 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"];
else if (topic.indexOf("/advanced/") != -1)
{
// "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;
}
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;
}
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;
else if (topic.endsWith("/powerMax")) mCfg->groups[topicGroup].powerMax = mLog["v"] = (uint16_t)obj["val"];
}
if ((topicInverter >= 0) && (topicInverter < ZEROEXPORT_GROUP_MAX_INVERTERS)) {
else if (topic.indexOf("/inverter/") != -1)
{
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;
}
if (topic.endsWith("/enabled")) mCfg->groups[topicGroup].inverters[topicInverter].enabled = mLog["v"] = (bool)obj["val"];
// "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;
}
else if (topic.endsWith("/powerMin")) mCfg->groups[topicGroup].inverters[topicInverter].powerMin = mLog["v"] = (uint16_t)obj["val"];
// "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.endsWith("/powerMax")) mCfg->groups[topicGroup].inverters[topicInverter].powerMax = mLog["v"] = (uint16_t)obj["val"];
else mLog["k"] = "error";
}
}
else {
mLog["k"] = "error";
}
}
}
@ -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;
}

12
src/web/RestApi.h

@ -20,6 +20,7 @@
#include "ESPAsyncWebServer.h"
#include "plugins/history.h"
#include <base64.h>
#if defined(F) && defined(ESP32)
#undef F
@ -1161,8 +1162,15 @@ class RestApi {
mConfig->plugin.zeroExport.groups[group].pm_type = jsonIn[F("pm_type")];
snprintf(mConfig->plugin.zeroExport.groups[group].pm_src, ZEROEXPORT_GROUP_MAX_LEN_PM_SRC, "%s", jsonIn[F("pm_src")].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++) {

2
src/web/html/setup.html

@ -1399,7 +1399,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),

Loading…
Cancel
Save