Added summer/wintertime detection.

master
Holger Wirtz 4 years ago
parent 655087cc22
commit 38d794300b
  1. 72
      WLAN_Thermometer.ino

@ -11,6 +11,7 @@
#include <looper.h>
#include <RunningMedian.h>
#include <ESPDateTime.h>
#include <Time.h>
#define MDNS_NAME "wlanthermometer"
#define AP_SSID_CONFIG_NAME "WLANTHERMOMETER-Config"
@ -29,9 +30,9 @@
LiquidCrystal_I2C lcd(LCD_I2C_ADDR, LCD_COL, LCD_ROW);
looper sched;
RunningMedian samples = RunningMedian(MEDIAN_SAMPLES);
float temp_min = (analogRead(TEMP_SENS_PIN) / 2048.0) * 330.0;
float temp_max = temp_min;
float temp = (analogRead(TEMP_SENS_PIN) / 2048.0) * 330.0;
float temp_min;
float temp_max;
float temp;
bool led_state;
String header;
WiFiServer server(80);
@ -59,8 +60,13 @@ void setup()
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
WiFiManager wm;
bool bounce[2];
if (digitalRead(AP_DATA_RESET_PIN) != LOW)
bounce[0] = digitalRead(AP_DATA_RESET_PIN);
delay(50);
bounce[1] = digitalRead(AP_DATA_RESET_PIN);
if (bounce[1] == LOW && bounce[0] == LOW)
{
wm.resetSettings();
DEBUG_MSG("Resetting AP data\n");
@ -117,7 +123,7 @@ void setup()
lcd.setCursor(0, 3);
lcd.print("Getting time...");
DateTime.setTimeZone(2);
DateTime.setTimeZone(1);
DateTime.begin(NTP_TIMEOUT);
while (!DateTime.isTimeValid())
{
@ -130,6 +136,10 @@ void setup()
sched.addJob(show_temperature, KRATE_TEMP);
sched.addJob(show_time, KRATE_TIME);
temp_min = (analogRead(TEMP_SENS_PIN) / 2048.0) * 330.0;
temp_max = temp_min;
temp = (analogRead(TEMP_SENS_PIN) / 2048.0) * 330.0;
lcd.clear();
show_time();
show_temperature();
@ -213,10 +223,19 @@ void show_time(void)
DateTimeParts p = DateTime.getParts();
char dt[21];
Serial.println(DateTime.format(DateFormatter::DATE_ONLY));
Serial.println(DateTime.format(DateFormatter::TIME_ONLY));
if (is_wintertime(DateTime.getTime()) == false)
{
sprintf(dt, "%02d.%02d.%4d %02d:%02d:%02d", p.getMonthDay(), p.getMonth() + 1, p.getYear(), p.getHours() + 1, p.getMinutes(), p.getSeconds());
Serial.print(dt);
Serial.println(" Summertime");
}
else
{
sprintf(dt, "%02d.%02d.%4d %02d:%02d:%02d", p.getMonthDay(), p.getMonth() + 1, p.getYear(), p.getHours(), p.getMinutes(), p.getSeconds());
Serial.print(dt);
Serial.println(" Wintertime");
}
sprintf(dt, "%02d.%02d.%4d %02d:%02d:%02d", p.getMonthDay(), p.getMonth() + 1, p.getYear(), p.getHours(), p.getMinutes(), p.getSeconds());
lcd.setCursor(0, 0);
lcd.print(dt);
@ -262,3 +281,40 @@ void show_temperature(void)
lcd.print("Maximum: ");
lcd.print(temp_max);
}
bool is_wintertime(time_t t)
{
// Sommerzeit/Winterzeit http://manfred.wilzeck.de/Datum_berechnen.html#Jahreszahl
// Tag = 31 – ( 4 + Jahr*5 / 4) MOD 7 ' Datum Tag für Beginn Sommerzeit (Jahr 4-stellig)
// Tag = 31 – ( 1 + Jahr*5 / 4) MOD 7 ' Datum Tag für Ende Sommerzeit (Jahr 4-stellig)
tmElements_t tm;
byte day_of_switch[2];
time_t switch_secs[2];
byte i;
day_of_switch[0] = 31 - (4 + year(t) * 5 / 4) % 7; // winter->summer
day_of_switch[1] = 31 - (1 + year(t) * 5 / 4) % 7; // summer->winter
for (i = 0; i < 2; i++)
{
tm.Second = 0;
if (i == 0)
tm.Hour = 2;
else
tm.Hour = 3;
tm.Minute = 0;
tm.Day = day_of_switch[i];
if (i == 0)
tm.Month = 3;
else
tm.Month = 10;
tm.Year = year(t) - 1970;
switch_secs[i] = makeTime(tm);
}
if (t >= switch_secs[0] && t < switch_secs[1])
return (false);
else
return (true);
}

Loading…
Cancel
Save