diff --git a/ESPNTUhrPx.ino b/ESPNTUhrPx.ino index d8deae1..54ce562 100644 --- a/ESPNTUhrPx.ino +++ b/ESPNTUhrPx.ino @@ -1,6 +1,7 @@ -#define VERSION (char *) "V2.21" +#define VERSION (char *) "V2.23" /* + "NodeMCU 1.0 (ESP-12e)" V2.12 230205 neues SDK 8266; AP+Wifi Client; lokaleip eingebaut V2.13 230206 Datum/Uhrzeit zeit auch KW an V2.14 230208 AP+STA nur wenn Wifi verbunden ist sonst geht der AP nicht @@ -11,6 +12,8 @@ V2.19 230327 Sommerzeit stellt die Uhr jetzt auch vor (nicht zurück); neues SDK V2.20 230331 OV-Alzenau in RST Karlstadt geändert (Name beim Booten) V2.21 231111 Begrüßungs OV kann jetzt mit "/do?set=owner&to=" gewählt werden (0=OALZ,1=ODES,default=RKST); Debug Zeile ausgeblendet; + V2.22 250702 KalenderWochen Fehler -> neue Funktion + V2.23 251209 NTP überarbeitet; send_P umgebaut */ // Pins for LED MATRIX @@ -34,11 +37,12 @@ uint8_t display_draw_time=30; //30-60 is usually fine // This defines the 'on' time of the display is us. The larger this number,// the brighter the display. If too large the ESP will crash //WebService - #define TEMPLATE_PLACEHOLDER '`' //-> Damit % in CSS funktioniert muss in der .h geändert werden!!! ... + #define TEMPLATE_PLACEHOLDER '`' //-> Damit % in CSS funktioniert muss in der WebResponseImpl.h geändert werden!!! ... #include #include #include +#define ELEGANTOTA_USE_ASYNC_WEBSERVER 1 #include #include AsyncWebServer webServer(80); @@ -80,7 +84,8 @@ char ChipID[10] = "ERROR"; uint8_t temperature=0; #include -#include +#include +#include long ti_second = 0; @@ -107,6 +112,15 @@ char ChipID[10] = "ERROR"; uint8_t owner = 0; +void delay_ex(uint16_t _ms){ + for(uint16_t ms = 0;ms<_ms;ms++){ + yield(); + //esp_task_wdt_reset(); + delay(1); + } + +} + // ISR for display refresh void display_updater(){ display.display(display_draw_time); @@ -735,8 +749,9 @@ void setup() { //showRST(); showNTOOLS(); display_update_enable(true); - + Wire.begin(1,3); + //Serial.begin(115200); //RTC if (rtc.begin() == false) { display.drawPixelRGB888(0,0,255,0,0); @@ -749,6 +764,7 @@ void setup() { pinMode(PINRTC_CLOCK, INPUT_PULLUP); setTime(rtc.getUNIX()); checkiDL(); + rtc.getTEMPERATURE(&temperature); } char NetName[30]; @@ -763,11 +779,12 @@ void setup() { WiFi.hostname(NetName); int xc = 0; while ((WiFi.status() != WL_CONNECTED) && (xc < 10)) { - delay(1500); + delay_ex(1500); xc++; display.drawPixelRGB888(xc+5,0,255,255,0); display_doupdate(); } + if (WiFi.status() == WL_CONNECTED) { char str[5]; IPAddress lip; @@ -787,16 +804,20 @@ void setup() { display.drawPixelRGB888(1, 0, 0, 255, 0); display_doupdate(); configTime("CET-1CEST,M3.5.0,M10.5.0/3", "ptbtime1.ptb.de", "ptbtime2.ptb.de", "ptbtime3.ptb.de"); - time_t timenow = time(nullptr); xc = 0; - while((timenow < SECS_YR_2000) && (xc < 10)) { - delay(1000); - timenow = time(nullptr); + while((sntp_get_current_timestamp() < 1735686000) && (xc < 10)) { + //while((xc < 40)) { + //Serial.println(sntp_get_current_timestamp()); + delay_ex(1000); xc++; display.drawPixelRGB888(xc+16,0,255,255,0); display_doupdate(); } - if(timenow > SECS_YR_2000){ + sntp_stop(); + //Serial.println("stop"); + //Serial.println(sntp_get_current_timestamp()); + if(sntp_get_current_timestamp() > 1735686000){ + time_t timenow = sntp_get_current_timestamp(); timenow += 1; uint8_t Month, Day, Hour; setTime(timenow); @@ -823,7 +844,7 @@ void setup() { display.drawPixelRGB888(2,0,255,0,255); display_doupdate(); } - delay(5000); + delay_ex(3000); }else{ display.drawPixelRGB888(1,0,255,0,0); display_doupdate(); @@ -832,15 +853,16 @@ void setup() { if(alwaysAccessPoint){ if (WiFi.status() != WL_CONNECTED) { WiFi.disconnect(); - delay(100); + delay_ex(100); WiFi.mode(WIFI_OFF); - delay(100); + delay_ex(100); WiFi.mode(WIFI_AP); } - delay(100); + delay_ex(100); WiFi.softAPConfig(ip_local, ip_gateway, ip_subnet); APEnabled = WiFi.softAP(APName, appass,2,0,2,250); + //APEnabled = WiFi.softAP(APName, "nix",2,0,2,250); if(!APEnabled) display.drawPixelRGB888(3,0,255,0,0); else @@ -867,7 +889,7 @@ void setup() { if(rtcEnabled) attachInterrupt(digitalPinToInterrupt(PINRTC_CLOCK), rtc_clock, CHANGE); - delay(3000); + delay_ex(3000); doClearLEDsStatus(); } @@ -881,6 +903,7 @@ void loop(){ time_t currentUNIXTime = now(); if(rtcEnabled){ currentUNIXTime = rtc.getUNIX(); + //Serial.println(currentUNIXTime); setTime(currentUNIXTime); } uint8_t Hour, Minute, Second, WDay; @@ -938,7 +961,7 @@ const char* PARAM_PWD = "pwd"; const char* PARAM_RESET = "reset"; void html_root(AsyncWebServerRequest *request) { - request->send_P(200, "text/html", html_page_index, html_processor); + request->send(200, "text/html", html_page_index, html_processor); } void html_poll(AsyncWebServerRequest *request) { @@ -969,10 +992,10 @@ void html_poll(AsyncWebServerRequest *request) { itoa(timeIndex,tempBuff,DEC); strcat(ret,(char *)","); strcat(ret,tempBuff); - itoa(lastTimeSyncTyp,tempBuff,DEC); + itoa(lastTimeSyncTime,tempBuff,DEC); strcat(ret,(char *)","); strcat(ret,tempBuff); - itoa(lastTimeSyncTime,tempBuff,DEC); + itoa(lastTimeSyncTyp,tempBuff,DEC); strcat(ret,(char *)","); strcat(ret,tempBuff); dtostrf(brightness, 10, 2, tempBuff); @@ -1131,7 +1154,7 @@ void html_do(AsyncWebServerRequest *request) { request->send(200, "text/plain", "OK"); }else if (request->hasParam(PARAM_RESET)){ request->send(200, "text/plain", "OK"); - delay(1000); + delay_ex(1000); ESP.restart(); }else{ request->send(200, "text/plain", "NOK"); diff --git a/index_html.h b/index_html.h index 0b8802f..ac5812b 100644 --- a/index_html.h +++ b/index_html.h @@ -1,4 +1,4 @@ -const char html_page_index[] PROGMEM = R"rawliteral( +static const char *html_page_index PROGMEM = R"rawliteral( N-Tools.de Uhr @@ -140,9 +140,6 @@ const char html_page_index[] PROGMEM = R"rawliteral( text-decoration: none; text-transform: uppercase; padding: 0.25rem 0.5rem; - @media(min-width: 600px) { - margin: 0 1em 2em; - } &:hover { text-decoration: none; } @@ -394,7 +391,8 @@ const char html_page_index[] PROGMEM = R"rawliteral( document.getElementById('actDate').style.color = colorString; document.getElementById('showWhat').value = parseInt(data[4]); - switch(data[5]){ + showTimeFromUnix(data[5],'sync'); + switch(data[6]){ case 0: document.getElementById('sync').innerHTML = " keiner"; break; @@ -407,8 +405,7 @@ const char html_page_index[] PROGMEM = R"rawliteral( case 3: document.getElementById('sync').innerHTML += " (manuel)"; break; - } - showTimeFromUnix(data[6],'sync'); + } document.getElementById('brigtness').innerHTML = (data[7]*100); document.getElementById("rtcactive").checked = (data[8] == 1);