From fe1030881e48f1fe9091cf1c24d2fc1d5b3af66d Mon Sep 17 00:00:00 2001 From: Daddy Date: Fri, 26 Dec 2025 12:51:19 +0100 Subject: [PATCH 1/4] feat: implementiere display taster per interrupt --- zisterne/display.ino | 201 +++++++++++++++++++++++++---------------- zisterne/myTypes.h | 3 +- zisterne/ota.ino | 4 +- zisterne/rechnen.ino | 11 +++ zisterne/relais.ino | 2 +- zisterne/relais2.ino | 2 +- zisterne/webserver.ino | 135 ++++++++++++++++++++++----- zisterne/zisterne.ino | 152 ++++++++++++++++++++++++++++--- 8 files changed, 385 insertions(+), 125 deletions(-) diff --git a/zisterne/display.ino b/zisterne/display.ino index e61b595..00eaf30 100644 --- a/zisterne/display.ino +++ b/zisterne/display.ino @@ -2,12 +2,13 @@ //LCD Setup //*********************** void ladeLCDdisplay() { - Wire.begin(12, 13); //SDA-D6, SCL-D7 // LCD Setup (bei beiden LCD Displays gleich) + // Wire.begin(12, 13); //SDA-D6, SCL-D7 // LCD Setup (bei beiden LCD Displays gleich) // *******************Boot mit LAN-Info für 1602 Display************************** if (cfg.data_display ==1) { timer.setInterval(1000); - lcd.begin(); + // lcd.begin(); + lcd.init(); lcd.backlight(); lcd.print(cfg.SSID); lcd.setCursor(0, 1); @@ -27,7 +28,7 @@ // *******************Boot mit LAN-Info für 1604 Display************************** if (cfg.data_display ==2) { timer.setInterval(1000); - lcd.begin(); + lcd.init(); lcd.backlight(); lcd.setCursor(0, 0); lcd.print("Ihre SSID:"); @@ -47,7 +48,8 @@ delay (5000); lcd.noBacklight(); } - } + } + void ladeOLEDdisplay() { //*******************************Initialisierung und DEBUG OLED************************************ @@ -97,101 +99,140 @@ //LCD mit Tastersteuerung für 1602 Display //*********************** void loop1602() { - if ( millis() - displayMicros >= 5000 ) { - displayMicros = millis(); - lcd.clear(); - lcd.setCursor(0,0); - lcd.print(volumen); - lcd.print( " Liter,"); - lcd.setCursor(0,1); - lcd.print(fuellstand); - lcd.print( " % voll"); + if (millis() - displayMicros >= 5000 ) { + displayMicros = millis(); + lcd.clear(); + lcd.setCursor(0,0); + lcd.print(volumen); + lcd.print( " Liter,"); + lcd.setCursor(0,1); + lcd.print(fuellstand); + lcd.print( " % voll"); } - if ((backlstatus == 0) && (digitalRead(taster) == HIGH)) { - lcd.backlight(); - backlstatus = 1; - delay (300); //gegen Tastenprellen - } unsigned long tasterMicros = millis(); - if (tasterMicros - previousMicros >= 90000 ) { - previousMicros = tasterMicros; - lcd.noBacklight(); + if ((tasterMicros - previousMicros >= 90000) && backlstatus) { + lcd.noBacklight(); + backlstatus = false; + return; } - if ((backlstatus == 1) && (digitalRead(taster) == HIGH)) { - lcd.noBacklight(); - backlstatus = 0; - delay (300); //gegen Tastenprellen + + if ((backlstatus == false) && (tasterHigh)) { + resetBacklightTaster(); + lcd.backlight(); + backlstatus = true; + previousMicros = millis(); + return; + } + + if (backlstatus && tasterHigh) { + resetBacklightTaster(); + lcd.noBacklight(); + backlstatus = false; + return; } - } + +} //*********************** //LCD mit Tastersteuerung für 1604 Display //*********************** - void loop1604() { +void loop1604() { if ( millis() - displayMicros >= 5000 ) { - displayMicros = millis(); - lcd.clear(); - lcd.setCursor(0,0); - lcd.print( "F\365llstand:"); // Ueberschrift - lcd.setCursor(0,1); - lcd.print(volumen); - lcd.print( " Liter,"); - lcd.setCursor(0,3); - lcd.print(fuellstand); - lcd.print( " % voll"); + displayMicros = millis(); + lcd.clear(); + lcd.setCursor(0,0); + lcd.print( "F\365llstand:"); // Ueberschrift + lcd.setCursor(0,1); + lcd.print(volumen); + lcd.print( " Liter,"); + lcd.setCursor(0,3); + lcd.print(fuellstand); + lcd.print( " % voll"); } - if ((backlstatus == 0) && (digitalRead(taster) == HIGH)) { - lcd.backlight(); - backlstatus = 1; - delay (300); //gegen Tastenprellen - } - unsigned long tasterMicros = millis(); - if (tasterMicros - previousMicros >= 180000 ) { - previousMicros = tasterMicros; - lcd.noBacklight(); - } - if ((backlstatus == 1) && (digitalRead(taster) == HIGH)) { - lcd.noBacklight(); - backlstatus = 0; - delay (300); //gegen Tastenprellen - } - } + unsigned long tasterMicros = millis(); + if ((tasterMicros - previousMicros >= 90000) && backlstatus) { + lcd.noBacklight(); + backlstatus = false; + return; + } + + if ((backlstatus == false) && (tasterHigh)) { + resetBacklightTaster(); + lcd.backlight(); + backlstatus = true; + previousMicros = millis(); + return; + } + + if (backlstatus && tasterHigh) { + resetBacklightTaster(); + lcd.noBacklight(); + backlstatus = false; + return; + } +} //*********************** // OLED Display //*********************** + void loopOLED() { - if (((backlstatus == 0) && (digitalRead(taster) == HIGH)) || (backlstatus == 1)){ - backlstatus = 1; - delay (300); - if ( millis() - displayMicros >= 5000 ) { - displayMicros = millis(); + + // setze Display-Timout zu 30 Sekunden + // prüfe wenn Display an ist, ob das letzte Einschalten mehr als 30sek in der Vergangenheit liegt + unsigned long oledTimeout = millis(); + if ((oledTimeout - previousMicros >= 30000) && backlstatus ) { oledFill(&ssoled, 0, 1); - char Volumen[10]; - sprintf(Volumen,"%.2f l", volumen); - char Fuellstand[10]; - sprintf(Fuellstand,"%.2f%%", fuellstand); - oledWriteString(&ssoled, 0,0,0,(char *)"Fuellstand:" , FONT_NORMAL, 0, 1); - oledWriteString(&ssoled, 0,60,3,Volumen, FONT_SMALL, 0, 1); - oledWriteString(&ssoled, 0,60,5,Fuellstand, FONT_SMALL, 0, 1); - //*********************Grafik ********************** - rest = map(fuellstand, 0, 100, 62, 13); // Hoehe des Balkens ermitteln - oledRectangle(&ssoled, (1), (13), (45), (62), 1, 0); // aeussere Linie zeichnen - oledRectangle(&ssoled, (1), (rest), (45), (62), 1, 1); // Fuellbalken - oledDumpBuffer(&ssoled, NULL); - } + backlstatus = false; + return; + } - unsigned long tasterMicros = millis(); - if (tasterMicros - previousMicros >= 180000 ) { - previousMicros = tasterMicros; - oledFill(&ssoled, 0, 1); - backlstatus = 0; - } - if ((backlstatus == 1) && (digitalRead(taster) == HIGH)) { + + //if ((backlstatus == 1) && (digitalRead(taster) == HIGH)) { + + // Schalte das Display aus, falls es an ist + // setze das Flag für den GPIO-Pin zurück + if (backlstatus && tasterHigh) { + resetBacklightTaster(); oledFill(&ssoled, 0, 1); - backlstatus = 0; - delay (300); + //delay (300); //gegen Tastenprellen + backlstatus = false; + return; } + + //if (((backlstatus == 0) && (digitalRead(taster) == HIGH)) || (backlstatus == 1)){ + // if ((backlstatus == 0) && (digitalRead(taster) == HIGH)) { + + // schalte Display ein, falls aus + // aktualisiere Display nach 5 sek falls an + // setze Flag für GPIO-Pin zurück und speichere Zeitpunkt des letzten Taster-Drucks in previousMicros + if (!backlstatus && tasterHigh) { + if (tasterHigh) { + previousMicros = millis(); + } + // delay (300); //gegen Tastenprellen + backlstatus = true; + resetBacklightTaster(); + } + + if (backlstatus) { + // aktualisiere Display + if ( millis() - displayMicros >= 5000 ) { + displayMicros = millis(); + oledFill(&ssoled, 0, 1); + char Volumen[10]; + sprintf(Volumen,"%.2f l", volumen); + char Fuellstand[10]; + sprintf(Fuellstand,"%.2f%%", fuellstand); + oledWriteString(&ssoled, 0,0,0,(char *)"Fuellstand:" , FONT_NORMAL, 0, 1); + oledWriteString(&ssoled, 0,60,3,Volumen, FONT_SMALL, 0, 1); + oledWriteString(&ssoled, 0,60,5,Fuellstand, FONT_SMALL, 0, 1); + //*********************Grafik ********************** + rest = map(fuellstand, 0, 100, 62, 13); // Hoehe des Balkens ermitteln + oledRectangle(&ssoled, (1), (13), (45), (62), 1, 0); // aeussere Linie zeichnen + oledRectangle(&ssoled, (1), (rest), (45), (62), 1, 1); // Fuellbalken + oledDumpBuffer(&ssoled, NULL); + } } } diff --git a/zisterne/myTypes.h b/zisterne/myTypes.h index 35d6783..259fb66 100644 --- a/zisterne/myTypes.h +++ b/zisterne/myTypes.h @@ -47,7 +47,8 @@ typedef struct { //Sonstiges int data_dezstellen_anzeige; int data_anzeige_liter_check; - + int data_height_over_NN; + //weitere MQTT char data_mqtt_abstand_topic[51]; int data_mqtt_port; diff --git a/zisterne/ota.ino b/zisterne/ota.ino index f87a7c9..1a90c6e 100644 --- a/zisterne/ota.ino +++ b/zisterne/ota.ino @@ -20,7 +20,7 @@ void checkForUpdates() { Serial.println( fwVersionURL ); HTTPClient httpClient; - httpClient.begin( fwVersionURL ); + // httpClient.begin( fwVersionURL ); int httpCode = httpClient.GET(); if( httpCode == 200 ) { String newFWVersion = httpClient.getString(); @@ -37,7 +37,7 @@ void checkForUpdates() { String fwImageURL = fwURL; fwImageURL.concat( ".bin" ); - t_httpUpdate_return ret = ESPhttpUpdate.update( fwImageURL ); + t_httpUpdate_return ret = ESPhttpUpdate.update(httpClient, fwImageURL ); switch(ret) { case HTTP_UPDATE_FAILED: diff --git a/zisterne/rechnen.ino b/zisterne/rechnen.ino index 32e564b..2945b73 100644 --- a/zisterne/rechnen.ino +++ b/zisterne/rechnen.ino @@ -52,6 +52,17 @@ void looprechnen() { delay(100); } + //**************************************************** + // Druck Sensor ADS1115 + //**************************************************** + if (cfg.data_zisterne_sensor == 4) { + adc0 = ads.getLastConversionResults(); + //Serial.print("AIN0: "); Serial.println(adc0*0.02); + abstand=(cfg.data_abst_sen_boden-(adc0*0.02)); + fuellhoehe=(adc0*0.02); + delay(100); + } + //abstand = 100; //nur testweise wenn kein Sensor dran haengt //Fuellstand prozentual berechnen diff --git a/zisterne/relais.ino b/zisterne/relais.ino index d7d184a..94477cc 100644 --- a/zisterne/relais.ino +++ b/zisterne/relais.ino @@ -1,5 +1,5 @@ //******************************************************** -// Schaltet ein externes Relais an Ausgang D4 / Pin 2 +// Schaltet ein externes Relais an Ausgang D3 / Pin 0 // in Abhaengigkeit von zwei Werten //******************************************************** void relais() { diff --git a/zisterne/relais2.ino b/zisterne/relais2.ino index 5dbe3f8..176c938 100644 --- a/zisterne/relais2.ino +++ b/zisterne/relais2.ino @@ -1,5 +1,5 @@ //*********************************************************** -// Schaltet ein zweites externes Relais an Ausgang D3 / Pin 2 +// Schaltet ein zweites externes Relais an Ausgang D4 / Pin 2 // in Abhaengigkeit von zwei Werten // NOCH NICHT IMPLEMENTIERT //*********************************************************** diff --git a/zisterne/webserver.ino b/zisterne/webserver.ino index 284a2e3..5faa7ab 100644 --- a/zisterne/webserver.ino +++ b/zisterne/webserver.ino @@ -1,14 +1,16 @@ void webHandleRoot() { String inhalt; float vcc = ESP.getVcc() / 1000.0; - inhalt = ""; - inhalt += "" + anwendungsname + ""; - inhalt += "

  "; - inhalt += "" + anwendungsname + " v" + fw_version + "

"; - inhalt += "

Startseite

"; - inhalt += "
"; - inhalt += "
"; - + inhalt = + "" + ""+anwendungsname+"" + // "

  " + ""+anwendungsname+" v"+fw_version+"

" + "

Startseite

" + "
" + "
"; + + int breite_anzeige = 0; // inhalt += ""; @@ -217,13 +219,35 @@ void webHandleRoot() { } //Abstand + if (cfg.data_zisterne_sensor < 4) { inhalt += "
"; inhalt += abstand; inhalt += "cm"; inhalt += "

Abstand Wasser

"; + } + if (cfg.data_zisterne_sensor == 4) { + inhalt += "
"; + inhalt += fuellhoehe; + inhalt += "cm"; + inhalt += "

Füllhöhe

"; + } +//-------------------------------------------------------------------- if (cfg.data_temperatur_enable == 1) { //Temperatur + if (cfg.data_temperatur == 1) { + inhalt += "
"; + inhalt += temperature; + inhalt += "°C"; + inhalt += "

Temperatur

"; + + //Luftfeuchte + inhalt += "
"; + inhalt += (int)roundf(humidity); + inhalt += "%"; + inhalt += "

Luftfeuchte

"; + } + if (cfg.data_temperatur == 2) { inhalt += "
"; inhalt += temperature; inhalt += "°C"; @@ -234,6 +258,26 @@ void webHandleRoot() { inhalt += (int)roundf(humidity); inhalt += "%"; inhalt += "

Luftfeuchte

"; + + //Luftdruck + inhalt += "
"; + inhalt += (int)roundf(pressure); + inhalt += "hPa"; + inhalt += "

Luftdruck (NN)

"; + } + + if (cfg.data_temperatur == 3) { + inhalt += "
"; + inhalt += temperature; + inhalt += "°C"; + inhalt += "

Temperatur

"; + + //Luftdruck + inhalt += "
"; + inhalt += (int)roundf(pressure); + inhalt += "hPa"; + inhalt += "

Luftdruck (NN)

"; + } } //******************************* @@ -258,7 +302,7 @@ void webHandleRoot() { // inhalt += "
"; // inhalt += relais2_status; // inhalt += ""; - // inhalt += "

Schalter an D3

"; + // inhalt += "

Schalter an D4

"; //} if (cfg.data_webapi_check == 1) { @@ -305,6 +349,9 @@ void webHandleRoot() { } if (cfg.data_zisterne_sensor == 3) { inhalt += "VL53L1X"; + } + if (cfg.data_zisterne_sensor == 4) { + inhalt += "ADS1115"; } inhalt += ""; @@ -529,16 +576,22 @@ void webHandleConfig() { inhalt += "'> an GPIO-Pin 14 (D5) mit 10kΩ von Daten gegen VCC"; inhalt += ""; - inhalt += "
BME280 //Pololu-Lib #include "SparkFun_VL53L1X.h" +#include +#include +#include +#include "Adafruit_BMP280.h" + extern "C" { #include "user_interface.h" @@ -39,11 +44,16 @@ VL53L0X l0x_sensor; //VL53L1X SFEVL53L1X l1x_sensor; +//ADS1115 +Adafruit_ADS1115 ads; /* Use this for the 16-bit version */ +//Adafruit_ADS1015 ads; /* Use this for the 12-bit version */ +int16_t adc0; //******************************************************** // Variablen für Abstandsmessung //******************************************************** int abstand; +int fuellhoehe; float fuellstand; float volumen; int volumen_max; @@ -57,14 +67,23 @@ unsigned long startMillisAbstand; //********************* // Temperatursensor //********************* +// DHT22 #define DHTPIN 14 //D5 #define DHTTYPE DHT22 DHT dht(DHTPIN, DHTTYPE); float humidity; float temperature; +float pressure; +float pressureReal; +float altitude; unsigned long startMillisTemp; unsigned long currentMillisTemp; +//BME280 +Adafruit_BME280 bme; // I2C + +//BMP280 +Adafruit_BMP280 bmp; // I2C //******************************************************** // Konfiguration der Displays @@ -78,22 +97,22 @@ SSOLED ssoled; // benoetigt fuer OLED //Taster fuer Display //int sensor = 14; // D5 VCC Sensor int taster = 15; // D8 für Taster -int tasterstatus = 0; -int previousMicros = 0; -int displayMicros = 0; -int backlstatus = 0; +// int tasterstatus = 0; +int previousMicros = 0; //timer +int displayMicros = 0; //timer +bool backlstatus = false; //******************************************************** // Relais an D4 //******************************************************** -const int relaisPIN = 2; //D4 +const int relaisPIN = 2; //D4 HIGH bei Boot unsigned long startMillisRelais; unsigned long currentMillisRelais; //******************************************************** // Relais an D3 //******************************************************** -const int relais2PIN = 2; //D3 +const int relais2PIN = 0; //D3 unsigned long startMillisRelais2; unsigned long currentMillisRelais2; @@ -144,10 +163,12 @@ const long utcOffsetInSeconds = 7200; NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds); //******************************************************** -// Display refresh +// Display variablen //******************************************************** unsigned long startMillisDisplay; unsigned long currentMillisDisplay; +// vgl. https://docs.arduino.cc/language-reference/funktionen/external-interrupts/attachInterrupt/ +volatile bool tasterHigh; //******************************************************** // Grundsätzliche Einstellungen @@ -187,6 +208,20 @@ uint32_t freeheap = system_get_free_heap_size(); bool gesendet_pushover = false; bool gesendet_mail = false; + +//******************************************************** +// ISR +//******************************************************** +ICACHE_RAM_ATTR void enableBacklight() { + tasterHigh = true; +} + +void resetBacklightTaster() { + tasterHigh = false; +} + + + //******************************************************** // SETUP //******************************************************** @@ -194,9 +229,9 @@ void setup() { Wire.begin(); Serial.begin(115200); - delay(3000); + delay(1000); Serial.println("Auf gehts..."); - + //Lade Konfiguration aus EEPROM ladekonfig(); @@ -275,7 +310,32 @@ void setup() { } } - + //ADS1115 + if (cfg.data_zisterne_sensor == 4) { + Serial.println("ADS1115 ausgewaehlt"); + // The ADC input range (or gain) can be changed via the following + // functions, but be careful never to exceed VDD +0.3V max, or to + // exceed the upper and lower limits if you adjust the input range! + // Setting these values incorrectly may destroy your ADC! + // ------- ------- + ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default) + // ads.setGain(GAIN_ONE); //1x gain +/- 4.096V 1 bit = 2mV 0.125mV + // ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV 0.0625mV + // ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV + // ads.setGain(GAIN_EIGHT); // 8x gaSerial.println("Single-ended readings from AIN0 with >3.0V comparator"); + // Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)"); + // Serial.println("Comparator Threshold: 1000 (3.000V)");in +/- 0.512V 1 bit = 0.25mV 0.015625mV + // ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV + if (!ads.begin()) { + Serial.println("Failed to initialize ADS."); + while (1); + } + + // Setup 3V comparator on channel 0 + ads.startComparator_SingleEnded(0, 1000); + } + +//----------------------------------------------------------------------------------------- //Zeit merken um EigenAPI, WebAPI und OTA zeitgesteuert aufzurufen //auch Intervall zum Refresh von Display und NTP startMillisEigen = millis(); @@ -313,23 +373,57 @@ void setup() { } //Starte Temperaturmessung - dht.begin(); + if (cfg.data_temperatur == 1) { + dht.begin(); //DHT22 //einmal initial messen humidity = dht.readHumidity(); Serial.println(humidity); // Lese Temperatur temperature = dht.readTemperature(); Serial.println(temperature); + } +// -------------------------------- + if (cfg.data_temperatur == 2) { + bme.begin(0x76); //BME280 + temperature = (bme.readTemperature() -1); + Serial.println(temperature); + humidity = bme.readHumidity(); + Serial.println(humidity); + pressureReal = (bme.readPressure() / 100); + Serial.println(pressureReal); + altitude = (cfg.data_height_over_NN); + Serial.println(altitude); + // Berechnung Druck über NN + pressure = pressureReal/pow(1 - altitude/44330.0, 5.255); + Serial.println(pressure); + } +//---------------------------------------- + if (cfg.data_temperatur == 3) { + bmp.begin(0x76); //BMP280 + temperature = (bmp.readTemperature() -1); + Serial.println(temperature); + pressureReal = (bmp.readPressure() / 100); + Serial.println(pressureReal); + altitude = (cfg.data_height_over_NN); + Serial.println(altitude); + // Berechnung Druck über NN + pressure = pressureReal/pow(1 - altitude/44330.0, 5.255); + Serial.println(pressure); + } - //Ausgang D4 + //Ausgang D3 pinMode(relaisPIN, OUTPUT); digitalWrite(relaisPIN,LOW); //Serial.println("LED Test.."); //digitalWrite(relaisPIN,HIGH); - //Ausgang D3 + //Ausgang D4 //pinMode(relais2PIN, OUTPUT); //digitalWrite(relais2PIN,LOW); + + //PIN taster für Backlight als Interupt registrieren + resetBacklightTaster(); + attachInterrupt(digitalPinToInterrupt(taster), enableBacklight, RISING); } @@ -377,9 +471,37 @@ void loop() { Serial.println(temperature); } - //BME Sensor + //BME280 if (cfg.data_temperatur == 2) { - //noch nix zu tun + // Lese Luftfeuchte + humidity = bme.readHumidity(); + Serial.println(humidity); + // Lese Temperatur + temperature = (bme.readTemperature() -1); + Serial.println(temperature); + // Lese Luftdruck + pressureReal = (bme.readPressure() / 100); + Serial.println(pressureReal); + altitude = (cfg.data_height_over_NN); + Serial.println(altitude); + // Berechnung Druck über NN + pressure = pressureReal/pow(1 - altitude/44330.0, 5.255); + Serial.println(pressure); + } + + //BMP280 + if (cfg.data_temperatur == 3) { + // Lese Temperatur + temperature = (bmp.readTemperature() -1); + Serial.println(temperature); + // Lese Luftdruck + pressureReal = (bmp.readPressure() / 100); + Serial.println(pressureReal); + altitude = (cfg.data_height_over_NN); + Serial.println(altitude); + // Berechnung Druck über NN + pressure = pressureReal/pow(1 - altitude/44330.0, 5.255); + Serial.println(pressure); } } } From 0de63fcae770272c37951edee82604860559be75 Mon Sep 17 00:00:00 2001 From: addi-daddi <155233802+addi-daddi@users.noreply.github.com> Date: Tue, 3 Feb 2026 15:51:41 +0100 Subject: [PATCH 2/4] Add files via upload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Veralteten Befehl für ISR korrigiert --- zisterne.ino | 629 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 629 insertions(+) create mode 100644 zisterne.ino diff --git a/zisterne.ino b/zisterne.ino new file mode 100644 index 0000000..c121b9a --- /dev/null +++ b/zisterne.ino @@ -0,0 +1,629 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include //für LCD +#include //für OLED +#include +#include +#include +#include +#include +#include +//#include +#include "myTypes.h" +#include "DHT.h" +//#include "Adafruit_VL53L0X.h" +#include //Pololu-Lib +#include "SparkFun_VL53L1X.h" +#include +#include +#include +#include "Adafruit_BMP280.h" + + +extern "C" { + #include "user_interface.h" +} + +//******************************************************** +// Die Sensoren +//******************************************************** +//HC-SR04 +#define TRIGGER 4 +#define ECHO 5 +#define MAX_DIST 300 + +//VL53L0X +VL53L0X l0x_sensor; + +//VL53L1X +SFEVL53L1X l1x_sensor; + +//ADS1115 +Adafruit_ADS1115 ads; /* Use this for the 16-bit version */ +//Adafruit_ADS1015 ads; /* Use this for the 12-bit version */ +int16_t adc0; + +//******************************************************** +// Variablen für Abstandsmessung +//******************************************************** +int abstand; +int fuellhoehe; +float fuellstand; +float volumen; +int volumen_max; +int var_abstand_sensor_wasser_min = 0; +int var_abstand_sensor_wasser_max = 0; +int dauer; +int rest; +unsigned long currentMillisAbstand; +unsigned long startMillisAbstand; + +//********************* +// Temperatursensor +//********************* +// DHT22 +#define DHTPIN 14 //D5 +#define DHTTYPE DHT22 +DHT dht(DHTPIN, DHTTYPE); +float humidity; +float temperature; +float pressure; +float pressureReal; +float altitude; +unsigned long startMillisTemp; +unsigned long currentMillisTemp; + +//BME280 +Adafruit_BME280 bme; // I2C + +//BMP280 +Adafruit_BMP280 bmp; // I2C + +//******************************************************** +// Konfiguration der Displays +// Deklaration der I2C Adresse, anz.Zeichen, anz.Zeilen +//******************************************************** +SimpleTimer timer; +LiquidCrystal_I2C lcd(0x27, 16, 4); // Konfiguration der LCD-Displays +static uint8_t ucBackBuffer[1025]; // Puffergroeße fuer OLED +SSOLED ssoled; // benoetigt fuer OLED + +//Taster fuer Display +//int sensor = 14; // D5 VCC Sensor +int taster = 15; // D8 für Taster +// int tasterstatus = 0; +int previousMicros = 0; //timer +int displayMicros = 0; //timer +bool backlstatus = false; + +//******************************************************** +// Relais an D4 +//******************************************************** +const int relaisPIN = 2; //D4 HIGH bei Boot +unsigned long startMillisRelais; +unsigned long currentMillisRelais; + +//******************************************************** +// Relais an D3 +//******************************************************** +const int relais2PIN = 0; //D3 +unsigned long startMillisRelais2; +unsigned long currentMillisRelais2; + +//******************************************************** +// Debug-Ausgabe aktivieren (true/false) +//******************************************************** +#define DEBUG true + +//******************************************************** +// Variablen für zeitgesteuerte Aufrufe der eigenen API +//********************************************************+ +unsigned long startMillisEigen; +unsigned long currentMillisEigen; +int eigenapi_anz_aufrufe = 0; +int webapi_anz_aufrufe = 0; + +//******************************************************** +// OTA-Variablen +//******************************************************** +const char* fw_url = "http://www.bubux.de/heimautomatisierung/ota/zisterne/"; +int ota_zeit = 3600; +unsigned long startMillisOta; +unsigned long currentMillisOta; + +//******************************************************** +// MQTT +//******************************************************** +unsigned long startMillisMQTT; +unsigned long currentMillisMQTT; +void callback(char* topic, byte* payload, unsigned int length) { + // Eingehende Nachricht verarbeiten +} + +//******************************************************** +// WEBAPI-Variablen +//******************************************************** +int webapi_zeit = 3600; +unsigned long startMillisWeb; +unsigned long currentMillisWeb; + +//******************************************************** +// Zeit per NTP holen +//******************************************************** +WiFiUDP ntpUDP; +unsigned long currentMillisNTP; +unsigned long startMillisNTP; +const long utcOffsetInSeconds = 7200; +NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds); + +//******************************************************** +// Display variablen +//******************************************************** +unsigned long startMillisDisplay; +unsigned long currentMillisDisplay; +// vgl. https://docs.arduino.cc/language-reference/funktionen/external-interrupts/attachInterrupt/ +volatile bool tasterHigh; + +//******************************************************** +// Grundsätzliche Einstellungen +//******************************************************** +const int fw_version = 1031; +String anwendungsname = "Zisternenfüllstand"; +String apSSID = "WLAN-Zisterne"; +const int cfgStart = 0; +const int setupTimeOutLimit = 300; // Zeit die AP bestehen bleibt. War mal 600, jetzt nur noch 5 Minuten + +ESP8266WebServer server(80); +WiFiClient wifiClient; +Ticker setupTimeOut_timer; // Timer um AP zu resetten +configData_t cfg; + +//Prüfung ob der EEPROM gelöscht werden soll...aktuell nicht genutzt +int eepromToClear = 0; + +//******************************************************** +// Globale Variablen +//******************************************************** +int webtypeGlob; + +uint8_t mac[6]; +String stationList = ""; +int setupTimeOut = 0; // Timeout für AP initialisieren + +String macAdresse; +String ipAdresse; +String myHostname; + +ADC_MODE(ADC_VCC); +uint32_t freeheap = system_get_free_heap_size(); + + +//Fuer die taegliche Ausfuehrung +bool gesendet_pushover = false; +bool gesendet_mail = false; + + +//******************************************************** +// ISR +//******************************************************** +// ICACHE_RAM_ATTR void enableBacklight() { (veraltet) +IRAM_ATTR void enableBacklight() { + tasterHigh = true; +} + +void resetBacklightTaster() { + tasterHigh = false; +} + + + +//******************************************************** +// SETUP +//******************************************************** +void setup() { + Wire.begin(); + + Serial.begin(115200); + delay(1000); + Serial.println("Auf gehts..."); + + //Lade Konfiguration aus EEPROM + ladekonfig(); + + if (cfg.data_sensorname!="") { + Serial.print("Anwendungsname setzen: "); + anwendungsname = cfg.data_sensorname; + Serial.println(anwendungsname); + } + + Serial.print("Sensor auswaehlen: "); + //Serial.print(cfg.data_zisterne_sensor); + Serial.print(" "); + if (cfg.data_zisterne_sensor == 0) { + Serial.println("Kein Sensor ausgewaehlt"); + } + //Anschluss HC SR04 + if (cfg.data_zisterne_sensor == 1) { + Serial.println("HC-SR04 ausgewaehlt"); + pinMode(TRIGGER, OUTPUT); + pinMode(ECHO, INPUT); + pinMode(taster, INPUT); + //pinMode(sensor, OUTPUT); + } + //VL53L0X + if (cfg.data_zisterne_sensor == 2) { + Serial.println("VL53L0X ausgewaehlt"); + + //Pololu + l0x_sensor.init(); + l0x_sensor.setTimeout(500); + + if (cfg.data_distance_mode_vl53l0x == 1) { + Serial.println("Long-Range gesetzt"); + // lower the return signal rate limit (default is 0.25 MCPS) + l0x_sensor.setSignalRateLimit(0.1); + // increase laser pulse periods (defaults are 14 and 10 PCLKs) + l0x_sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18); + l0x_sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14); + } else { + Serial.println("Short-Range gesetzt (default)"); + } + + //High accuracy + if (cfg.data_accuracy_mode_vl53l0x == 1) { + l0x_sensor.setMeasurementTimingBudget(200000); + Serial.println("Timing gesetzt auf High-Accuracy"); + } + //High speed + if (cfg.data_accuracy_mode_vl53l0x == 2) { + l0x_sensor.setMeasurementTimingBudget(20000); + Serial.println("Timing gesetzt auf High-Speed"); + } + //Default + if (cfg.data_accuracy_mode_vl53l0x == 0) { + l0x_sensor.setMeasurementTimingBudget(33000); + Serial.println("Timing gesetzt auf Default"); + } + + + } + //VL53L1X + if (cfg.data_zisterne_sensor == 3) { + Serial.println("VL53L1X ausgewaehlt"); + if (l1x_sensor.begin() == true) + { + Serial.println("Sensor gefunden"); + } + + if (cfg.data_distance_mode_vl53l1x == 0) { + l1x_sensor.setDistanceModeShort(); + Serial.println("Distanzmodus: Short"); + } + if (cfg.data_distance_mode_vl53l1x == 1) { + l1x_sensor.setDistanceModeLong(); + Serial.println("Distanzmodus: Long"); + } + + } + //ADS1115 + if (cfg.data_zisterne_sensor == 4) { + Serial.println("ADS1115 ausgewaehlt"); + // The ADC input range (or gain) can be changed via the following + // functions, but be careful never to exceed VDD +0.3V max, or to + // exceed the upper and lower limits if you adjust the input range! + // Setting these values incorrectly may destroy your ADC! + // ------- ------- + ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default) + // ads.setGain(GAIN_ONE); //1x gain +/- 4.096V 1 bit = 2mV 0.125mV + // ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV 0.0625mV + // ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV + // ads.setGain(GAIN_EIGHT); // 8x gaSerial.println("Single-ended readings from AIN0 with >3.0V comparator"); + // Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)"); + // Serial.println("Comparator Threshold: 1000 (3.000V)");in +/- 0.512V 1 bit = 0.25mV 0.015625mV + // ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV + if (!ads.begin()) { + Serial.println("Failed to initialize ADS."); + while (1); + } + + // Setup 3V comparator on channel 0 + ads.startComparator_SingleEnded(0, 1000); + } + +//----------------------------------------------------------------------------------------- + //Zeit merken um EigenAPI, WebAPI und OTA zeitgesteuert aufzurufen + //auch Intervall zum Refresh von Display und NTP + startMillisEigen = millis(); + startMillisWeb = millis(); + startMillisOta = millis(); + startMillisMQTT = millis(); + startMillisDisplay = millis(); + startMillisNTP = millis(); + startMillisTemp = millis(); + startMillisAbstand = millis(); + + //MAC auslesen und in Variablen schreiben + WiFi.macAddress(mac); + macAdresse = macToStr(mac); + macAdresse.toUpperCase(); + myHostname = macToHostname(mac); + + //Starte WLAN-Verbindung + starteWLAN(); + + //NTP + //NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds); + timeClient.begin(); //Timer starten + timeClient.update(); //Zeit mit NTP updaten + if (DEBUG) Serial.println("Initialales NTP-Update erfolgt"); + + //Starte Display + if ((cfg.data_display == 1) || (cfg.data_display == 2)){ + if (DEBUG) Serial.println("Initialisiere LCD Display"); + ladeLCDdisplay(); + } + if (cfg.data_display == 3) { + if (DEBUG) Serial.println("Initialisiere OLED Display"); + ladeOLEDdisplay(); + } + + //Starte Temperaturmessung + if (cfg.data_temperatur == 1) { + dht.begin(); //DHT22 + //einmal initial messen + humidity = dht.readHumidity(); + Serial.println(humidity); + // Lese Temperatur + temperature = dht.readTemperature(); + Serial.println(temperature); + } +// -------------------------------- + if (cfg.data_temperatur == 2) { + bme.begin(0x76); //BME280 + temperature = (bme.readTemperature() -1); + Serial.println(temperature); + humidity = bme.readHumidity(); + Serial.println(humidity); + pressureReal = (bme.readPressure() / 100); + Serial.println(pressureReal); + altitude = (cfg.data_height_over_NN); + Serial.println(altitude); + // Berechnung Druck über NN + pressure = pressureReal/pow(1 - altitude/44330.0, 5.255); + Serial.println(pressure); + } +//---------------------------------------- + if (cfg.data_temperatur == 3) { + bmp.begin(0x76); //BMP280 + temperature = (bmp.readTemperature() -1); + Serial.println(temperature); + pressureReal = (bmp.readPressure() / 100); + Serial.println(pressureReal); + altitude = (cfg.data_height_over_NN); + Serial.println(altitude); + // Berechnung Druck über NN + pressure = pressureReal/pow(1 - altitude/44330.0, 5.255); + Serial.println(pressure); + } + + //Ausgang D3 + pinMode(relaisPIN, OUTPUT); + digitalWrite(relaisPIN,LOW); + //Serial.println("LED Test.."); + //digitalWrite(relaisPIN,HIGH); + + //Ausgang D4 + //pinMode(relais2PIN, OUTPUT); + //digitalWrite(relais2PIN,LOW); + + //PIN taster für Backlight als Interupt registrieren + resetBacklightTaster(); + attachInterrupt(digitalPinToInterrupt(taster), enableBacklight, RISING); + +} + +//******************************************************** +// LOOP +//******************************************************** +void loop() { + + //********************** + //Status für Sensorpower + //********************** + //if (cfg.data_senson == 1) { + // digitalWrite(sensor, HIGH); + //} + //else { + // digitalWrite (sensor, LOW); + //} + + //******************** + //Sensordaten auslesen + //******************** + //alle 2 Sekunden Abstand messen + currentMillisAbstand = millis(); + if (currentMillisAbstand - startMillisAbstand >= 2000) { + startMillisAbstand = currentMillisAbstand; + looprechnen(); + } + + //Temperatursensor + if (cfg.data_temperatur_enable == 1) { + + //alle 60 Sekunden Temperatur messen + currentMillisTemp = millis(); + if (currentMillisTemp - startMillisTemp >= 60000) { + startMillisTemp = currentMillisTemp; + Serial.println("Temperaturmessung"); + + //DHT Sensor + if (cfg.data_temperatur == 1) { + // Lese Luftfeuchte + humidity = dht.readHumidity(); + Serial.println(humidity); + // Lese Temperatur + temperature = dht.readTemperature(); + Serial.println(temperature); + } + + //BME280 + if (cfg.data_temperatur == 2) { + // Lese Luftfeuchte + humidity = bme.readHumidity(); + Serial.println(humidity); + // Lese Temperatur + temperature = (bme.readTemperature() -1); + Serial.println(temperature); + // Lese Luftdruck + pressureReal = (bme.readPressure() / 100); + Serial.println(pressureReal); + altitude = (cfg.data_height_over_NN); + Serial.println(altitude); + // Berechnung Druck über NN + pressure = pressureReal/pow(1 - altitude/44330.0, 5.255); + Serial.println(pressure); + } + + //BMP280 + if (cfg.data_temperatur == 3) { + // Lese Temperatur + temperature = (bmp.readTemperature() -1); + Serial.println(temperature); + // Lese Luftdruck + pressureReal = (bmp.readPressure() / 100); + Serial.println(pressureReal); + altitude = (cfg.data_height_over_NN); + Serial.println(altitude); + // Berechnung Druck über NN + pressure = pressureReal/pow(1 - altitude/44330.0, 5.255); + Serial.println(pressure); + } + } + } + + //***************************** + //Daten an eigene API übergeben + //***************************** + if (cfg.data_eigenapi_check == 1) { + eigene_api(); + } + + //************************** + //Daten an Web API übergeben + //************************** + if (cfg.data_webapi_check == 1) { + web_api(); + } + + //************************** + //Relais ggf. schalten + //************************** + if (cfg.data_relais_enable == 1) { + relais(); + } + + //************************** + //Relais2 ggf. schalten + //************************** + //if (cfg.data_relais2_enable == 1) { + // relais2(); + //} + + //************************** + //Display setzen + //************************** + if ((cfg.data_display == 1) && (cfg.data_display_enable == 1)) { + loop1602(); + } + + if ((cfg.data_display == 2) && (cfg.data_display_enable == 1)) { + loop1604(); + } + + if ((cfg.data_display == 3) && (cfg.data_display_enable == 1)) { + loopOLED(); + } + + //************************** + //OTA-Update prüfen + //************************** + if (cfg.data_ota_check == 1) { + checkForUpdates(); + } + + //************************** + //MQTT + //************************** + if (cfg.data_mqtt_check == 1) { + mqtt_api(); + } + + if (eepromToClear == 1) { + if (DEBUG) Serial.println("Flag zur Löschung des EEPROM gesetzt!"); + eraseConfig(); + delay(1000); + eepromToClear = 0; + system_restart(); + } + + //****************** + //WLAN-Status prüfen + //****************** + if (WiFi.status() == WL_CONNECTED || webtypeGlob == 1) { + server.handleClient(); + delay(10); + } else { + if (DEBUG) Serial.println("WLAN nicht verbunden"); + delay(1000); + starteWLAN(); + } + + //****************** + //NTP + //****************** + currentMillisNTP = millis(); + //Alle 30 Minuten refreshen + if (currentMillisNTP - startMillisNTP >= (1800 * 1000)) { + startMillisNTP = currentMillisNTP; + timeClient.update(); + if (DEBUG) Serial.println("NTP-Update erfolgt"); + } + + //******************************************** + //Taegliche Ausfuehrung zur gewaehlten Uhrzeit + //******************************************** + if (cfg.data_pushover_check == 1) { + if (timeClient.getHours() == cfg.data_pushover_zeit && gesendet_pushover==false) { + Pushover pushover = Pushover(cfg.data_pushover_apptoken,cfg.data_pushover_usertoken, UNSAFE); + pushover.setTitle("Zisterne"); + pushover.setMessage("Füllstand um " +(timeClient.getFormattedTime()) + " Uhr " + String(fuellstand) + "%25"); + if (DEBUG) Serial.println("Pushover-Nachricht gesendet"); + Serial.println(pushover.send()); + delay(300); + gesendet_pushover=true; + } + if (timeClient.getHours() != cfg.data_pushover_zeit) { + gesendet_pushover=false; + } + } + +// if (cfg.data_mail_check == 1) { +// if (timeClient.getFormattedTime().substring(0,2) == (String)cfg.data_mail_zeit && gesendet_mail==false) { +// //Testweise +// SendEmail e("mailserver", 587, "benutzer", "passwort", 5000, true); +// e.send("", "", "Zisterne", "Testmail von der Zisterne"); +// gesendet_mail=true; +// } +// +// if (timeClient.getFormattedTime().substring(0,2) != (String)cfg.data_mail_zeit) { +// gesendet_mail=false; +// } +// } + +} From 713cbc4ecb19d219b8cb9331e41da070f6cee83e Mon Sep 17 00:00:00 2001 From: addi-daddi <155233802+addi-daddi@users.noreply.github.com> Date: Tue, 3 Feb 2026 15:57:29 +0100 Subject: [PATCH 3/4] Delete zisterne.ino --- zisterne.ino | 629 --------------------------------------------------- 1 file changed, 629 deletions(-) delete mode 100644 zisterne.ino diff --git a/zisterne.ino b/zisterne.ino deleted file mode 100644 index c121b9a..0000000 --- a/zisterne.ino +++ /dev/null @@ -1,629 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include //für LCD -#include //für OLED -#include -#include -#include -#include -#include -#include -//#include -#include "myTypes.h" -#include "DHT.h" -//#include "Adafruit_VL53L0X.h" -#include //Pololu-Lib -#include "SparkFun_VL53L1X.h" -#include -#include -#include -#include "Adafruit_BMP280.h" - - -extern "C" { - #include "user_interface.h" -} - -//******************************************************** -// Die Sensoren -//******************************************************** -//HC-SR04 -#define TRIGGER 4 -#define ECHO 5 -#define MAX_DIST 300 - -//VL53L0X -VL53L0X l0x_sensor; - -//VL53L1X -SFEVL53L1X l1x_sensor; - -//ADS1115 -Adafruit_ADS1115 ads; /* Use this for the 16-bit version */ -//Adafruit_ADS1015 ads; /* Use this for the 12-bit version */ -int16_t adc0; - -//******************************************************** -// Variablen für Abstandsmessung -//******************************************************** -int abstand; -int fuellhoehe; -float fuellstand; -float volumen; -int volumen_max; -int var_abstand_sensor_wasser_min = 0; -int var_abstand_sensor_wasser_max = 0; -int dauer; -int rest; -unsigned long currentMillisAbstand; -unsigned long startMillisAbstand; - -//********************* -// Temperatursensor -//********************* -// DHT22 -#define DHTPIN 14 //D5 -#define DHTTYPE DHT22 -DHT dht(DHTPIN, DHTTYPE); -float humidity; -float temperature; -float pressure; -float pressureReal; -float altitude; -unsigned long startMillisTemp; -unsigned long currentMillisTemp; - -//BME280 -Adafruit_BME280 bme; // I2C - -//BMP280 -Adafruit_BMP280 bmp; // I2C - -//******************************************************** -// Konfiguration der Displays -// Deklaration der I2C Adresse, anz.Zeichen, anz.Zeilen -//******************************************************** -SimpleTimer timer; -LiquidCrystal_I2C lcd(0x27, 16, 4); // Konfiguration der LCD-Displays -static uint8_t ucBackBuffer[1025]; // Puffergroeße fuer OLED -SSOLED ssoled; // benoetigt fuer OLED - -//Taster fuer Display -//int sensor = 14; // D5 VCC Sensor -int taster = 15; // D8 für Taster -// int tasterstatus = 0; -int previousMicros = 0; //timer -int displayMicros = 0; //timer -bool backlstatus = false; - -//******************************************************** -// Relais an D4 -//******************************************************** -const int relaisPIN = 2; //D4 HIGH bei Boot -unsigned long startMillisRelais; -unsigned long currentMillisRelais; - -//******************************************************** -// Relais an D3 -//******************************************************** -const int relais2PIN = 0; //D3 -unsigned long startMillisRelais2; -unsigned long currentMillisRelais2; - -//******************************************************** -// Debug-Ausgabe aktivieren (true/false) -//******************************************************** -#define DEBUG true - -//******************************************************** -// Variablen für zeitgesteuerte Aufrufe der eigenen API -//********************************************************+ -unsigned long startMillisEigen; -unsigned long currentMillisEigen; -int eigenapi_anz_aufrufe = 0; -int webapi_anz_aufrufe = 0; - -//******************************************************** -// OTA-Variablen -//******************************************************** -const char* fw_url = "http://www.bubux.de/heimautomatisierung/ota/zisterne/"; -int ota_zeit = 3600; -unsigned long startMillisOta; -unsigned long currentMillisOta; - -//******************************************************** -// MQTT -//******************************************************** -unsigned long startMillisMQTT; -unsigned long currentMillisMQTT; -void callback(char* topic, byte* payload, unsigned int length) { - // Eingehende Nachricht verarbeiten -} - -//******************************************************** -// WEBAPI-Variablen -//******************************************************** -int webapi_zeit = 3600; -unsigned long startMillisWeb; -unsigned long currentMillisWeb; - -//******************************************************** -// Zeit per NTP holen -//******************************************************** -WiFiUDP ntpUDP; -unsigned long currentMillisNTP; -unsigned long startMillisNTP; -const long utcOffsetInSeconds = 7200; -NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds); - -//******************************************************** -// Display variablen -//******************************************************** -unsigned long startMillisDisplay; -unsigned long currentMillisDisplay; -// vgl. https://docs.arduino.cc/language-reference/funktionen/external-interrupts/attachInterrupt/ -volatile bool tasterHigh; - -//******************************************************** -// Grundsätzliche Einstellungen -//******************************************************** -const int fw_version = 1031; -String anwendungsname = "Zisternenfüllstand"; -String apSSID = "WLAN-Zisterne"; -const int cfgStart = 0; -const int setupTimeOutLimit = 300; // Zeit die AP bestehen bleibt. War mal 600, jetzt nur noch 5 Minuten - -ESP8266WebServer server(80); -WiFiClient wifiClient; -Ticker setupTimeOut_timer; // Timer um AP zu resetten -configData_t cfg; - -//Prüfung ob der EEPROM gelöscht werden soll...aktuell nicht genutzt -int eepromToClear = 0; - -//******************************************************** -// Globale Variablen -//******************************************************** -int webtypeGlob; - -uint8_t mac[6]; -String stationList = ""; -int setupTimeOut = 0; // Timeout für AP initialisieren - -String macAdresse; -String ipAdresse; -String myHostname; - -ADC_MODE(ADC_VCC); -uint32_t freeheap = system_get_free_heap_size(); - - -//Fuer die taegliche Ausfuehrung -bool gesendet_pushover = false; -bool gesendet_mail = false; - - -//******************************************************** -// ISR -//******************************************************** -// ICACHE_RAM_ATTR void enableBacklight() { (veraltet) -IRAM_ATTR void enableBacklight() { - tasterHigh = true; -} - -void resetBacklightTaster() { - tasterHigh = false; -} - - - -//******************************************************** -// SETUP -//******************************************************** -void setup() { - Wire.begin(); - - Serial.begin(115200); - delay(1000); - Serial.println("Auf gehts..."); - - //Lade Konfiguration aus EEPROM - ladekonfig(); - - if (cfg.data_sensorname!="") { - Serial.print("Anwendungsname setzen: "); - anwendungsname = cfg.data_sensorname; - Serial.println(anwendungsname); - } - - Serial.print("Sensor auswaehlen: "); - //Serial.print(cfg.data_zisterne_sensor); - Serial.print(" "); - if (cfg.data_zisterne_sensor == 0) { - Serial.println("Kein Sensor ausgewaehlt"); - } - //Anschluss HC SR04 - if (cfg.data_zisterne_sensor == 1) { - Serial.println("HC-SR04 ausgewaehlt"); - pinMode(TRIGGER, OUTPUT); - pinMode(ECHO, INPUT); - pinMode(taster, INPUT); - //pinMode(sensor, OUTPUT); - } - //VL53L0X - if (cfg.data_zisterne_sensor == 2) { - Serial.println("VL53L0X ausgewaehlt"); - - //Pololu - l0x_sensor.init(); - l0x_sensor.setTimeout(500); - - if (cfg.data_distance_mode_vl53l0x == 1) { - Serial.println("Long-Range gesetzt"); - // lower the return signal rate limit (default is 0.25 MCPS) - l0x_sensor.setSignalRateLimit(0.1); - // increase laser pulse periods (defaults are 14 and 10 PCLKs) - l0x_sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18); - l0x_sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14); - } else { - Serial.println("Short-Range gesetzt (default)"); - } - - //High accuracy - if (cfg.data_accuracy_mode_vl53l0x == 1) { - l0x_sensor.setMeasurementTimingBudget(200000); - Serial.println("Timing gesetzt auf High-Accuracy"); - } - //High speed - if (cfg.data_accuracy_mode_vl53l0x == 2) { - l0x_sensor.setMeasurementTimingBudget(20000); - Serial.println("Timing gesetzt auf High-Speed"); - } - //Default - if (cfg.data_accuracy_mode_vl53l0x == 0) { - l0x_sensor.setMeasurementTimingBudget(33000); - Serial.println("Timing gesetzt auf Default"); - } - - - } - //VL53L1X - if (cfg.data_zisterne_sensor == 3) { - Serial.println("VL53L1X ausgewaehlt"); - if (l1x_sensor.begin() == true) - { - Serial.println("Sensor gefunden"); - } - - if (cfg.data_distance_mode_vl53l1x == 0) { - l1x_sensor.setDistanceModeShort(); - Serial.println("Distanzmodus: Short"); - } - if (cfg.data_distance_mode_vl53l1x == 1) { - l1x_sensor.setDistanceModeLong(); - Serial.println("Distanzmodus: Long"); - } - - } - //ADS1115 - if (cfg.data_zisterne_sensor == 4) { - Serial.println("ADS1115 ausgewaehlt"); - // The ADC input range (or gain) can be changed via the following - // functions, but be careful never to exceed VDD +0.3V max, or to - // exceed the upper and lower limits if you adjust the input range! - // Setting these values incorrectly may destroy your ADC! - // ------- ------- - ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default) - // ads.setGain(GAIN_ONE); //1x gain +/- 4.096V 1 bit = 2mV 0.125mV - // ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV 0.0625mV - // ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV - // ads.setGain(GAIN_EIGHT); // 8x gaSerial.println("Single-ended readings from AIN0 with >3.0V comparator"); - // Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)"); - // Serial.println("Comparator Threshold: 1000 (3.000V)");in +/- 0.512V 1 bit = 0.25mV 0.015625mV - // ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV - if (!ads.begin()) { - Serial.println("Failed to initialize ADS."); - while (1); - } - - // Setup 3V comparator on channel 0 - ads.startComparator_SingleEnded(0, 1000); - } - -//----------------------------------------------------------------------------------------- - //Zeit merken um EigenAPI, WebAPI und OTA zeitgesteuert aufzurufen - //auch Intervall zum Refresh von Display und NTP - startMillisEigen = millis(); - startMillisWeb = millis(); - startMillisOta = millis(); - startMillisMQTT = millis(); - startMillisDisplay = millis(); - startMillisNTP = millis(); - startMillisTemp = millis(); - startMillisAbstand = millis(); - - //MAC auslesen und in Variablen schreiben - WiFi.macAddress(mac); - macAdresse = macToStr(mac); - macAdresse.toUpperCase(); - myHostname = macToHostname(mac); - - //Starte WLAN-Verbindung - starteWLAN(); - - //NTP - //NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds); - timeClient.begin(); //Timer starten - timeClient.update(); //Zeit mit NTP updaten - if (DEBUG) Serial.println("Initialales NTP-Update erfolgt"); - - //Starte Display - if ((cfg.data_display == 1) || (cfg.data_display == 2)){ - if (DEBUG) Serial.println("Initialisiere LCD Display"); - ladeLCDdisplay(); - } - if (cfg.data_display == 3) { - if (DEBUG) Serial.println("Initialisiere OLED Display"); - ladeOLEDdisplay(); - } - - //Starte Temperaturmessung - if (cfg.data_temperatur == 1) { - dht.begin(); //DHT22 - //einmal initial messen - humidity = dht.readHumidity(); - Serial.println(humidity); - // Lese Temperatur - temperature = dht.readTemperature(); - Serial.println(temperature); - } -// -------------------------------- - if (cfg.data_temperatur == 2) { - bme.begin(0x76); //BME280 - temperature = (bme.readTemperature() -1); - Serial.println(temperature); - humidity = bme.readHumidity(); - Serial.println(humidity); - pressureReal = (bme.readPressure() / 100); - Serial.println(pressureReal); - altitude = (cfg.data_height_over_NN); - Serial.println(altitude); - // Berechnung Druck über NN - pressure = pressureReal/pow(1 - altitude/44330.0, 5.255); - Serial.println(pressure); - } -//---------------------------------------- - if (cfg.data_temperatur == 3) { - bmp.begin(0x76); //BMP280 - temperature = (bmp.readTemperature() -1); - Serial.println(temperature); - pressureReal = (bmp.readPressure() / 100); - Serial.println(pressureReal); - altitude = (cfg.data_height_over_NN); - Serial.println(altitude); - // Berechnung Druck über NN - pressure = pressureReal/pow(1 - altitude/44330.0, 5.255); - Serial.println(pressure); - } - - //Ausgang D3 - pinMode(relaisPIN, OUTPUT); - digitalWrite(relaisPIN,LOW); - //Serial.println("LED Test.."); - //digitalWrite(relaisPIN,HIGH); - - //Ausgang D4 - //pinMode(relais2PIN, OUTPUT); - //digitalWrite(relais2PIN,LOW); - - //PIN taster für Backlight als Interupt registrieren - resetBacklightTaster(); - attachInterrupt(digitalPinToInterrupt(taster), enableBacklight, RISING); - -} - -//******************************************************** -// LOOP -//******************************************************** -void loop() { - - //********************** - //Status für Sensorpower - //********************** - //if (cfg.data_senson == 1) { - // digitalWrite(sensor, HIGH); - //} - //else { - // digitalWrite (sensor, LOW); - //} - - //******************** - //Sensordaten auslesen - //******************** - //alle 2 Sekunden Abstand messen - currentMillisAbstand = millis(); - if (currentMillisAbstand - startMillisAbstand >= 2000) { - startMillisAbstand = currentMillisAbstand; - looprechnen(); - } - - //Temperatursensor - if (cfg.data_temperatur_enable == 1) { - - //alle 60 Sekunden Temperatur messen - currentMillisTemp = millis(); - if (currentMillisTemp - startMillisTemp >= 60000) { - startMillisTemp = currentMillisTemp; - Serial.println("Temperaturmessung"); - - //DHT Sensor - if (cfg.data_temperatur == 1) { - // Lese Luftfeuchte - humidity = dht.readHumidity(); - Serial.println(humidity); - // Lese Temperatur - temperature = dht.readTemperature(); - Serial.println(temperature); - } - - //BME280 - if (cfg.data_temperatur == 2) { - // Lese Luftfeuchte - humidity = bme.readHumidity(); - Serial.println(humidity); - // Lese Temperatur - temperature = (bme.readTemperature() -1); - Serial.println(temperature); - // Lese Luftdruck - pressureReal = (bme.readPressure() / 100); - Serial.println(pressureReal); - altitude = (cfg.data_height_over_NN); - Serial.println(altitude); - // Berechnung Druck über NN - pressure = pressureReal/pow(1 - altitude/44330.0, 5.255); - Serial.println(pressure); - } - - //BMP280 - if (cfg.data_temperatur == 3) { - // Lese Temperatur - temperature = (bmp.readTemperature() -1); - Serial.println(temperature); - // Lese Luftdruck - pressureReal = (bmp.readPressure() / 100); - Serial.println(pressureReal); - altitude = (cfg.data_height_over_NN); - Serial.println(altitude); - // Berechnung Druck über NN - pressure = pressureReal/pow(1 - altitude/44330.0, 5.255); - Serial.println(pressure); - } - } - } - - //***************************** - //Daten an eigene API übergeben - //***************************** - if (cfg.data_eigenapi_check == 1) { - eigene_api(); - } - - //************************** - //Daten an Web API übergeben - //************************** - if (cfg.data_webapi_check == 1) { - web_api(); - } - - //************************** - //Relais ggf. schalten - //************************** - if (cfg.data_relais_enable == 1) { - relais(); - } - - //************************** - //Relais2 ggf. schalten - //************************** - //if (cfg.data_relais2_enable == 1) { - // relais2(); - //} - - //************************** - //Display setzen - //************************** - if ((cfg.data_display == 1) && (cfg.data_display_enable == 1)) { - loop1602(); - } - - if ((cfg.data_display == 2) && (cfg.data_display_enable == 1)) { - loop1604(); - } - - if ((cfg.data_display == 3) && (cfg.data_display_enable == 1)) { - loopOLED(); - } - - //************************** - //OTA-Update prüfen - //************************** - if (cfg.data_ota_check == 1) { - checkForUpdates(); - } - - //************************** - //MQTT - //************************** - if (cfg.data_mqtt_check == 1) { - mqtt_api(); - } - - if (eepromToClear == 1) { - if (DEBUG) Serial.println("Flag zur Löschung des EEPROM gesetzt!"); - eraseConfig(); - delay(1000); - eepromToClear = 0; - system_restart(); - } - - //****************** - //WLAN-Status prüfen - //****************** - if (WiFi.status() == WL_CONNECTED || webtypeGlob == 1) { - server.handleClient(); - delay(10); - } else { - if (DEBUG) Serial.println("WLAN nicht verbunden"); - delay(1000); - starteWLAN(); - } - - //****************** - //NTP - //****************** - currentMillisNTP = millis(); - //Alle 30 Minuten refreshen - if (currentMillisNTP - startMillisNTP >= (1800 * 1000)) { - startMillisNTP = currentMillisNTP; - timeClient.update(); - if (DEBUG) Serial.println("NTP-Update erfolgt"); - } - - //******************************************** - //Taegliche Ausfuehrung zur gewaehlten Uhrzeit - //******************************************** - if (cfg.data_pushover_check == 1) { - if (timeClient.getHours() == cfg.data_pushover_zeit && gesendet_pushover==false) { - Pushover pushover = Pushover(cfg.data_pushover_apptoken,cfg.data_pushover_usertoken, UNSAFE); - pushover.setTitle("Zisterne"); - pushover.setMessage("Füllstand um " +(timeClient.getFormattedTime()) + " Uhr " + String(fuellstand) + "%25"); - if (DEBUG) Serial.println("Pushover-Nachricht gesendet"); - Serial.println(pushover.send()); - delay(300); - gesendet_pushover=true; - } - if (timeClient.getHours() != cfg.data_pushover_zeit) { - gesendet_pushover=false; - } - } - -// if (cfg.data_mail_check == 1) { -// if (timeClient.getFormattedTime().substring(0,2) == (String)cfg.data_mail_zeit && gesendet_mail==false) { -// //Testweise -// SendEmail e("mailserver", 587, "benutzer", "passwort", 5000, true); -// e.send("", "", "Zisterne", "Testmail von der Zisterne"); -// gesendet_mail=true; -// } -// -// if (timeClient.getFormattedTime().substring(0,2) != (String)cfg.data_mail_zeit) { -// gesendet_mail=false; -// } -// } - -} From e3ebf779dab16cd4b9b3eddb0b6de0408a7564bb Mon Sep 17 00:00:00 2001 From: addi-daddi <155233802+addi-daddi@users.noreply.github.com> Date: Tue, 3 Feb 2026 15:59:04 +0100 Subject: [PATCH 4/4] Add files via upload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Befehl für IRS korrigiert --- zisterne/zisterne.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zisterne/zisterne.ino b/zisterne/zisterne.ino index c264f68..c121b9a 100644 --- a/zisterne/zisterne.ino +++ b/zisterne/zisterne.ino @@ -212,7 +212,8 @@ bool gesendet_mail = false; //******************************************************** // ISR //******************************************************** -ICACHE_RAM_ATTR void enableBacklight() { +// ICACHE_RAM_ATTR void enableBacklight() { (veraltet) +IRAM_ATTR void enableBacklight() { tasterHigh = true; }