From ab651d22f1a0e6ca6d52bed799bdfff2535897e8 Mon Sep 17 00:00:00 2001 From: GerhardMitterbaur <63344758+mgerhard74@users.noreply.github.com> Date: Fri, 11 Oct 2024 17:10:11 +0200 Subject: [PATCH] Add files via upload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Änderungen für 1.3.0 --- src/main.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++-- src/proj.h | 8 +++++++- src/system.cpp | 5 +++++ 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 654f17f..88d89e8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -57,6 +57,7 @@ String lastMonth; kwhstruct kwh_hist[7]; bool inAPMode,mqttStatus,hwTest; ADC_MODE(ADC_VCC); +int switch_last = 0; void setup(){ Serial.begin(9600,SERIAL_8E1); // Schnittstelle zu Amis-Z?er @@ -273,16 +274,58 @@ void secTick() { writeHistFileIn(x,a_result[0]); kwh_day_out[x]=a_result[1]; // 2.8.0 writeHistFileOut(x,a_result[1]); - dow_local=dow; + dow_local=dow; if (mon_local != mon) { // Monatswechsel writeMonthFile(year,mon); mon_local=mon; } first_frame=2; // Wochen- + Monatstabelle Energie neu erzeugen + + if ((millis()/1000 > 43200) && (config.reboot0)) // Reboot wenn uptime > 12h + { + writeEvent("INFO", "sys", "Reboot uptime>12h", ""); + delay(10); + ESP.restart(); + } } } - /// Thingspeak aktualisieren + // Wifi Switch on/off + if ((config.switch_url_on != "") && (config.switch_url_off != "")) + { + signed int xsaldo; + xsaldo=(a_result[4]-a_result[5]); + unsigned int sek = (millis()/1000) % 5; + + if ((xsaldo < config.switch_on) && (switch_last != 1) && (sek == 0)) + { + HTTPClient http; + WiFiClient client; + http.begin(client,config.switch_url_on); + int httpCode = http.GET(); + if(httpCode == HTTP_CODE_OK) + { + //writeEvent("INFO", "sys", "Switch on Url sent", ""); + } + http.end(); + switch_last = 1; + } + if ((xsaldo > config.switch_off) && (switch_last != 2) && (sek == 0)) + { + HTTPClient http; + WiFiClient client; + http.begin(client,config.switch_url_off); + int httpCode = http.GET(); + if(httpCode == HTTP_CODE_OK) + { + //writeEvent("INFO", "sys", "Switch off Url sent", ""); + } + http.end(); + switch_last = 2; + } + } + + // Thingspeak aktualisieren if (config.thingspeak_aktiv && things_cycle >= config.thingspeak_iv && new_data && valid==5) { things_cycle=0; thingspeak_watch++; diff --git a/src/proj.h b/src/proj.h index 085d077..ce95e5e 100644 --- a/src/proj.h +++ b/src/proj.h @@ -13,6 +13,7 @@ #include "LittleFS.h" #include #include +#include /// Debug Einstellungen: /// DEBUGHW 0 keine Ausgaben @@ -25,7 +26,7 @@ #define AP_PIN 14 //#define OTA //#define STROMPREIS -#define VERSION "1.2.9" +#define VERSION "1.3.0" #define APP_NAME "Amis" extern String dbg_string; extern char dbg[128]; @@ -59,6 +60,11 @@ struct strConfig { unsigned rest_var; signed rest_ofs; bool rest_neg; + bool reboot0; + signed switch_on; + signed switch_off; + String switch_url_on; + String switch_url_off; }; struct kwhstruct { unsigned kwh_in; diff --git a/src/system.cpp b/src/system.cpp index c73cb21..4ab6863 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -190,6 +190,11 @@ void generalInit() { config.rest_var=json[F("rest_var")].as(); config.rest_ofs=json[F("rest_ofs")].as(); config.rest_neg=json[F("rest_neg")].as(); + config.reboot0=json[F("reboot0")].as(); + config.switch_on=json[F("switch_on")].as(); + config.switch_off=json[F("switch_off")].as(); + config.switch_url_on=json[F("switch_url_on")].as(); + config.switch_url_off=json[F("switch_url_off")].as(); } void histInit () {