//ESP32_Taupunkt_watchdog_RTC
#include <EEPROM.h>
#include "conf.h"
#include "serialcmd.h"
#include "SDlog.h" //SDlog.h für ESP32 Loggen von Daten
//warning
//If you are trying to read this sensor from the ESP32, use the "DHT sensor library for ESPx" library.
//Other DHT22 libraries may not work reliably on the ESP32. You can use this example project as a starting point.
// Dieser Code benötigt zwingend die folgenden Libraries:
//#include "DHTesp.h" //Funktionierr in Wokwi nicht!!!
#include "DHT.h"
#include <Wire.h>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiWire.h"
#define I2C_ADDRESS 0x3C
SSD1306AsciiWire oled;
#include "esp_system.h"
#include "rom/ets_sys.h"
//RTC
//Aus RtcDS1307_Test01a
//https://wolles-elektronikkiste.de/ds1302-und-ds1307-rtc-real-time-clock
//RTC
//#include <Wire.h> oben schon geschehen
#include "RtcDS1307.h"
//TP
const int wdtTimeout = 20000; //3000; //20Sek. Sollte deutlich groeser sein als delayMessen. time in ms to trigger the watchdog
hw_timer_t *timer = NULL;
//DHTesp dht1; //DHT22 mit ESPx //Funktioniert in Wokwi nicht!!!
//DHTesp dht2; //DHT22 mit ESPx
DHT dht1(DHTPIN_1, DHTTYPE_1); //Der Innensensor wird ab jetzt mit dht1 angesprochen
DHT dht2(DHTPIN_2, DHTTYPE_2); //Der Außensensor wird ab jetzt mit dht2 angesprochen
bool fehler = true;
//RTC
RtcDS1307<TwoWire> rtc(Wire);
void setup() {
timer = timerBegin(1000000); //timer 1Mhz resolution
timerAttachInterrupt(timer, &resetModule); //attach callback
timerAlarm(timer, wdtTimeout * 1000, false, 0); //set time in us
pinMode(RELAIPIN, OUTPUT); // Relaispin als Output definieren
digitalWrite(RELAIPIN, RELAIS_AUS); // Relais ausschalten
pinMode(27, INPUT_PULLUP); //RXD Pullup
Serial.begin(9600); // Serielle Ausgabe, falls noch kein LCD angeschlossen ist
Serial.println(VERSION_ID);
Serial.println(F("Teste Sensoren.."));
//OLED setup
Wire.begin();
Wire.setClock(400000L); //modifies the clock frequency for I2C communication
oled.begin(&SH1106_128x64, I2C_ADDRESS);
//oled.begin(&SH1106_128x64, CS_PIN, DC_PIN, RST_PIN);
//oled.begin(&Adafruit128x64, I2C_ADDRESS);
//dht1.setup(DHTPIN_1, DHTesp::DHT22); //DHT Sensoren ESPx starten //Funktioniert in Wokwi nicht!!!
//dht1.setup(DHTPIN_2, DHTesp::DHT22); //DHT Sensoren ESPx starten
dht1.begin(); // Sensoren starten
dht2.begin();
//Getestetet Fonts
//oled.setFont(Wendy3x5); //sehr klein
//oled.setFont(newbasic3x5); //sehr klein
oled.setFont(Iain5x7); //Sehr schmal Mehrere Leerzeichen einfuegen bei Bedarf
//oled.setFont(Stang5x7); //breit
//oled.setFont(SystemFont5x7); // Mit ° Auswahl der Schriftart
//oled.setFont(lcd5x7); //breit
//oled.setFont(font5x7); //breit
//oled.setFont(lcd5x7); //breit
//oled.setFont(System5x7); // Mit ° Auswahl der Schriftart
//oled.setFont(Adafruit5x7);
//RTC
rtc.Begin();
RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
Serial.println("Compile Time:");
DateTime(compiled);
Serial.println();
if (!rtc.IsDateTimeValid()) {
if (rtc.LastError() != 0)
{
// we have a communications error
// see https://www.arduino.cc/en/Reference/WireEndTransmission for
// what the number means
Serial.print("RTC communications error = ");
Serial.println(rtc.LastError());
}
else
{
// Common Causes:
// 1) first time you ran and the device wasn't running yet
// 2) the battery on the device is low or even missing
Serial.println("RTC lost confidence in the DateTime!");
// following line sets the RTC to the date & time this sketch was compiled
// it will also reset the valid flag internally unless the Rtc device is
// having an issue
rtc.SetDateTime(compiled);
}
}
if(!rtc.GetIsRunning()) {
Serial.println("RTC was not actively running, starting now");
rtc.SetIsRunning(true);
}
RtcDateTime now = rtc.GetDateTime();
if (now < compiled)
{
Serial.println("RTC is older than compile time! (Updating DateTime)");
rtc.SetDateTime(compiled);
}
else if (now > compiled)
{
Serial.println("RTC is newer than compile time. (this is expected)");
}
else if (now == compiled)
{
Serial.println("RTC is the same as compile time! (not expected but all is fine)");
}
//Folgende Zeile später durch Abfrage usw. ersetzen
//Serial.println("Enter the new time as hh:mm:ss");
//SDlog.h
Serial.print("SDinit Rueckgabe: ");
//Serial.println(SDinit(SDFileNameGlobal, SDDatenGlobal)); //SD Karte initialisieren und File prüfen
SDStatusGlobal = SDinit(SDFileNameGlobal, SDDatenGlobal);
Serial.println(SDStatusGlobal);
}
//--------------------------------------------------------------------------------------
void loop() {
// regulär || millis() Sprung auf 0
if (millis() - milDispLast >= delayMessen || millis() < milDispLast){
milDispLast = millis(); //Letzte Ausführung auf aktuelle Zeit setzen
FanContDisp();
}
// regulär || millis() Sprung auf 0
if (millis() - milLogLast >= delayLog || millis() < milLogLast){
milLogLast = millis(); //Letzte Ausführung auf aktuelle Zeit setzen
//Serial.println("------------");
//Serial.println("Jetzt loggen");
//Serial.println("------------");
if(log_serial==1) {
Serial.println(LogToSD());
} else {
int i = LogToSD();
}
}
ser(); // auswertung Serialschnittstelle
ser_log(); //Logausgabe, wenn l1
//delay(500);
delay(10); // this speeds up the simulation
//Hier sonstiger code zwischen den Messungen und der Anzeige
timerWrite(timer, 0); //reset timer (feed watchdog)
}
//Ende Loop ------------------------------------------------------------------------------
//Hauptprogramm Lüftersteuerung + Ausgabe auf Display
int FanContDisp(){
//Auchtung noch auf ESPx ändern!!!
//TempAndHumidity data = dhtSensor.getTempAndHumidity();
//Serial.println("Temp: " + String(data.temperature, 2) + "°C");
//Serial.println("Humidity: " + String(data.humidity, 1) + "%");
//Funktioniert nicht in Wokwi!!!
/*
delay(1000);
TempAndHumidity data1 = dht1.getTempAndHumidity();
delay(1000);
float t1 = data1.temperature + Korrektur_h_1;
delay(1000);
float h1 = data1.humidity + Korrektur_h_1;
delay(1000);
TempAndHumidity data2 = dht2.getTempAndHumidity();
delay(1000);
float t2 = data2.temperature + Korrektur_h_1;
delay(1000);
float h2 = data2.humidity + Korrektur_h_1;
delay(1000);
*/
float h1 = dht1.readHumidity()+Korrektur_h_1; // Innenluftfeuchtigkeit auslesen und unter „h1“ speichern
float t1 = dht1.readTemperature()+ Korrektur_t_1; // Innentemperatur auslesen und unter „t1“ speichern
float h2 = dht2.readHumidity()+Korrektur_h_2; // Außenluftfeuchtigkeit auslesen und unter „h2“ speichern
float t2 = dht2.readTemperature()+ Korrektur_t_2; // Außentemperatur auslesen und unter „t2“ speichern
//RTC Abfrage direkt nach Abfrage der Sensoren
RtcDateTime now = rtc.GetDateTime(); //now Zeit jetzt gesetzt
/* //Test Sensorfehler
Serial.print("isnan(h1) ");
Serial.println(isnan(h1));
Serial.print("isnan(t1) ");
Serial.println(isnan(t1));
Serial.print("isnan(h2) ");
Serial.println(isnan(h2));
Serial.print("isnan(t2) ");
Serial.println(isnan(t2));
delay(500);
*/
if (fehler == true) // Prüfen, ob gültige Werte von den Sensoren kommen
{
fehler = false;
if (isnan(h1) || isnan(t1) || h1 > 100 || h1 < 1 || t1 < -40 || t1 > 80 ) {
Serial.println(F("Fehler beim Auslesen vom 1. Sensor!"));
oled.clear(); //Löschen der aktuellen Displayanzeige
oled.println("Fehler Sensor 1"); //Text in der ersten Zeile. "Println" sorgt dabei für einen Zeilensprung.
fehler = true;
}else {
oled.clear(); //Löschen der aktuellen Displayanzeige
oled.println(F("Sensor 1 in Ordnung"));
}
//delay(delayDisplay); // Zeit um das Display zu lesen
if (isnan(h2) || isnan(t2) || h2 > 100 || h2 < 1 || t2 < -40 || t2 > 80) {
Serial.println(F("Fehler beim Auslesen vom 2. Sensor!"));
//oled.clear(); //Löschen der aktuellen Displayanzeige
oled.println("Fehler Sensor 2"); //Text in der ersten Zeile. "Println" sorgt dabei für einen Zeilensprung.
fehler = true;
} else {
oled.println(F("Sensor 2 in Ordnung"));
}
delay(delayDisplay); // Zeit um das Display zu lesen
}
if (isnan(h1) || isnan(t1) || isnan(h2) || isnan(t2)) fehler = true;
//Neustart bei Fehlerverhindern
if (fehler == true) {
digitalWrite(RELAIPIN, RELAIS_AUS); // Relais ausschalten
oled.clear(); //Löschen der aktuellen Displayanzeige
oled.println("CPU Neustart....."); //Text in der ersten Zeile. "Println" sorgt dabei für einen Zeilensprung.
while (1); // Endlosschleife um das Display zu lesen und die CPU durch den Watchdog neu zu starten
}
timerWrite(timer, 0); //reset timer (feed watchdog)
//**** Taupunkte errechnen********
float Taupunkt_1 = taupunkt(t1, h1);
float Taupunkt_2 = taupunkt(t2, h2);
//Taupunktunterschied berechnen und min. max. prüfen/setzen
float DeltaTP = Taupunkt_1 - Taupunkt_2;
//Braucht man die Prüfung?
if (!fehler){ //Wenn Nicht Fehler dann min. Max. speichern
if ( h1 < h1min ) h1min = h1;
if ( h1 > h1max ) h1max = h1;
if ( h2 < h2min ) h2min = h2;
if ( h2 > h2max ) h2max = h2;
if ( t1 < t1min ) t1min = t1;
if ( t1 > t1max ) t1max = t1;
if ( t2 < t2min ) t2min = t2;
if ( t2 > t2max ) t2max = t2;
if ( Taupunkt_1 < Taupunkt_1min ) Taupunkt_1min = Taupunkt_1;
if ( Taupunkt_1 > Taupunkt_1max ) Taupunkt_1max = Taupunkt_1;
if ( Taupunkt_2 < Taupunkt_2min ) Taupunkt_2min = Taupunkt_2;
if ( Taupunkt_2 > Taupunkt_2max ) Taupunkt_2max = Taupunkt_2;
if ( DeltaTP < DeltaTPmin ) DeltaTPmin = DeltaTP;
if ( DeltaTP > DeltaTPmax ) DeltaTPmax = DeltaTP;
}
// Werteausgabe auf Serial Monitor
if(log_serial==1){ //Serial Monitor nur schreiben, wenn l1
Serial.print(DateTime(now)); //Formatierte Zeit
Serial.print(" ");
Serial.print(milDispLast/1000); //Anzahl Sek. aus millis() beim Messen
Serial.println("Sek.");
Serial.print(F("S1 "));
Serial.print(t1,1);
Serial.write(128); // Sonderzeichen °C
Serial.print(F("C "));
//oled.write(124); // Sonderzeichen |
//oled.print(F(" "));
Serial.print(h1,0);
Serial.print(F("% "));
Serial.print(F("Tp "));
Serial.print(Taupunkt_1,1);
Serial.write(128); // Sonderzeichen °C
Serial.println(F("C "));
Serial.print(F("S2 "));
Serial.print(t2,1);
Serial.write(128); // Sonderzeichen °C
Serial.print(F("C "));
//oled.write(124); // Sonderzeichen |
//oled.print(F(" "));
Serial.print(h2,0);
Serial.print(F("% " ));
Serial.print(F("Tp "));
Serial.print(Taupunkt_2,1);
Serial.write(128); // Sonderzeichen °C
Serial.println(F("C "));
//Serial.println("");
//Min
Serial.print(F("S1min "));
Serial.print(t1min,1);
Serial.write(128); // Sonderzeichen °C
Serial.print(F("C "));
//oled.write(124); // Sonderzeichen |
//oled.print(F(" "));
Serial.print(h1min,0);
Serial.print(F("% "));
Serial.print(F("Tp "));
Serial.print(Taupunkt_1min,1);
Serial.write(128); // Sonderzeichen °C
Serial.println(F("C "));
Serial.print(F("S2min "));
Serial.print(t2min,1);
Serial.write(128); // Sonderzeichen °C
Serial.print(F("C "));
//oled.write(124); // Sonderzeichen |
//oled.print(F(" "));
Serial.print(h2min,0);
Serial.print(F("% " ));
Serial.print(F("Tp "));
Serial.print(Taupunkt_2min,1);
Serial.write(128); // Sonderzeichen °C
Serial.println(F("C "));
//Serial.println("");
//Max
Serial.print(F("S1max "));
Serial.print(t1max,1);
Serial.write(128); // Sonderzeichen °C
Serial.print(F("C "));
//oled.write(124); // Sonderzeichen |
//oled.print(F(" "));
Serial.print(h1max,0);
Serial.print(F("% "));
Serial.print(F("Tp "));
Serial.print(Taupunkt_1max,1);
Serial.write(128); // Sonderzeichen °C
Serial.println(F("C "));
Serial.print(F("S2max "));
Serial.print(t2max,1);
Serial.write(128); // Sonderzeichen °C
Serial.print(F("C "));
//oled.write(124); // Sonderzeichen |
//oled.print(F(" "));
Serial.print(h2max,0);
Serial.print(F("% " ));
Serial.print(F("Tp "));
Serial.print(Taupunkt_2max,1);
Serial.write(128); // Sonderzeichen °C
Serial.println(F("C "));
//Serial.println("");
//Taupunktunderschied zwischen S1 und S2 anzeigen im Serialmonitor
Serial.print(F("DTp "));
Serial.print(DeltaTP,1);
Serial.print(F("C "));
Serial.print(DeltaTPmin,1);
Serial.write(128); // Sonderzeichen °C
Serial.print(F("C "));
Serial.print(DeltaTPmax,1);
Serial.write(128); // Sonderzeichen °C
Serial.print(F("C "));
}
// Werteausgabe auf dem I2C-Display
oled.clear();
oled.print(DateTime(now)); //Formatierte Zeit
oled.print(" ");
oled.print(milDispLast/1000); //Anzahl Sek. aus millis() beim Messen
oled.println("Sek.");
oled.print(F("S1 "));
oled.print(t1,1);
oled.write(128); // Sonderzeichen °C
oled.print(F("C "));
//oled.write(124); // Sonderzeichen |
//oled.print(F(" "));
oled.print(h1,0);
oled.print(F("% "));
oled.print(F("Tp "));
oled.print(Taupunkt_1,1);
oled.write(128); // Sonderzeichen °C
oled.println(F("C "));
oled.print(F("S2 "));
oled.print(t2,1);
oled.write(128); // Sonderzeichen °C
oled.print(F("C "));
//oled.write(124); // Sonderzeichen |
//oled.print(F(" "));
oled.print(h2,0);
oled.print(F("% " ));
oled.print(F("Tp "));
oled.print(Taupunkt_2,1);
oled.write(128); // Sonderzeichen °C
oled.println(F("C "));
//oled.println("");
//Min
oled.print(F("S1min "));
oled.print(t1min,1);
oled.write(128); // Sonderzeichen °C
oled.print(F("C "));
//oled.write(124); // Sonderzeichen |
//oled.print(F(" "));
oled.print(h1min,0);
oled.print(F("% "));
oled.print(F("Tp "));
oled.print(Taupunkt_1min,1);
oled.write(128); // Sonderzeichen °C
oled.println(F("C "));
oled.print(F("S2min "));
oled.print(t2min,1);
oled.write(128); // Sonderzeichen °C
oled.print(F("C "));
//oled.write(124); // Sonderzeichen |
//oled.print(F(" "));
oled.print(h2min,0);
oled.print(F("% " ));
oled.print(F("Tp "));
oled.print(Taupunkt_2min,1);
oled.write(128); // Sonderzeichen °C
oled.println(F("C "));
//oled.println("");
//Max
oled.print(F("S1max "));
oled.print(t1max,1);
oled.write(128); // Sonderzeichen °C
oled.print(F("C "));
//oled.write(124); // Sonderzeichen |
//oled.print(F(" "));
oled.print(h1max,0);
oled.print(F("% "));
oled.print(F("Tp "));
oled.print(Taupunkt_1max,1);
oled.write(128); // Sonderzeichen °C
oled.println(F("C "));
oled.print(F("S2max "));
oled.print(t2max,1);
oled.write(128); // Sonderzeichen °C
oled.print(F("C "));
//oled.write(124); // Sonderzeichen |
//oled.print(F(" "));
oled.print(h2max,0);
oled.print(F("% " ));
oled.print(F("Tp "));
oled.print(Taupunkt_2max,1);
oled.write(128); // Sonderzeichen °C
oled.println(F("C "));
//oled.println("");
oled.print(F("DTp "));
oled.print(DeltaTP,1);
oled.print(F("C "));
oled.print(DeltaTPmin,1);
oled.write(128); // Sonderzeichen °C
oled.print(F("C "));
oled.print(DeltaTPmax,1);
oled.write(128); // Sonderzeichen °C
oled.print(F("C "));
//delay(delayDisplay); //6000); // Zeit um das Display zu lesen
timerWrite(timer, 0); //reset timer (feed watchdog)
//Prüfe ob Relais (rel) an oder aus soll
if (DeltaTP > (SCHALTmin + HYSTERESE))rel = true;
if (DeltaTP < (SCHALTmin))rel = false;
if (t1 < TEMP1_min )rel = false;
if (t2 < TEMP2_min )rel = false;
//String relString = "AUS";
if (rel == true)
{
digitalWrite(RELAIPIN, RELAIS_EIN); // Relais einschalten
oled.println(F("Fan AN"));
if(log_serial==1) Serial.println(F("Fan AN"));
//String relString = "AN";
} else {
digitalWrite(RELAIPIN, RELAIS_AUS); // Relais ausschalten
oled.println(F("Fan AUS"));
if(log_serial==1) Serial.println(F("Fan AUS"));
//String relString = "AUS";
}
if(log_serial==1) Serial.println("rel ");
if(log_serial==1) Serial.println(rel);
//SDDatenGlobal = "text der etwas länger ist und noch laenger...";// "int10";
//Serial.println(SDDatenGlobal);
//Hier wird der String konstruiert
//char *SDDatenGlobalLabel = "Zaehler; Datum Zeit; Laufzeit; S1_Temp_C; S1_Feuchte_%; S1_Taupunkt_C; S2_Temp_C; S2_Feuchte_%; S2_Taupunkt_C; S1min_Temp_C; S1min_Feuchte_%; S1min_Taupunkt_C; S2min_Temp_C; S2min_Feuchte_%; S2min_Taupunkt_C; S1max_Temp_C; S1max_Feuchte_%; S1max_Taupunkt_C; S2max_Temp_C; S2max_Feuchte_%; S2max_Taupunkt_C; Delta_Taupunkt; Delta_Taupunkt_S1min; Delta_Taupunkt_S1max; Fan_An-Aus \r\n"; //Erste Zeile Trennzeichen ";
String StringSDDatenGlobal_t1 = String(SDLogZaehlerGlobal)+";"+String(DateTime(now))+";"+String(milDispLast/1000)+";"+String(t1,1)+";"+String(h1,0)+";"+String(Taupunkt_1,1)+";"+String(t2,1)+";"+String(h2,0)+";"+String(Taupunkt_2,1)+";"+String(t1min,1)+";"+String(h1min,0)+";"+String(Taupunkt_1min,1)+";"+String(t2min,1)+";"+String(h2min,0)+";"+String(Taupunkt_2min,1)+";"+String(t1max,1)+";"+String(h1max,0)+";";
//Serial.println(StringSDStatusGlobal_t1);
StringSDDatenGlobal = StringSDDatenGlobal_t1 + String(Taupunkt_1max,1)+";"+String(t2max,1)+";"+String(h2max,0)+";"+String(Taupunkt_2max,1)+";"+String(DeltaTP)+";"+String(DeltaTPmin)+";"+String(DeltaTPmax)+";"+String(rel)+" \r\n";
//StringSDDatenGlobal = String(SDLogZaehlerGlobal)+";"+String(DateTime(now))+";"+String(milDispLast/1000)+";"+String(t1,1)+";"+String(h1,0)+";"+String(Taupunkt_1,1)+";"+String(t2,1)+";"+String(h2,0)+";"+String(Taupunkt_2,1)+";"+String(t1min,1)+";"+String(h1min,0)+";"+String(Taupunkt_1min,1)+";"+String(t2min,1)+";"+String(h2min,0)+";"+String(Taupunkt_2min,1)+";"+String(t1max,1)+";"+String(h1max,0)+";"+String(Taupunkt_1max,1)+";"+String(t2max,1)+";"+String(h2max,0)+";"+String(Taupunkt_2max,1)+";"+String(DeltaTP)+";"+String(DeltaTPmin)+";"+String(DeltaTPmax)+" \r\n";
StringSDDatenGlobal.toCharArray(SDDatenGlobal, StringSDDatenGlobal.length()+1);
if(log_serial==1) Serial.println(StringSDDatenGlobal);
if(log_serial==1) Serial.println(SDDatenGlobal);
if(log_serial==1) Serial.println(SDLogZaehlerGlobal);
//delay(2000);
//SDLogZaehlerGlobal= SDLogZaehlerGlobal+1;
//Serial.println("---------------------------------------------------------");
//Serial.println(xSDDatenGlobal);
//Serial.println("---------------------------------------------------------");
timerWrite(timer, 0); //reset timer (feed watchdog)
int i = 1;
//Serial.println(F("FanContDisp()"));
return i;
}
int LogToSD(){
int i = 0;
if(log_serial==1) Serial.print("Jetzt wird geloggt ");
if (SDStatusGlobal >= 10){
//Prüfen ob SDFileNameGlobal schon existiert
File file = SD.open(SDFileNameGlobal);
//File file = SD.open("/temperature_readings.txt");
if(!file) {
Serial.println(F("File does not exist"));
Serial.println(F("Creating file..."));
writeFile(SD, SDFileNameGlobal, SDDatenGlobalLabel); //File anlege und in die erste Zeile Legende schreiben
//readFile(SD, SDFileNameGlobal);
SDStatusGlobal = 20; //File angelegt
}
else {
//Serial.println(readFile(SD, SDFileNameGlobal));
//readFile(SD, SDFileNameGlobal);
if(log_serial==1) Serial.println(F("File exists"));
SDStatusGlobal = 30; //File bereit vorhanden
}
//appendFile(SD, SDFileNameGlobal, "Daten; Daten1; Daten2; Daten3 \r\n");
if ((appendFile(SD, SDFileNameGlobal, SDDatenGlobal)) <= 10){
//SDlog.h
Serial.print("SDinit Rueckgabe: ");
//Serial.println(SDinit(SDFileNameGlobal, SDDatenGlobal)); //SD Karte initialisieren und File prüfen
SDStatusGlobal = SDinit(SDFileNameGlobal, SDDatenGlobal);
Serial.println(SDStatusGlobal);
};
SDLogZaehlerGlobal ++;
file.close();
if(log_serial==1) Serial.println(SDStatusGlobal);
} else {
//SDlog.h
Serial.print("SDinit Rueckgabe: ");
//Serial.println(SDinit(SDFileNameGlobal, SDDatenGlobal)); //SD Karte initialisieren und File prüfen
SDStatusGlobal = SDinit(SDFileNameGlobal, SDDatenGlobal);
Serial.println(SDStatusGlobal);
}
i = SDStatusGlobal;
if(log_serial==1) Serial.println(i);
return i;
}
//Taupunkt Berechnung
float taupunkt(float t, float r) {
float a, b;
if (t >= 0) {
a = 7.5;
b = 237.3;
} else if (t < 0) {
a = 7.6;
b = 240.7;
}
// Sättigungsdampfdruck in hPa
float sdd = 6.1078 * pow(10, (a*t)/(b+t));
// Dampfdruck in hPa
float dd = sdd * (r/100);
// v-Parameter
float v = log10(dd/6.1078);
// Taupunkttemperatur (°C)
float tt = (b*v) / (a-v);
return { tt };
}
//RTC Erzeuge Zeitstempel als String
String DateTime(const RtcDateTime& dt){
char datestring[25];
char daysOfTheWeek[7][3] = {"So","Mo", "Di", "Mi", "Do", "Fr", "Sa"};
//char daysOfTheWeek[7][4] = {"Sun","Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
//String without String class anschauen
//https://cpp4arduino.com/2020/02/07/how-to-format-strings-without-the-string-class.html
snprintf_P(datestring,
countof(datestring),
PSTR("%2s, %02u.%02u.%04u %02u:%02u:%02u"),
daysOfTheWeek[dt.DayOfWeek()],
dt.Day(),
dt.Month(),
dt.Year(),
dt.Hour(),
dt.Minute(),
dt.Second() );
//Serial.print(datestring);
return datestring;
}
//-RTC
void ARDUINO_ISR_ATTR resetModule() {
//ets_printf("reboot\n");
esp_restart();
}