From 04e2975cb1da0e94debdb5292df729a9d04d8222 Mon Sep 17 00:00:00 2001 From: "NTEN\\Nenninger" Date: Wed, 28 Dec 2022 23:07:31 +0100 Subject: [PATCH] 2022 / 12 --- ESPNTUhrPx.ino | 777 +++++++++++++++++++++++++++++++++++++------------ index_html.h | 259 +++++++++-------- 2 files changed, 738 insertions(+), 298 deletions(-) diff --git a/ESPNTUhrPx.ino b/ESPNTUhrPx.ino index f26e832..336ffdb 100644 --- a/ESPNTUhrPx.ino +++ b/ESPNTUhrPx.ino @@ -1,4 +1,4 @@ -#define VERSION "V2.4" +#define VERSION (char *) "V2.11" // Pins for LED MATRIX #include @@ -10,7 +10,7 @@ #define P_D 0 //#define P_E 0 #define P_OE 2 - //#define PxMATRIX_COLOR_DEPTH 4 // This is how many color levels the display shows - the more the slower the update + #define PxMATRIX_COLOR_DEPTH 3 // This is how many color levels the display shows - the more the slower the update #define double_buffer // Creates a second buffer for backround drawing (doubles the required RAM) #define MATRIX_WIDTH 64 #define MATRIX_HEIGHT 32 @@ -18,51 +18,48 @@ #include "PxMatrix.h" PxMATRIX display(64,32,P_LAT, P_OE,P_A,P_B,P_C,P_D); - uint8_t display_draw_time=5; //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 + 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 ... + #define TEMPLATE_PLACEHOLDER '`' //-> Damit % in CSS funktioniert muss in der .h geändert werden!!! ... #include #include #include -//#include +#include +#include AsyncWebServer webServer(80); - //DNSServer dnsServer; + DNSServer dnsServer; IPAddress ip_local(192, 168, 13, 1); - IPAddress ip_gateway(0, 0, 0, 0); + IPAddress ip_gateway(192, 168, 13, 1); IPAddress ip_subnet(255, 255, 255, 0); boolean APEnabled = false; char ssid[30] = "THW Freifunk"; char pass[30] = ""; - - //WiFiMulti.addAP("THW Freifunk", ""); // THW - //WiFiMulti.addAP("ic_lg", "DEADBEEF!aaaa"); //Firma - //WiFiMulti.addAP("NTW", "!TJDn@Wb868"); // daheim + char appass[30] = "gibteskeins"; //permanenter Speicher #include -String ChipID = "ERROR"; +char ChipID[10] = "ERROR"; //i2c #include #include RV3029 rtc; const int PINRTC_CLOCK = 12; boolean rtcEnabled = false; + uint8_t temperature=0; #include +#include long ti_second = 0; - String timeColor = "ffffff"; - String tacticalTimeColor = "FFFF00"; //4D4DFF - String dateColor = "ffffff"; - uint8_t timeCr = 0; - uint8_t timeCg = 0; - uint8_t timeCb = 0; - uint8_t tacCr = 0; - uint8_t tacCg = 0; - uint8_t tacCb = 0; + + uint8_t timeColor[3] = {0xff,0xff,0xff}; + uint8_t tacticalTimeColor[3] = {0x88,0xff,0x00}; + uint8_t dateColor[3] {0x10,0xff,0x00}; + uint8_t kwColor[3] {0x10,0xff,0x00}; + float brightness = 0.80; int8_t lastminutes = -1; @@ -74,6 +71,9 @@ String ChipID = "ERROR"; uint8_t timeIndex = 0; bool EEPROMDataNotSaved = false; + uint8_t options = 0; + bool withSeconds = true; + bool alwaysAccessPoint = true; // ISR for display refresh void display_updater(){ @@ -124,10 +124,10 @@ void LineV(uint8_t x, uint8_t y, uint8_t z, uint8_t red, uint8_t green, uint8_t #include "D:\arduino\Projekte\_includes\char6x8.h" #include "D:\arduino\Projekte\_includes\char10x16.h" -void doClearLEDsSeconds(){ +void doClearLEDsSeconds(int8_t ycorrection=0){ for(uint8_t x=0;x<5;x++){ - display.drawFastHLine(56,26+x,7,0); + display.drawFastHLine(56,26 + x + ycorrection, 7, 0); } /*for(uint16_t x=56;x 59) x--; - x += Out5x7Char((tmp)+0x30,x,y,tacCr,tacCg,tacCb); + x += Out5x7Char((tmp)+0x30,x,y,r,g,b); return x; } +void drawTime(time_t t,int8_t ycorrection=0){ + uint16_t tmp = 0; + uint8_t x = 9; + uint8_t y = 15 + ycorrection; + + uint8_t r = timeColor[0]; + uint8_t g = timeColor[1]; + uint8_t b = timeColor[2]; + + tmp = hour(t); + + if((tmp/10 > 0)){ + Out10x16Char((tmp/10)+0x30,x,y,r,g,b); + tmp -= (tmp/10)*10; + } + x += 11; + Out10x16Char((tmp)+0x30,x,y,r,g,b); + Out10x16Char(':',x+11,y,r,g,b); + x += 14; + tmp = minute(t); + Out10x16Char((tmp/10)+0x30,x,y,r,g,b); + tmp -= (tmp/10)*10; + x += 11; + Out10x16Char((tmp)+0x30,x,y,r,g,b); +} + +void drawSeconds(time_t t,int8_t ycorrection=0){ + uint16_t tmp = 0; + uint8_t x = 56; + uint8_t y = 15 + ycorrection; + + uint8_t r = timeColor[0]; + uint8_t g = timeColor[1]; + uint8_t b = timeColor[2]; + + doClearLEDsSeconds(ycorrection); + + tmp = second(t); + Out3x5Char((tmp/10)+0x30,x,y+11,r,g,b); + tmp -= (tmp/10)*10; + x += 4; + Out3x5Char((tmp)+0x30,x,y+11,r,g,b); +} + void showTimeTactical(time_t t){ uint16_t tmp = 0; uint8_t x = 0; uint8_t y = 0; + + uint8_t r = timeColor[0]; + uint8_t g = timeColor[1]; + uint8_t b = timeColor[2]; tmp = minute(t); if(lastminutes != tmp){ @@ -295,36 +362,250 @@ void showTimeTactical(time_t t){ drawTactical(t,x_tactical+1,3); } //Uhrzeit - x = 9; - y = 15; - tmp = hour(t); - - if((tmp/10 > 0)){ - Out10x16Char((tmp/10)+0x30,x,y,timeCr,timeCg,timeCb); - tmp -= (tmp/10)*10; - } - x += 11; - Out10x16Char((tmp)+0x30,x,y,timeCr,timeCg,timeCb); - Out10x16Char(':',x+11,y,timeCr,timeCg,timeCb); - x += 14; - tmp = minute(t); - Out10x16Char((tmp/10)+0x30,x,y,timeCr,timeCg,timeCb); - tmp -= (tmp/10)*10; - - x += 11; - Out10x16Char((tmp)+0x30,x,y,timeCr,timeCg,timeCb); - x += 11; - }else{ - doClearLEDsSeconds(); - x = 56; - y = 15; + drawTime(t); } - - tmp = second(t); - Out3x5Char((tmp/10)+0x30,x,y+11,timeCr,timeCg,timeCb); + if(withSeconds) + drawSeconds(t); +} + +void showTime(time_t t){ + uint16_t tmp = 0; + uint8_t x = 0; + uint8_t y = 0; + + uint8_t r = timeColor[0]; + uint8_t g = timeColor[1]; + uint8_t b = timeColor[2]; + + tmp = minute(t); + if(lastminutes != tmp){ + lastminutes = tmp; + doClearLEDs(); + //Uhrzeit + drawTime(t,-7); + } + if(withSeconds) + drawSeconds(t,-7); +} + +void drawDate(time_t t){ + uint8_t r = dateColor[0]; + uint8_t g = dateColor[1]; + uint8_t b = dateColor[2]; + uint8_t x = 2; + uint8_t y = 3; + + UnixTime stamp(0); + stamp.getDateTime(t); + switch(stamp.dayOfWeek){ + case 1: + x += Out5x7Char('M',x,y,r,g,b)+1; + x += Out5x7Char('o',x,y,r,g,b)+1; + break; + case 2: + x += Out5x7Char('D',x,y,r,g,b)+1; + x += Out5x7Char('i',x,y,r,g,b)+1; + break; + case 3: + x += Out5x7Char('M',x,y,r,g,b)+1; + x += Out5x7Char('i',x,y,r,g,b)+1; + break; + case 4: + x += Out5x7Char('D',x,y,r,g,b)+1; + x += Out5x7Char('o',x,y,r,g,b)+1; + break; + case 5: + x += Out5x7Char('F',x,y,r,g,b)+1; + x += Out5x7Char('r',x,y,r,g,b)+1; + break; + case 6: + x += Out5x7Char('S',x,y,r,g,b)+1; + x += Out5x7Char('a',x,y,r,g,b)+1; + break; + case 7: + x += Out5x7Char('S',x,y,r,g,b)+1; + x += Out5x7Char('o',x,y,r,g,b)+1; + break; + } + + x = 13; + + uint16_t tmp = day(t); + x += Out5x7Char((tmp/10)+0x30,x,y,r,g,b)+1; tmp -= (tmp/10)*10; - x += 4; - Out3x5Char((tmp)+0x30,x,y+11,timeCr,timeCg,timeCb); + x += Out5x7Char((tmp)+0x30,x,y,r,g,b)+1; + x += Out5x7Char('.',x,y,r,g,b)+1; + + tmp = month(t); + x += Out5x7Char((tmp/10)+0x30,x,y,r,g,b)+1; + tmp -= (tmp/10)*10; + x += Out5x7Char((tmp)+0x30,x,y,r,g,b)+1; + x += Out5x7Char('.',x,y,r,g,b)+1; + + tmp = year(t); + x += Out5x7Char((tmp/1000)+0x30,x,y,r,g,b)+1; + tmp -= (tmp/1000)*1000; + x += Out5x7Char((tmp/100)+0x30,x,y,r,g,b)+1; + tmp -= (tmp/100)*100; + x += Out5x7Char((tmp/10)+0x30,x,y,r,g,b)+1; + tmp -= (tmp/10)*10; + x += Out5x7Char((tmp)+0x30,x,y,r,g,b)+1; +} + +void showDateTime(time_t t){ + doClearLEDs(); + drawDate(t); + drawTime(t); + if(withSeconds) + drawSeconds(t); +} + +uint8_t clock_center_x = 16; +uint8_t clock_center_y = 15; +uint8_t clock_radius = 15; + +uint16_t ACcolor = display.color565(255, 255, 255); +uint16_t ACcolorBlk = display.color565(0, 0, 0); + +void drawAnalogSecond(int second){ + //uint y = ((clock_radius-1)*cos(PI -(2*PI )/60*second))+clock_center_y; + //uint x = ((clock_radius-1)*sin(PI -(2*PI )/60*second))+clock_center_x; + //display.drawCircle(x, y, 1, 0x0ff000); + uint y = ((clock_radius)*cos(PI-(2*PI)/60*second))+clock_center_y; + uint x = ((clock_radius)*sin(PI-(2*PI)/60*second))+clock_center_x; + display.drawLine(clock_center_x,clock_center_y,x,y,display.color565(255, 0, 0)); +} + +void drawAnalogMinute(int minute){ + uint y = ((clock_radius-1)*cos(PI-(2*PI)/60*minute))+clock_center_y; + uint x = ((clock_radius-1)*sin(PI-(2*PI)/60*minute))+clock_center_x; + display.drawLine(clock_center_x,clock_center_y,x,y,display.color565(0, 0, 255)); +} + +void drawAnalogHour(int hour, int minute){ + + uint y = ((clock_radius-4)*cos(PI-(2*PI)/12*hour-(2*PI)/720*minute))+clock_center_y; + uint x = ((clock_radius-4)*sin(PI-(2*PI)/12*hour-(2*PI)/720*minute))+clock_center_x; + //uint y1 = ((clock_radius-4)*cos(PI-(2*PI)/12*hour-(2*PI)/720*minute))+clock_center_y+1; + //uint x1 = ((clock_radius-4)*sin(PI-(2*PI)/12*hour-(2*PI)/720*minute))+clock_center_x+1; + uint y2 = ((clock_radius-4)*cos(PI-(2*PI)/12*hour-(2*PI)/720*minute))+clock_center_y-1; + uint x2 = ((clock_radius-4)*sin(PI-(2*PI)/12*hour-(2*PI)/720*minute))+clock_center_x-1; + display.drawLine(clock_center_x,clock_center_y,x,y,display.color565(88, 255, 0)); + //display.drawLine(clock_center_x+1,clock_center_y+1,x1,y1,display.color565(88, 255, 0)); + display.drawLine(clock_center_x-1,clock_center_y-1,x2,y2,display.color565(88, 255, 0)); +} + +void drawAnalogFace(void){ + // draw the center of the clock + //display.drawCircle(clock_center_x, clock_center_y,3, ACcolor); + display.fillCircle(clock_center_x, clock_center_y,2, ACcolor); + + // draw hour pointers around the face of a clock + for (int i=0;i<12;i++){ + uint y = ((clock_radius)*cos(PI-(2*PI)/12*i))+clock_center_y; + uint x = ((clock_radius)*sin(PI-(2*PI)/12*i))+clock_center_x; + uint y1 = ((clock_radius-3)*cos(PI-(2*PI)/12*i))+clock_center_y; + uint x1 = ((clock_radius-3)*sin(PI-(2*PI)/12*i))+clock_center_x; + if(i==1) + x1 -= 1; + if(i==2) + y1 += 1; + if(i==4) + y1 -= 1; + if(i==5) + x1 -= 1; + if(i==8) + y += 1; + if(i==11) + x1 += 1; + display.drawLine(x1,y1,x,y,ACcolor); + } + display.drawLine(clock_center_x,clock_center_y-clock_radius,clock_center_x,clock_center_y-clock_radius-4,ACcolor); +} + +void showAnalogDate(time_t t){ + uint8_t r = dateColor[0]; + uint8_t g = dateColor[1]; + uint8_t b = dateColor[2]; + uint8_t x = 41; + uint8_t y = 1; + + UnixTime stamp(0); + stamp.getDateTime(t); + switch(stamp.dayOfWeek){ + case 1: + show5x7(x,y,(char *)"Mo",r,g,b); + break; + case 2: + show5x7(x,y,(char *)"Di",r,g,b); + break; + case 3: + show5x7(x,y,(char *)"Mi",r,g,b); + break; + case 4: + show5x7(x,y,(char *)"Do",r,g,b); + break; + case 5: + show5x7(x,y,(char *)"Fr",r,g,b); + break; + case 6: + show5x7(x,y,(char *)"Sa",r,g,b); + break; + case 7: + show5x7(x,y,(char *)"So",r,g,b); + break; + } + + x = 36; + y = 10; + + uint16_t tmp = day(t); + x += Out5x7Char((tmp/10)+0x30,x,y,r,g,b)+1; + tmp -= (tmp/10)*10; + x += Out5x7Char((tmp)+0x30,x,y,r,g,b)+1; + x += Out5x7Char('.',x,y,r,g,b)+1; + + tmp = month(t); + x += Out5x7Char((tmp/10)+0x30,x,y,r,g,b)+1; + tmp -= (tmp/10)*10; + x += Out5x7Char((tmp)+0x30,x,y,r,g,b)+1; + x += Out5x7Char('.',x,y,r,g,b)+1; + + x = 36; + y = 24; + tmp = year(t); + x += Out5x7Char((tmp/1000)+0x30,x,y,r,g,b)+1; + tmp -= (tmp/1000)*1000; + x += Out5x7Char((tmp/100)+0x30,x,y,r,g,b)+1; + tmp -= (tmp/100)*100; + x += Out5x7Char((tmp/10)+0x30,x,y,r,g,b)+1; + tmp -= (tmp/10)*10; + x += Out5x7Char((tmp)+0x30,x,y,r,g,b)+1; + + uint8_t kw = GetWeekNumber(year(t),month(t),day(t)); + char str[6]; + char kws[3]; + itoa(kw,kws,10); + strcpy(str, "KW "); + strcat(str, kws); + + show3x5(38,18,str,kwColor[0],kwColor[1],kwColor[2]); +} + +void showAnalogTime(time_t t){ + doClearLEDs(); + uint16_t tmp = 0; + uint16_t tmp2 = 0; + // + drawAnalogFace(); + tmp = minute(t); + tmp2 = hour(t); + drawAnalogHour(tmp2,tmp); + drawAnalogMinute(tmp); + if(withSeconds){ + tmp = second(t); + drawAnalogSecond(tmp); + } } void doSetTime(unsigned long t){ @@ -367,24 +648,46 @@ void display_doupdate(void){ } void setup() { - ChipID = String(ESP.getChipId()); + ultoa(ESP.getChipId(),ChipID,10); + + EEPROM.begin(256); + EEPROM.get(0, timeIndex); + EEPROM.get(1, options); + withSeconds = bitRead(options,0); + alwaysAccessPoint = bitRead(options,1); + + EEPROM.get(5, brightness); + if(brightness < 0.10) + brightness = 0.10; + if(brightness > 1.0) + brightness = 1.0; + + timeColor[0] = EEPROM.read(11); + timeColor[1] = EEPROM.read(12); + timeColor[2] = EEPROM.read(13); + + tacticalTimeColor[0] = EEPROM.read(21); + tacticalTimeColor[1] = EEPROM.read(22); + tacticalTimeColor[2] = EEPROM.read(23); + + dateColor[0] = EEPROM.read(31); + dateColor[1] = EEPROM.read(32); + dateColor[2] = EEPROM.read(33); + + kwColor[0] = EEPROM.read(41); + kwColor[1] = EEPROM.read(42); + kwColor[2] = EEPROM.read(43); + + EEPROM.get(101,ssid); + EEPROM.get(201,pass); + EEPROM.get(151,appass); + display.begin(16); - //display.setFlip(true); - display.setBrightness(255); - //display.setBrightness(ceil(255 * brightness)); + //display.setBrightness(255); + display.setBrightness(ceil(255 * brightness)); display.setFastUpdate(true); doClearLEDs(true); - uint32_t color = strtol(timeColor.c_str(), 0, 16); - timeCr = color >> 16; - timeCg = color >> 8; - timeCb = color; - - color = strtol(tacticalTimeColor.c_str(), 0, 16); - tacCr = color >> 16; - tacCg = color >> 8; - tacCb = color; - showOVALZ(); showNTOOLS(); display_update_enable(true); @@ -412,11 +715,16 @@ void setup() { WDay = weekday(); iDL = isDayLight(Hour,Day,WDay,Month); } - - String newHostname = "NTUVPx"+String(ChipID); + + char NetName[30]; + strcpy(NetName, "NTUVPx"); + strcat(NetName, ChipID); + char APName[30]; + strcpy(APName, "NTUhr VPx "); + strcat(APName, ChipID); WiFi.begin(ssid,pass); - WiFi.hostname(newHostname.c_str()); + WiFi.hostname(NetName); int xc = 0; while ((WiFi.status() != WL_CONNECTED) && (xc < 10)) { delay(1500); @@ -425,7 +733,23 @@ void setup() { display_doupdate(); } if (WiFi.status() == WL_CONNECTED) { - display.drawPixelRGB888(1,0,0,255,0); + char localip[16]; + char str[5]; + IPAddress lip; + lip = WiFi.localIP(); + itoa(lip[0],str,10); + strcpy(localip, str); + strcat(localip, "."); + itoa(lip[1],str,10); + strcat(localip, str); + strcat(localip, "."); + itoa(lip[2],str,10); + strcat(localip, str); + strcat(localip, "."); + itoa(lip[3],str,10); + strcat(localip, str); + show3x5( 10, 13, localip, 100, 255, 0); + 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); @@ -456,49 +780,57 @@ void setup() { doSetTime(timenow); } lastTimeSyncTyp = 2; - lastTimeSyncTime = now(); + lastTimeSyncTime = timenow; display.drawPixelRGB888(2,0,0,255,0); display_doupdate(); }else{ display.drawPixelRGB888(2,0,255,0,255); display_doupdate(); } - //WiFi.localIP() + delay(5000); }else{ display.drawPixelRGB888(1,0,255,0,0); display_doupdate(); + alwaysAccessPoint = true; + } + + if(alwaysAccessPoint){ WiFi.disconnect(); - delay(3000); - + delay(1000); ESP.eraseConfig(); + delay(1000); WiFi.mode(WIFI_OFF); WiFi.mode(WIFI_AP); + delay(1000); WiFi.softAPConfig(ip_local, ip_gateway, ip_subnet); - APEnabled = WiFi.softAP("NTUhr VPx "+ChipID, "gibteskeins"); - } + //appass = ; + APEnabled = WiFi.softAP(APName, appass,2,0,1); + if(!APEnabled) + display.drawPixelRGB888(3,0,255,0,0); + else + display.drawPixelRGB888(3,0,0,255,0); + dnsServer.setErrorReplyCode(DNSReplyCode::NoError); + dnsServer.start(53, "*", ip_local); + }else{ + display.drawPixelRGB888(3,0,0,0,0); + } - - if(!APEnabled) - display.drawPixelRGB888(3,0,255,0,0); - else - display.drawPixelRGB888(3,0,0,255,0); display_doupdate(); - - //dnsServer.setErrorReplyCode(DNSReplyCode::NoError); - //dnsServer.start(53, "*", ip_local); //für die automatische Umleitung - /*webServer.on("/generate_204", HTTP_GET, [](AsyncWebServerRequest *request){html_redirect(request);}); //Android captive portal. + webServer.on("/generate_204", HTTP_GET, [](AsyncWebServerRequest *request){html_redirect(request);}); //Android captive portal. webServer.on("/fwlink", HTTP_GET, [](AsyncWebServerRequest *request){html_redirect(request);}); //Microsoft captive portal. - webServer.on("/favicon.ico", HTTP_GET, [](AsyncWebServerRequest *request){html_redirect(request);}); webServer.on("/connecttest.txt", HTTP_GET, [](AsyncWebServerRequest *request){html_redirect(request);}); //www.msftconnecttest.com webServer.on("/hotspot-detect.html", HTTP_GET, [](AsyncWebServerRequest *request){html_redirect(request);}); //captive.apple.com webServer.on("/success.txt", HTTP_GET, [](AsyncWebServerRequest *request){html_handle_success(request);}); //detectportal.firefox.com/sucess.txt webServer.onNotFound([](AsyncWebServerRequest *request){html_redirect(request);}); - */ + //eigene Seiten webServer.on("/", HTTP_GET, [](AsyncWebServerRequest *request){html_root(request);}); webServer.on("/do", HTTP_GET, [] (AsyncWebServerRequest *request) {html_do(request);}); + webServer.on("/poll", HTTP_GET, [] (AsyncWebServerRequest *request) {html_poll(request);}); + + AsyncElegantOTA.begin(&webServer); // Start AsyncElegantOTA webServer.begin(); if(rtcEnabled) @@ -536,20 +868,38 @@ void loop(){ if((WDay == 1) && (Hour == 3) && (Minute == 1) && (Second == 0)){ ESP.restart(); } - showTimeTactical(currentUNIXTime); + switch(timeIndex){ + case 0: + showTimeTactical(currentUNIXTime); + break; + case 1: + showTime(currentUNIXTime); + break; + case 2: + showDateTime(currentUNIXTime); + break; + case 3: + clock_center_x = 32; + showAnalogTime(currentUNIXTime); + break; + case 4: + clock_center_x = 16; + showAnalogTime(currentUNIXTime); + showAnalogDate(currentUNIXTime); + break; + } + display_doupdate(); } + rtc.getTEMPERATURE(&temperature); } - //dnsServer.processNextRequest(); + dnsServer.processNextRequest(); //yield(); - //display.copyBuffer(); } //alles was WEB ist ... - #include "index_html.h" const char* PARAM_SET = "set"; -const char* PARAM_POLL = "poll"; const char* PARAM_SAVE = "save"; const char* PARAM_TO = "to"; const char* PARAM_SHOWWHAT = "showWhat"; @@ -563,6 +913,74 @@ void html_root(AsyncWebServerRequest *request) { request->send_P(200, "text/html", html_page_index, html_processor); } +void html_poll(AsyncWebServerRequest *request) { + long color = 0; + char ret[250]; + char tempBuff[30]; + strcpy(ret,(char *)"["); + ltoa(now(),tempBuff,DEC); + strcat(ret,tempBuff); + color = timeColor[0] << 16; + color += timeColor[1] << 8; + color += timeColor[2]; + itoa(color,tempBuff,DEC); + strcat(ret,(char *)","); + strcat(ret,tempBuff); + color = tacticalTimeColor[0] << 16; + color += tacticalTimeColor[1] << 8; + color += tacticalTimeColor[2]; + itoa(color,tempBuff,DEC); + strcat(ret,(char *)","); + strcat(ret,tempBuff); + color = dateColor[0] << 16; + color += dateColor[1] << 8; + color += dateColor[2]; + itoa(color,tempBuff,DEC); + strcat(ret,(char *)","); + strcat(ret,tempBuff); + itoa(timeIndex,tempBuff,DEC); + strcat(ret,(char *)","); + strcat(ret,tempBuff); + itoa(lastTimeSyncTyp,tempBuff,DEC); + strcat(ret,(char *)","); + strcat(ret,tempBuff); + itoa(lastTimeSyncTime,tempBuff,DEC); + strcat(ret,(char *)","); + strcat(ret,tempBuff); + dtostrf(brightness, 10, 2, tempBuff); + strcat(ret,(char *)",\""); + strcat(ret,tempBuff); + strcat(ret,(char *)"\""); + itoa(rtcEnabled,tempBuff,DEC); + strcat(ret,(char *)","); + strcat(ret,tempBuff); + itoa(EEPROMDataNotSaved,tempBuff,DEC); + strcat(ret,(char *)","); + strcat(ret,tempBuff); + strcat(ret,(char *)",\""); + strcat(ret,ssid); + strcat(ret,(char *)"\""); + dtostrf(temperature, 10, 2, tempBuff); + strcat(ret,(char *)",\""); + strcat(ret,tempBuff); + strcat(ret,(char *)"\""); + itoa(options,tempBuff,DEC); + strcat(ret,(char *)","); + strcat(ret,tempBuff); + color = kwColor[0] << 16; + color += kwColor[1] << 8; + color += kwColor[2]; + itoa(color,tempBuff,DEC); + strcat(ret,(char *)","); + strcat(ret,tempBuff); + uint8_t kw = GetWeekNumber(year(now()),month(now()),day(now())); + itoa(kw,tempBuff,DEC); + strcat(ret,(char *)","); + strcat(ret,tempBuff); + strcat(ret,(char *)"]"); + request->send(200, "text/plain", ret); +} + void html_do(AsyncWebServerRequest *request) { String s_set,s_value,s_idx,s_value2; uint32_t l_value; @@ -578,7 +996,8 @@ void html_do(AsyncWebServerRequest *request) { s_value = request->getParam(PARAM_SHOWWHAT)->value(); timeIndex = s_value.toInt(); EEPROM.put(0, timeIndex); - }else if(((s_set == "color") | (s_set == "tcolor") | (s_set == "dcolor")) & (request->hasParam(PARAM_TO))) { + EEPROMDataNotSaved = true; + }else if(((s_set == "color") | (s_set == "tcolor") | (s_set == "dcolor") | (s_set == "kwcolor")) & (request->hasParam(PARAM_TO))) { s_value = request->getParam(PARAM_TO)->value(); uint8_t c[3]; l_value = strtol(s_value.c_str(), NULL, 16); @@ -592,6 +1011,7 @@ void html_do(AsyncWebServerRequest *request) { EEPROM.write(11,timeColor[0]); EEPROM.write(12,timeColor[1]); EEPROM.write(13,timeColor[2]); + EEPROMDataNotSaved = true; }else if(s_set == "tcolor"){ tacticalTimeColor[0] = c[0]; tacticalTimeColor[1] = c[1]; @@ -599,73 +1019,66 @@ void html_do(AsyncWebServerRequest *request) { EEPROM.write(21,tacticalTimeColor[0]); EEPROM.write(22,tacticalTimeColor[1]); EEPROM.write(23,tacticalTimeColor[2]); + EEPROMDataNotSaved = true; }else if(s_set == "dcolor"){ - /*dateColor[0] = c[0]; + dateColor[0] = c[0]; dateColor[1] = c[1]; dateColor[2] = c[2]; EEPROM.write(31,dateColor[0]); EEPROM.write(32,dateColor[1]); - EEPROM.write(33,dateColor[2]);*/ + EEPROM.write(33,dateColor[2]); + EEPROMDataNotSaved = true; + }else if(s_set == "kwcolor"){ + kwColor[0] = c[0]; + kwColor[1] = c[1]; + kwColor[2] = c[2]; + EEPROM.write(41,kwColor[0]); + EEPROM.write(42,kwColor[1]); + EEPROM.write(43,kwColor[2]); + EEPROMDataNotSaved = true; } }else if((s_set == "option")) { if(request->hasParam(PARAM_BRIGHTNESS)) { s_value = request->getParam(PARAM_BRIGHTNESS)->value(); brightness = s_value.toFloat(); EEPROM.put(5,brightness); - //display.setBrightness(ceil(255 * brightness)); + EEPROMDataNotSaved = true; + display.setBrightness(ceil(255 * brightness)); } if(request->hasParam(PARAM_OPTIONS)) { s_value = request->getParam(PARAM_OPTIONS)->value(); - //options = s_value.toInt(); - //EEPROM.put(1,options); - //autobrightness = bitRead(options,0); + options = s_value.toInt(); + EEPROM.put(1,options); + EEPROMDataNotSaved = true; + withSeconds = bitRead(options,0); + alwaysAccessPoint = bitRead(options,1); } }else if((s_set == "wifi")) { if((request->hasParam(PARAM_SSID)) && (request->hasParam(PARAM_PWD))){ s_value = request->getParam(PARAM_SSID)->value(); - if(s_value != ssid){ + s_value2 = request->getParam(PARAM_PWD )->value(); + if((s_value != ssid) || (s_value2 != pass)){ s_value.toCharArray(ssid, 30); - s_value = request->getParam(PARAM_PWD )->value(); - s_value.toCharArray(pass, 30); + s_value2.toCharArray(pass, 30); EEPROM.put(101,ssid); EEPROM.put(201,pass); + EEPROMDataNotSaved = true; + } + + } + }else if((s_set == "appass")) { + if(request->hasParam(PARAM_PWD)){ + s_value2 = request->getParam(PARAM_PWD )->value(); + if((s_value2 != appass)){ + s_value2.toCharArray(appass, 30); + EEPROM.put(151,appass); + EEPROMDataNotSaved = true; } } } request->send(200, "text/plain", "OK"); - EEPROMDataNotSaved = true; lastminutes = -1; - }else if(request->hasParam(PARAM_POLL)) { - long color = 0; - String ret = "[" - +String(now()); - color = timeColor[0] << 16; - color += timeColor[1] << 8; - color += timeColor[2]; - ret += "," + String(color); - color = tacticalTimeColor[0] << 16; - color += tacticalTimeColor[1] << 8; - color += tacticalTimeColor[2]; - ret += "," + String(color); - color = dateColor[0] << 16; - color += dateColor[1] << 8; - color += dateColor[2]; - ret += "," + String(color); - ret += "," + String(timeIndex); - ret += "," + String(lastTimeSyncTyp); - ret += "," + String(lastTimeSyncTime); - ret += ",\"0.0\""; - ret += ",\"" + String(brightness)+"\""; - ret += "," + String("0"); - ret += "," + String(rtcEnabled); - ret += "," + String("0"); - ret += "," + String("0"); - ret += "," + String("0"); - ret += "," + String(EEPROMDataNotSaved); - ret += ",\"" + String(ssid)+"\""; - ret += "]"; - request->send(200, "text/plain", ret); }else if (request->hasParam(PARAM_SAVE)){ EEPROM.commit(); EEPROMDataNotSaved = false; @@ -679,13 +1092,13 @@ void html_do(AsyncWebServerRequest *request) { } // Replaces placeholder with button section in your web page -String html_processor(const String& var){ +char * html_processor(const String& var){ if(var == "VERSION"){ - return String(VERSION); + return VERSION; }else if(var == "ID"){ - return String(ChipID); + return ChipID; } - return String(); + return (char *) "not defined"; } String toggleState(int toggle){ @@ -706,12 +1119,12 @@ String toStringIp(IPAddress ip) { return res; } -void redirect(AsyncWebServerRequest *request){ +void html_redirect(AsyncWebServerRequest *request){ AsyncWebServerResponse *response = request->beginResponse(302, "text/plain", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves. response->addHeader("Location", String("http://") + toStringIp(ip_local)); request->send(response); } -void handle_success(AsyncWebServerRequest *request){ +void html_handle_success(AsyncWebServerRequest *request){ request->send(200, "text/plain", "success"); } diff --git a/index_html.h b/index_html.h index 7cc3ad0..be1023b 100644 --- a/index_html.h +++ b/index_html.h @@ -10,9 +10,9 @@ const char html_page_index[] PROGMEM = R"rawliteral( body {font-size: 1.5rem; margin:0px auto; padding-bottom: 25px; min-height:100%;} body * {font-size: 1.3rem;} input[type=checkbox]{ - transform: scale(1.5); - padding: 10px; - position: relative; + transform: scale(1.5); + padding: 10px; + position: relative; } label {min-width: 150px;display: inline-block;text-align: left; padding-left: 5px;} input,select,option { display: inline-block;text-align:center;} @@ -142,10 +142,8 @@ const char html_page_index[] PROGMEM = R"rawliteral( width: 100%; padding: 0.25rem 0.5rem; @media(min-width: 600px) { - - margin: 0 1em 2em; - - } + margin: 0 1em 2em; + } &:hover { text-decoration: none; } @@ -185,7 +183,8 @@ const char html_page_index[] PROGMEM = R"rawliteral(


- +
+
@@ -199,14 +198,20 @@ const char html_page_index[] PROGMEM = R"rawliteral( + +
- - %
- - LUX
-
+ + + %
+
+ + + ° C
+
+
@@ -218,6 +223,14 @@ const char html_page_index[] PROGMEM = R"rawliteral( + + + + + + + +
@@ -226,25 +239,37 @@ const char html_page_index[] PROGMEM = R"rawliteral(
-
-
+
+
X




+



-
+
X

Optionen

- % + %
+ + + + + + + + +
+ +

@@ -255,7 +280,14 @@ const char html_page_index[] PROGMEM = R"rawliteral(
-
+ +

+ + + + +
+
@@ -296,6 +328,7 @@ const char html_page_index[] PROGMEM = R"rawliteral( document.getElementById("eActTimeC").value = RGBToHex(document.getElementById('actTime').style.color); document.getElementById("eActTacTimeC").value = RGBToHex(document.getElementById('actTacTime').style.color); document.getElementById("eActDateC").value = RGBToHex(document.getElementById('actDate').style.color); + document.getElementById("eActKWC").value = RGBToHex(document.getElementById('actKW').style.color); } document.getElementById("te").style.display = "initial"; } @@ -305,10 +338,11 @@ const char html_page_index[] PROGMEM = R"rawliteral( } function editOption(){ - document.getElementById('ebs').value = document.getElementById('brigtness').innerHTML; - document.getElementById('eSSID').value = document.getElementById('SSID').innerHTML; - - document.getElementById("oe").style.display = "initial"; + document.getElementById('ebs').value = document.getElementById('brigtness').innerHTML; + document.getElementById('eSSID').value = document.getElementById('SSID').innerHTML; + document.getElementById("eWithSeconds").checked = document.getElementById("withSeconds").checked; + document.getElementById("eAlwaysAccessPoint").checked = document.getElementById("alwaysAccessPoint").checked; + document.getElementById("oe").style.display = "initial"; } Number.prototype.AddZero= function(b,c){ @@ -317,52 +351,26 @@ const char html_page_index[] PROGMEM = R"rawliteral( } function showOK(){ - document.getElementById("message").innerHTML='ok'; - document.getElementById("message").style.backgroundColor = "#0f0"; - document.getElementById("message").style.display = "initial"; - setTimeout(function(){ - document.getElementById("message").style.display = "none"; - }, 2000); + document.getElementById("message").innerHTML='ok'; + document.getElementById("message").style.backgroundColor = "#0f0"; + document.getElementById("message").style.display = "initial"; + setTimeout(function(){ + document.getElementById("message").style.display = "none"; + }, 2000); } function fetchHandle(res){ if(!res.ok){ - console.log(res); - document.getElementById("site").style.backgroundColor = "#f00"; + console.log(res); + document.getElementById("site").style.backgroundColor = "#f00"; }else{ - if(EEPROMDataChanged) - document.getElementById("site").style.backgroundColor = "#ffa"; - else - document.getElementById("site").style.backgroundColor = "#fff"; + if(EEPROMDataChanged) + document.getElementById("site").style.backgroundColor = "#ffa"; + else + document.getElementById("site").style.backgroundColor = "#fff"; return res; } } - /* - +String(now()); - color = timeColor[0] << 16; - color += timeColor[1] << 8; - color += timeColor[2]; - ret += "," + String(color); - color = tacticalTimeColor[0] << 16; - color += tacticalTimeColor[1] << 8; - color += tacticalTimeColor[2]; - ret += "," + String(color); - color = dateColor[0] << 16; - color += dateColor[1] << 8; - color += dateColor[2]; - ret += "," + String(color); - ret += "," + String(timeIndex); - ret += "," + String(lastTimeSyncTyp); - ret += "," + String(lastTimeSyncTime); - ret += ",\"" + String(lux_value)+"\""; - ret += ",\"" + String(brightness)+"\""; - ret += "," + String(autobrightness); - ret += "," + String(rtcEnabled); - ret += "," + String(GPSdoSync); - ret += "," + String(countSatellites); - ret += "," + String(countGPS); - ret += "," + String(EEPROMDataNotSaved); - */ function fetch_handle_response(res){ var elem=document.getElementById('d'); @@ -372,43 +380,47 @@ const char html_page_index[] PROGMEM = R"rawliteral( }else if(res[0] == '['){ try{ var data = JSON.parse(res); - ti = data[0]; - showAktTimeFromUnix(ti); - colorString = "#" + data[1].toString(16).padStart(6, '0'); - document.getElementById('actTime').style.color = colorString; - colorString = "#" + data[2].toString(16).padStart(6, '0'); - document.getElementById('actTacTime').style.color = colorString; - colorString = "#" + data[3].toString(16).padStart(6, '0'); - document.getElementById('actDate').style.color = colorString; - - document.getElementById('showWhat').value = parseInt(data[4]); - showTimeFromUnix(data[6],'sync'); - switch(data[5]){ - case 0: - document.getElementById('sync').innerHTML = " keiner"; - break; - case 1: - document.getElementById('sync').innerHTML += " (GPS)"; - break; - case 2: - document.getElementById('sync').innerHTML += " (NTP)"; - break; - case 3: - document.getElementById('sync').innerHTML += " (manuel)"; - break; - }brigtness - - document.getElementById('lux').innerHTML = data[7]; - document.getElementById('brigtness').innerHTML = (data[8]*100); - document.getElementById("rtcactive").checked = (data[10] == 1); - - EEPROMDataChanged = (data[14] == 1); - if(EEPROMDataChanged){ - document.getElementById("site").style.backgroundColor = "#ffa"; - } - document.getElementById('SSID').innerHTML = data[15]; - - + ti = data[0]; + showAktTimeFromUnix(ti); + colorString = "#" + data[1].toString(16).padStart(6, '0'); + document.getElementById('actTime').style.color = colorString; + colorString = "#" + data[2].toString(16).padStart(6, '0'); + document.getElementById('actTacTime').style.color = colorString; + colorString = "#" + data[3].toString(16).padStart(6, '0'); + document.getElementById('actDate').style.color = colorString; + + document.getElementById('showWhat').value = parseInt(data[4]); + switch(data[5]){ + case 0: + document.getElementById('sync').innerHTML = " keiner"; + break; + case 1: + document.getElementById('sync').innerHTML += " (GPS)"; + break; + case 2: + document.getElementById('sync').innerHTML += " (NTP)"; + break; + 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); + + EEPROMDataChanged = (data[9] == 1); + if(EEPROMDataChanged){ + document.getElementById("site").style.backgroundColor = "#ffa"; + } + document.getElementById('SSID').innerHTML = data[10]; + document.getElementById('temp').innerHTML = data[11]; + var options = parseInt(data[12]); + document.getElementById("withSeconds").checked = (options >> 0) & 0x1; + document.getElementById("alwaysAccessPoint").checked = (options >> 1) & 0x1; + + colorString = "#" + data[13].toString(16).padStart(6, '0'); + document.getElementById('actKW').style.color = colorString; + document.getElementById('actKW').innerHTML = "KW " + data[14]; }catch(e){ console.log(e); } @@ -418,13 +430,18 @@ const char html_page_index[] PROGMEM = R"rawliteral( function doSend(_value1,_value2=[],_value3=[]){ var send_str = "/do?"+_value1[0]+"="+_value1[1]; if(_value2.length > 0){ - send_str += "&"+_value2[0]+"="+_value2[1]; + send_str += "&"+_value2[0]+"="+_value2[1]; } - if(_value3.length > 0){ - send_str += "&"+_value3[0]+"="+_value3[1]; + if(_value3.length > 0){ + send_str += "&"+_value3[0]+"="+_value3[1]; } fetch(send_str).then(fetchHandle).then((res) => res.text()).then((text) => fetch_handle_response(text)).catch((err) => { console.log(err);document.getElementById("site").style.backgroundColor = "#f00";}); } + + function doPoll(){ + var send_str = "/poll"; + fetch(send_str).then(fetchHandle).then((res) => res.text()).then((text) => fetch_handle_response(text)).catch((err) => { console.log(err);document.getElementById("site").style.backgroundColor = "#f00";}); + } function doSetTime(_idx = -1){ var d=new Date(); @@ -435,10 +452,12 @@ const char html_page_index[] PROGMEM = R"rawliteral( function setColor(){ var elem=document.getElementById('eActTimeC'); doSend(['set','color'],['to',elem.value.substring(1)]); - elem=document.getElementById('eActTacTimeC'); + elem=document.getElementById('eActTacTimeC'); doSend(['set','tcolor'],['to',elem.value.substring(1)]); - elem=document.getElementById('eActDateC'); + elem=document.getElementById('eActDateC'); doSend(['set','dcolor'],['to',elem.value.substring(1)]); + elem=document.getElementById('eActKWC'); + doSend(['set','kwcolor'],['to',elem.value.substring(1)]); } function setTimeFromUnix(_ti,_id){ @@ -491,21 +510,30 @@ const char html_page_index[] PROGMEM = R"rawliteral( function setWifi(){ var elem=document.getElementById("eSSID"); - var elem2=document.getElementById("ePASS"); - doSend(['set','wifi'],['ssid',elem.value],['pwd',elem2.value]); + var elem2=document.getElementById("ePASS"); + doSend(['set','wifi'],['ssid',encodeURIComponent(elem.value)],['pwd',encodeURIComponent(elem2.value)]); } - + + function setAPPass(){ + var elem=document.getElementById("apPASS"); + var pwd = String(elem.value); + if((pwd.length > 7) && (pwd.length < 65)){ + doSend(['set','appass'],['pwd',encodeURIComponent(pwd)]); + elem.value = ''; + }else{ + alert('Das AccessPoint Passwort muss zwischen 8 und 64 Zeichen lang sein!'); + } + } function setOption(){ setBrightness(); - var option = 0; - - if(document.getElementById("eab").checked) - option += 1; - doSend(['set','option'],['options',option]); - - setWifi(); - closeOptionEdit(); + var option = 0; + if(document.getElementById("eWithSeconds").checked) + option += 1; + if(document.getElementById("eAlwaysAccessPoint").checked) + option += 2; + + doSend(['set','option'],['options',option]); } function save() { @@ -517,15 +545,14 @@ const char html_page_index[] PROGMEM = R"rawliteral( } function poll() { - doSend(['poll','']); + doPoll(); setTimeout(function(){ poll(); }, 1000); } document.addEventListener("DOMContentLoaded", function(event) { - - poll(); + poll(); });