240517 -> V2.3 WiFi.setAutoReconnect(true);

250702 -> V2.4 Wochennummern korrektur
251207 -> V2.5 NTP Überarbeitet; Webserver send_P ausgebaut
This commit is contained in:
2025-12-12 16:55:48 +01:00
parent 5bae57fa1b
commit f71798dd61
2 changed files with 64 additions and 42 deletions

View File

@@ -1,10 +1,15 @@
/* /*
N-Tools 2023 N-Tools 2023
"ESP32 Dev Module"
231112 -> Webseite Optimiert; kleinigkeiten für Uli; 231112 -> Webseite Optimiert; kleinigkeiten für Uli;
231210 -> Fehler in der Schrift NT7x10 behoben 231210 -> Fehler in der Schrift NT7x10 behoben
240306 -> ???
240517 -> V2.3 WiFi.setAutoReconnect(true);
250702 -> V2.4 Wochennummern korrektur
251207 -> V2.5 NTP Überarbeitet; Webserver send_P ausgebaut
*/ */
#define VERSION (char *) "V2.1" #define VERSION (char *) "V2.5"
char ChipID[10] = "ERROR"; char ChipID[10] = "ERROR";
uint64_t macAddress = ESP.getEfuseMac(); uint64_t macAddress = ESP.getEfuseMac();
@@ -32,7 +37,7 @@ uint64_t macAddressTrunc = (macAddress << 40);
#define NUM_COLS 1 // Number of INDIVIDUAL PANELS per ROW #define NUM_COLS 1 // Number of INDIVIDUAL PANELS per ROW
#define PANEL_CHAIN NUM_ROWS*NUM_COLS // total number of panels chained one to another #define PANEL_CHAIN NUM_ROWS*NUM_COLS // total number of panels chained one to another
//#define PIXEL_COLOR_DEPTH_BITS 2 #define PIXEL_COLOR_DEPTH_BITS 4
// library includes // library includes
//#include <ESP32-VirtualMatrixPanel-I2S-DMA.h> //#include <ESP32-VirtualMatrixPanel-I2S-DMA.h>
@@ -44,8 +49,9 @@ MatrixPanel_I2S_DMA *display = nullptr;
#include <WiFiClient.h> #include <WiFiClient.h>
#include <WiFiAP.h> #include <WiFiAP.h>
#include <AsyncTCP.h> #include <AsyncTCP.h>
#include <ESPAsyncWebServer.h> #define ELEGANTOTA_USE_ASYNC_WEBSERVER 1
#include <ElegantOTA.h> #include <ElegantOTA.h>
#include <ESPAsyncWebServer.h>
#include <DNSServer.h> #include <DNSServer.h>
AsyncWebServer webServer(80); AsyncWebServer webServer(80);
DNSServer dnsServer; DNSServer dnsServer;
@@ -96,7 +102,7 @@ MatrixPanel_I2S_DMA *display = nullptr;
} }
void html_root(AsyncWebServerRequest *request); void html_root(AsyncWebServerRequest *request);
void html_root(AsyncWebServerRequest *request) { 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); void html_poll(AsyncWebServerRequest *request);
@@ -116,7 +122,8 @@ MatrixPanel_I2S_DMA *display = nullptr;
bool doRTCSecond = false; bool doRTCSecond = false;
#include <TimeLib.h> #include <TimeLib.h>
#include <WeekNumber.h> #include <WeekNumberEx.h>
#include <esp_sntp.h>
long ti_second = 0; long ti_second = 0;
float brightness = 1.0; float brightness = 1.0;
@@ -170,14 +177,23 @@ void doClearTacticalLEDs(uint8_t x=0,uint8_t y=0){
//eigene Schriften //eigene Schriften
#include <char5x7.h> #include <char5x7.h>
#include <char6x8.h>
#include <char10x16.h> #include <char10x16.h>
#include <char16x24.h> #include <char16x24.h>
#include <tthcent8p.h> //#include <tthcent8p.h>
#include <NT7x10.h> #include <NT7x10.h>
#include <BundesSans6P.h> //#include <BundesSans6P.h>
#include <teko6P.h> //#include <teko6P.h>
void delay_ex(uint16_t _ms){
for(uint16_t ms = 0;ms<_ms;ms++){
yield();
//esp_task_wdt_reset();
delay(1);
}
}
void showNTOOLS(void){ void showNTOOLS(void){
uint8_t zeile=12; uint8_t zeile=12;
@@ -201,15 +217,15 @@ void drawSeconds(time_t t, uint8_t x=0, uint8_t y=0){
uint8_t g = timeColor[1]; uint8_t g = timeColor[1];
uint8_t b = timeColor[2]; uint8_t b = timeColor[2];
for(uint8_t i=0;i<16;i++){ for(uint8_t i=0;i<8;i++){
display->drawFastHLine(x,y+i, 21, 0); display->drawFastHLine(x,y+i, 13, 0);
} }
tmp = second(t); tmp = second(t);
Out10x16Char((tmp/10)+0x30,x,y,r,g,b); Out6x8Char((tmp/10)+0x30,x,y,r,g,b);
tmp -= (tmp/10)*10; tmp -= (tmp/10)*10;
x += 11; x += 7;
Out10x16Char((tmp)+0x30,x,y,r,g,b); Out6x8Char((tmp)+0x30,x,y,r,g,b);
} }
void drawTime(time_t t,uint8_t x=0,uint8_t y=0){ void drawTime(time_t t,uint8_t x=0,uint8_t y=0){
@@ -252,8 +268,8 @@ void showTime(time_t t,uint8_t x=12,uint8_t y=22){
uint16_t tmp = minute(t); uint16_t tmp = minute(t);
if(withSeconds){ if(withSeconds){
drawSeconds(t,x+62,y+8); drawSeconds(t,x+75,y+16);
x -= 11; x -= 6;
} }
if(lastminutes != tmp){ if(lastminutes != tmp){
@@ -375,8 +391,8 @@ void showTimeTactical(time_t t){
uint8_t x = 8; uint8_t x = 8;
uint8_t y = 22; uint8_t y = 22;
if(withSeconds){ if(withSeconds){
drawSeconds(t,x+62,y+8); drawSeconds(t,x+75,y+16);
x -= 11; x -= 6;
} }
if(lastminutes != tmp){ if(lastminutes != tmp){
@@ -460,12 +476,13 @@ void setup() {
mxconfig.i2sspeed = HUB75_I2S_CFG::HZ_10M; mxconfig.i2sspeed = HUB75_I2S_CFG::HZ_10M;
mxconfig.latch_blanking = 4; mxconfig.latch_blanking = 4;
mxconfig.min_refresh_rate = 50; mxconfig.min_refresh_rate = 50;
mxconfig.clkphase = false;
display = new MatrixPanel_I2S_DMA(mxconfig); display = new MatrixPanel_I2S_DMA(mxconfig);
display->begin(); display->begin();
display->setPanelBrightness(100); display->setPanelBrightness(100);
display->clearScreen(); display->clearScreen();
display->setFont(&TTHCENT8pt7b); display->setFont(&NT7x10);
EEPROM.begin(256); EEPROM.begin(256);
EEPROM.get(0, timeIndex); EEPROM.get(0, timeIndex);
@@ -500,10 +517,9 @@ void setup() {
EEPROM.get(101,ssid); EEPROM.get(101,ssid);
EEPROM.get(201,pass); EEPROM.get(201,pass);
EEPROM.get(151,appass); EEPROM.get(151,appass);
showNTOOLS(); showNTOOLS();
display->setCursor(1, 34); display->setCursor(16, 34);
display->print("bitte warten"); display->print("bitte warten");
Wire.begin(21,22); Wire.begin(21,22);
@@ -534,6 +550,7 @@ void setup() {
strcat(APName, ChipID); strcat(APName, ChipID);
WiFi.persistent(false); WiFi.persistent(false);
WiFi.setAutoReconnect(true);
WiFi.begin(ssid,pass); WiFi.begin(ssid,pass);
WiFi.hostname(NetName); WiFi.hostname(NetName);
int xc = 0; int xc = 0;
@@ -560,15 +577,21 @@ void setup() {
show5x7( 5, 2, localip, 255, 255, 255); show5x7( 5, 2, localip, 255, 255, 255);
display->drawPixelRGB888(2, 0, 0, 255, 0); display->drawPixelRGB888(2, 0, 0, 255, 0);
configTime(0,0, "ptbtime1.ptb.de", "ptbtime2.ptb.de", "ptbtime3.ptb.de"); configTime(0,0, "ptbtime1.ptb.de", "ptbtime2.ptb.de", "ptbtime3.ptb.de");
time_t timenow = time(nullptr); delay_ex(2000);
xc = 0; xc = 0;
while((timenow < SECS_YR_2000) && (xc < 10)) { sntp_sync_status_t syncStatus;
delay(1000); syncStatus = sntp_get_sync_status();
timenow = time(nullptr); while((syncStatus != SNTP_SYNC_STATUS_COMPLETED) && (xc < 40)) {
xc++; delay_ex(1000);
syncStatus = sntp_get_sync_status();
display->drawPixelRGB888(xc+17,0,255,255,0); display->drawPixelRGB888(xc+17,0,255,255,0);
xc++;
} }
if(timenow > SECS_YR_2000){ esp_sntp_stop();
if(syncStatus == SNTP_SYNC_STATUS_COMPLETED){
time_t timenow = time(nullptr);
timenow = time(nullptr);
timenow += 1; //Zeit korrektur
byte Month, Day, Hour; byte Month, Day, Hour;
setTime(timenow); setTime(timenow);
Month = month(timenow); Month = month(timenow);
@@ -587,10 +610,16 @@ void setup() {
EEPROM.put(10, savediDL); EEPROM.put(10, savediDL);
EEPROM.commit(); EEPROM.commit();
display->drawPixelRGB888(3,0,0,255,0); display->drawPixelRGB888(3,0,0,255,0);
lastTimeSyncTyp = 2;
lastTimeSyncTime = now();
}else{ }else{
display->drawPixelRGB888(3,0,255,0,255); display->drawPixelRGB888(3,0,255,0,255);
} }
delay(5000); for(uint8_t i=0;i<5;i++){
delay_ex(1000);
display->drawPixelRGB888(xc+17,0,0,255,0);
xc++;
}
}else{ }else{
display->drawPixelRGB888(2,0,255,0,0); display->drawPixelRGB888(2,0,255,0,0);
APEnabled = true; APEnabled = true;
@@ -603,6 +632,7 @@ void setup() {
WiFi.mode(WIFI_AP); WiFi.mode(WIFI_AP);
delay(100); delay(100);
WiFi.softAPConfig(ip_local, ip_gateway, ip_subnet); WiFi.softAPConfig(ip_local, ip_gateway, ip_subnet);
//APEnabled = WiFi.softAP(APName, "1234567890",2,0,1);
APEnabled = WiFi.softAP(APName, appass,2,0,1); APEnabled = WiFi.softAP(APName, appass,2,0,1);
if(!APEnabled) if(!APEnabled)
display->drawPixelRGB888(4,0,255,0,0); display->drawPixelRGB888(4,0,255,0,0);
@@ -622,19 +652,10 @@ void setup() {
webServer.on("/poll", HTTP_GET, [] (AsyncWebServerRequest *request) {html_poll(request);}); webServer.on("/poll", HTTP_GET, [] (AsyncWebServerRequest *request) {html_poll(request);});
webServer.begin(); webServer.begin();
delay(1000); delay(500);
display->setPanelBrightness(ceil(255 * brightness)); display->setPanelBrightness(ceil(255 * brightness));
display->clearScreen(); display->clearScreen();
/*display->setTextColor(display->color565(128,255,0));
display->setFont(&NT7x10);
display->setCursor(13, 11);
display->print("alles gute im");
display->setCursor(17, 22);
display->setTextColor(display->color565(255,0,0));
display->print("neuen heim");
*/
} }
void loop() { void loop() {
@@ -721,10 +742,10 @@ void html_poll(AsyncWebServerRequest *request) {
itoa(timeIndex,tempBuff,DEC); itoa(timeIndex,tempBuff,DEC);
strcat(ret,(char *)","); strcat(ret,(char *)",");
strcat(ret,tempBuff); strcat(ret,tempBuff);
itoa(lastTimeSyncTyp,tempBuff,DEC); itoa(lastTimeSyncTime,tempBuff,DEC);
strcat(ret,(char *)","); strcat(ret,(char *)",");
strcat(ret,tempBuff); strcat(ret,tempBuff);
itoa(lastTimeSyncTime,tempBuff,DEC); itoa(lastTimeSyncTyp,tempBuff,DEC);
strcat(ret,(char *)","); strcat(ret,(char *)",");
strcat(ret,tempBuff); strcat(ret,tempBuff);
dtostrf(brightness, 10, 2, tempBuff); dtostrf(brightness, 10, 2, tempBuff);

View File

@@ -1,4 +1,4 @@
const char html_page_index[] PROGMEM = R"rawliteral( static const char *html_page_index PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html> <!DOCTYPE HTML><html>
<head> <head>
<title>N-Tools.de Uhr</title> <title>N-Tools.de Uhr</title>
@@ -389,7 +389,8 @@ const char html_page_index[] PROGMEM = R"rawliteral(
document.getElementById('actDate').style.color = colorString; document.getElementById('actDate').style.color = colorString;
document.getElementById('showWhat').value = parseInt(data[4]); document.getElementById('showWhat').value = parseInt(data[4]);
switch(data[5]){ showTimeFromUnix(data[5],'sync');
switch(data[6]){
case 0: case 0:
document.getElementById('sync').innerHTML = " keiner"; document.getElementById('sync').innerHTML = " keiner";
break; break;
@@ -403,7 +404,7 @@ const char html_page_index[] PROGMEM = R"rawliteral(
document.getElementById('sync').innerHTML += " (manuel)"; document.getElementById('sync').innerHTML += " (manuel)";
break; break;
} }
showTimeFromUnix(data[6],'sync');
document.getElementById('brigtness').innerHTML = (data[7]*100); document.getElementById('brigtness').innerHTML = (data[7]*100);
document.getElementById("rtcactive").checked = (data[8] == 1); document.getElementById("rtcactive").checked = (data[8] == 1);