diff --git a/ESPNTUhrPx.ino b/ESPNTUhrPx.ino index 1424e4b..b6082c0 100644 --- a/ESPNTUhrPx.ino +++ b/ESPNTUhrPx.ino @@ -1,4 +1,4 @@ -#define VERSION (char *) "V2.17" +#define VERSION (char *) "V2.19" /* V2.12 230205 neues SDK 8266; AP+Wifi Client; lokaleip eingebaut @@ -7,6 +7,8 @@ V2.15 230212 Verbesserung AP_STA modus;Wlan auf 1 Connect beschränkt; V2.16 230212 MaxConnect auf 2; Beacon auf 250ms V2.17 230227 alle unbekannten Seiten Leiten auf die IP um + V2.18 230313 Sommerzeitprüfung auch offline eingebaut; Auf doRTCSecond umgebaut; + V2.19 230327 Sommerzeit stellt die Uhr jetzt auch vor (nicht zurück); neues SDK */ // Pins for LED MATRIX @@ -71,7 +73,8 @@ char ChipID[10] = "ERROR"; #include RV3029 rtc; const int PINRTC_CLOCK = 12; - boolean rtcEnabled = false; + bool rtcEnabled = false; + bool doRTCSecond = false; uint8_t temperature=0; #include @@ -87,7 +90,8 @@ char ChipID[10] = "ERROR"; float brightness = 0.80; int8_t lastminutes = -1; - boolean iDL = false; + bool iDL = false; + bool savediDL = false; uint8_t lastTimeSyncTyp = 0; long lastTimeSyncTime = 0; @@ -111,35 +115,21 @@ void display_update_enable(bool is_enable){ display_ticker.detach(); } -//Led mit Helligkeit setzen +//Led setzen void setPixelColor(uint8_t x,uint8_t y, uint8_t red, uint8_t green ,uint8_t blue){ - /*red = ceil(red * brightness); - green = ceil(green * brightness); - blue = ceil(blue * brightness);*/ display.drawPixelRGB888(x, y, red, green, blue); - // } //Zeichene eine Linie waagrecht x/y und z als länge void LineH(uint8_t x, uint8_t y, uint8_t z, uint8_t red, uint8_t green ,uint8_t blue){ uint16_t color = display.color565(red, green, blue); display.drawFastHLine(x,y,z,color); - //display.display(display_draw_time); - /*for(uint8_t c = 0; c void doClearLEDsSeconds(int8_t ycorrection=0){ - for(uint8_t x=0;x<5;x++){ display.drawFastHLine(56,26 + x + ycorrection, 7, 0); } - /*for(uint16_t x=56;x 1.0) brightness = 1.0; + EEPROM.get(10, savediDL); + timeColor[0] = EEPROM.read(11); timeColor[1] = EEPROM.read(12); timeColor[2] = EEPROM.read(13); @@ -709,7 +677,6 @@ void setup() { EEPROM.get(151,appass); display.begin(16); - //display.setBrightness(255); display.setBrightness(ceil(255 * brightness)); display.setFastUpdate(true); doClearLEDs(true); @@ -719,7 +686,6 @@ void setup() { display_update_enable(true); Wire.begin(1,3); - //Wire.setClock(400000); //RTC if (rtc.begin() == false) { display.drawPixelRGB888(0,0,255,0,0); @@ -731,15 +697,7 @@ void setup() { rtcEnabled = true; pinMode(PINRTC_CLOCK, INPUT_PULLUP); setTime(rtc.getUNIX()); - long currentUNIXTime = now(); - byte Month, Day, Hour, Minute, Second, WDay; - Month = month(currentUNIXTime); - Day = day(currentUNIXTime); - Hour = hour(currentUNIXTime); - Minute = minute(currentUNIXTime); - Second = second(currentUNIXTime); - WDay = weekday(); - iDL = isDayLight(Hour,Day,WDay,Month); + checkiDL(); } char NetName[30]; @@ -749,9 +707,7 @@ void setup() { strcpy(APName, "NTUhr VPx "); strcat(APName, ChipID); - WiFi.persistent(false); - WiFi.mode(WIFI_AP_STA); WiFi.begin(ssid,pass); WiFi.hostname(NetName); int xc = 0; @@ -791,21 +747,25 @@ void setup() { } if(timenow > SECS_YR_2000){ timenow += 1; - int Year; - byte Month, Day, Hour; + uint8_t Month, Day, Hour; setTime(timenow); - Year = year(timenow); + Month = month(timenow); Day = day(timenow); Hour = hour(timenow); - if(isDayLight(Hour,Day,weekday(),Month)) + iDL = isDayLight(Hour,Day,weekday(),Month); + if(iDL) timenow += (SECS_PER_HOUR * 2); else timenow += (SECS_PER_HOUR); + setTime(timenow); if(rtcEnabled){ doSetTime(timenow); } lastTimeSyncTyp = 2; lastTimeSyncTime = timenow; + savediDL = iDL; + EEPROM.put(10, savediDL); + EEPROM.commit(); display.drawPixelRGB888(2,0,0,255,0); display_doupdate(); }else{ @@ -829,7 +789,6 @@ void setup() { delay(100); WiFi.softAPConfig(ip_local, ip_gateway, ip_subnet); - //appass = ; APEnabled = WiFi.softAP(APName, appass,2,0,2,250); if(!APEnabled) display.drawPixelRGB888(3,0,255,0,0); @@ -843,13 +802,6 @@ void setup() { display_doupdate(); - //für die automatische Umleitung - /*webServer.on("/generate_204", HTTP_GET, [](AsyncWebServerRequest *request){html_root(request);}); //Android captive portal. - webServer.on("/fwlink", HTTP_GET, [](AsyncWebServerRequest *request){html_root(request);}); //Microsoft captive portal. - webServer.on("/connecttest.txt", HTTP_GET, [](AsyncWebServerRequest *request){html_root(request);}); //www.msftconnecttest.com - webServer.on("/hotspot-detect.html", HTTP_GET, [](AsyncWebServerRequest *request){html_root(request);}); //captive.apple.com - webServer.on("/success.txt", HTTP_GET, [](AsyncWebServerRequest *request){html_handle_success(request);}); //detectportal.firefox.com/sucess.txt - webServer.on("/redirect", HTTP_GET, [](AsyncWebServerRequest *request){html_root(request);}); //Microsoft captive portal.*/ webServer.onNotFound([](AsyncWebServerRequest *request){html_handle_notsuccess(request);}); //eigene Seiten @@ -871,28 +823,22 @@ void setup() { void loop(){ if (millis() - ti_second > 1000) { ti_second = millis(); + } + if(doRTCSecond){ + doRTCSecond = false; if((timeStatus() != timeNotSet)){ time_t currentUNIXTime = now(); if(rtcEnabled){ currentUNIXTime = rtc.getUNIX(); setTime(currentUNIXTime); } - byte Month, Day, Hour, Minute, Second, WDay; - Month = month(currentUNIXTime); - Day = day(currentUNIXTime); + uint8_t Hour, Minute, Second, WDay; Hour = hour(currentUNIXTime); Minute = minute(currentUNIXTime); Second = second(currentUNIXTime); WDay = weekday(); - if((isDayLight(Hour,Day,WDay,Month) != iDL) && (((Month == 10) & (Hour >= 3)) | (Month == 3))){ - if(iDL){ - doSetTime(currentUNIXTime - SECS_PER_HOUR); - }else{ - doSetTime(currentUNIXTime + SECS_PER_HOUR); - } - iDL = isDayLight(Hour,Day,WDay,Month); - } - //Sonntag und NTP = Reset .. + checkiDL(); + //Sonntag Reset .. if((WDay == 1) && (Hour == 3) && (Minute == 1) && (Second == 0)){ ESP.restart(); } @@ -922,8 +868,8 @@ void loop(){ } rtc.getTEMPERATURE(&temperature); } - dnsServer.processNextRequest(); - //yield(); + if(APEnabled) + dnsServer.processNextRequest(); } //alles was WEB ist ... @@ -1006,6 +952,9 @@ void html_poll(AsyncWebServerRequest *request) { itoa(kw,tempBuff,DEC); strcat(ret,(char *)","); strcat(ret,tempBuff); + itoa(iDL,tempBuff,DEC); + strcat(ret,(char *)","); + strcat(ret,tempBuff); strcat(ret,(char *)"]"); request->send(200, "text/plain", ret); } @@ -1021,6 +970,16 @@ void html_do(AsyncWebServerRequest *request) { doSetTime(l_value); lastTimeSyncTyp = 3; lastTimeSyncTime = now(); + //isDayLight (Sommerzeit) prüfen + uint8_t Month, Day, Hour; + setTime(l_value); + Month = month(l_value); + Day = day(l_value); + Hour = hour(l_value); + iDL = isDayLight(Hour,Day,weekday(),Month); + savediDL = iDL; + EEPROM.put(10, savediDL); + EEPROM.commit(); }else if(request->hasParam(PARAM_SHOWWHAT)) { s_value = request->getParam(PARAM_SHOWWHAT)->value(); timeIndex = s_value.toInt(); @@ -1138,13 +1097,4 @@ char * html_processor(const String& var){ return localip; } return (char *) "not defined"; -} - -String toggleState(int toggle){ - switch(toggle){ - case 0: - - break; - } - return ""; } \ No newline at end of file diff --git a/index_html.h b/index_html.h index 27e0944..738cd66 100644 --- a/index_html.h +++ b/index_html.h @@ -228,6 +228,10 @@ const char html_page_index[] PROGMEM = R"rawliteral( + + + + @@ -422,6 +426,7 @@ const char html_page_index[] PROGMEM = R"rawliteral( colorString = "#" + data[13].toString(16).padStart(6, '0'); document.getElementById('actKW').style.color = colorString; document.getElementById('actKW').innerHTML = "KW " + data[14]; + document.getElementById("isSummerTime").checked = (data[15] == 1); }catch(e){ console.log(e); }