#define VERSION (char *) "V2.17" /* 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 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 */ // Pins for LED MATRIX #include Ticker display_ticker; #define P_LAT 16 #define P_A 5 #define P_B 4 #define P_C 15 #define P_D 0 //#define P_E 0 #define P_OE 2 #define PxMATRIX_COLOR_DEPTH 2 // 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 #include "PxMatrix.h" PxMATRIX display(64,32,P_LAT, P_OE,P_A,P_B,P_C,P_D); 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!!! ... #include #include #include #include #include AsyncWebServer webServer(80); DNSServer dnsServer; IPAddress ip_local(192, 168, 13, 1); IPAddress ip_gateway(192, 168, 13, 1); IPAddress ip_subnet(255, 255, 255, 0); char localip[16]; boolean APEnabled = false; char ssid[30] = "THW Freifunk"; char pass[30] = ""; char appass[30] = "gibteskeins"; String toStringIp(IPAddress ip) { String res = ""; for (int i = 0; i < 3; i++) { res += String((ip >> (8 * i)) & 0xFF) + "."; } res += String(((ip >> 8 * 3)) & 0xFF); return res; } void html_handle_notsuccess(AsyncWebServerRequest *request); void html_handle_notsuccess(AsyncWebServerRequest *request){ request->send(200, "text/html", String("zur Konfigurationsseite")); } //permanenter Speicher #include 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; 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; boolean iDL = false; uint8_t lastTimeSyncTyp = 0; long lastTimeSyncTime = 0; uint8_t timeIndex = 0; bool EEPROMDataNotSaved = false; uint8_t options = 0; bool withSeconds = true; bool alwaysAccessPoint = true; // ISR for display refresh void display_updater(){ display.display(display_draw_time); } void display_update_enable(bool is_enable){ if (is_enable) display_ticker.attach(0.001, display_updater); else display_ticker.detach(); } //Led mit Helligkeit 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 #include #include #include 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 59) x--; 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; tmp = minute(t); if(lastminutes != tmp){ lastminutes = tmp; doClearLEDs(); uint8_t x_tactical = drawTactical(t,0,3); if(x_tactical < 63){ x_tactical = ceil((63 - x_tactical)/2); doClearLEDs(); drawTactical(t,x_tactical+1,3); } //Uhrzeit drawTime(t); } 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 = 0; 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 += 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,-6); if(withSeconds) drawSeconds(t,-6); 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(0,26,str,kwColor[0],kwColor[1],kwColor[2]); } 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){ rtc.reset(); rtc.setUNIX(t); } void IRAM_ATTR rtc_clock(){ //Interrupt vom RTC if(digitalRead(PINRTC_CLOCK)){ ti_second = millis() - 1020; //display.drawPixelRGB888(4,0,0,255,0); }else{ //display.drawPixelRGB888(4,0,0,0,0); } } uint8_t isDayLight(uint8_t hour, uint8_t day, uint8_t wday, uint8_t month){ if( month < 3 || month > 10 ) // month 1, 2, 11, 12 return 0; // -> Winter if( day - wday >= 25 && (wday || hour >= 2) ){ // after last Sunday 2:00 if( month == 10 ) // October -> Winter return 0; }else{ // before last Sunday 2:00 if( month == 3 ) // March -> Winter return 0; } return 1; } //NTP Update auf ganz lange uint32_t sntp_update_delay_MS_rfc_not_less_than_15000 (){ return 365 * 24 * 60 * 60 * 1000UL; // 365 Tage } //reboot!!! void display_doupdate(void){ display.showBuffer(); display.copyBuffer(); } void setup() { 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.setBrightness(255); display.setBrightness(ceil(255 * brightness)); display.setFastUpdate(true); doClearLEDs(true); showOVALZ(); showNTOOLS(); display_update_enable(true); Wire.begin(1,3); //Wire.setClock(400000); //RTC if (rtc.begin() == false) { display.drawPixelRGB888(0,0,255,0,0); display_doupdate(); }else{ display.drawPixelRGB888(0,0,0,255,0); display_doupdate(); rtc.setBackupSwitchoverMode(3); 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); } char NetName[30]; strcpy(NetName, "NTUVPx"); strcat(NetName, ChipID); char APName[30]; 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; while ((WiFi.status() != WL_CONNECTED) && (xc < 10)) { delay(1500); xc++; display.drawPixelRGB888(xc+5,0,255,255,0); display_doupdate(); } if (WiFi.status() == WL_CONNECTED) { 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); xc = 0; while((timenow < SECS_YR_2000) && (xc < 10)) { delay(1000); timenow = time(nullptr); xc++; display.drawPixelRGB888(xc+16,0,255,255,0); display_doupdate(); } if(timenow > SECS_YR_2000){ timenow += 1; int Year; byte Month, Day, Hour; setTime(timenow); Year = year(timenow); Day = day(timenow); Hour = hour(timenow); if(isDayLight(Hour,Day,weekday(),Month)) timenow += (SECS_PER_HOUR * 2); else timenow += (SECS_PER_HOUR); if(rtcEnabled){ doSetTime(timenow); } lastTimeSyncTyp = 2; lastTimeSyncTime = timenow; display.drawPixelRGB888(2,0,0,255,0); display_doupdate(); }else{ display.drawPixelRGB888(2,0,255,0,255); display_doupdate(); } delay(5000); }else{ display.drawPixelRGB888(1,0,255,0,0); display_doupdate(); alwaysAccessPoint = true; } if(alwaysAccessPoint){ if (WiFi.status() != WL_CONNECTED) { WiFi.disconnect(); delay(100); WiFi.mode(WIFI_OFF); delay(100); WiFi.mode(WIFI_AP); } 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); 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); } 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 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);}); //webServer.on("/resetAP", HTTP_GET, [] (AsyncWebServerRequest *request) {html_resetAP(request);}); AsyncElegantOTA.begin(&webServer); // Start AsyncElegantOTA webServer.begin(); if(rtcEnabled) attachInterrupt(digitalPinToInterrupt(PINRTC_CLOCK), rtc_clock, CHANGE); delay(3000); doClearLEDsStatus(); } void loop(){ if (millis() - ti_second > 1000) { ti_second = millis(); 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); 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 .. if((WDay == 1) && (Hour == 3) && (Minute == 1) && (Second == 0)){ ESP.restart(); } 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(); //yield(); } //alles was WEB ist ... #include "index_html.h" const char* PARAM_SET = "set"; const char* PARAM_SAVE = "save"; const char* PARAM_TO = "to"; const char* PARAM_SHOWWHAT = "showWhat"; const char* PARAM_BRIGHTNESS = "brightness"; const char* PARAM_OPTIONS = "options"; const char* PARAM_SSID = "ssid"; 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); } 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; if (request->hasParam(PARAM_SET)) { s_set = request->getParam(PARAM_SET)->value(); if((s_set == "time") & (request->hasParam(PARAM_TO))) { s_value = request->getParam(PARAM_TO)->value(); l_value = strtol(s_value.c_str(), NULL, 10); doSetTime(l_value); lastTimeSyncTyp = 3; lastTimeSyncTime = now(); }else if(request->hasParam(PARAM_SHOWWHAT)) { s_value = request->getParam(PARAM_SHOWWHAT)->value(); timeIndex = s_value.toInt(); EEPROM.put(0, timeIndex); 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); c[0] = l_value >> 16; c[1] = l_value >> 8; c[2] = l_value; if(s_set == "color"){ timeColor[0] = c[0]; timeColor[1] = c[1]; timeColor[2] = c[2]; 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]; tacticalTimeColor[2] = c[2]; 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[1] = c[1]; dateColor[2] = c[2]; EEPROM.write(31,dateColor[0]); EEPROM.write(32,dateColor[1]); 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); 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); 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(); s_value2 = request->getParam(PARAM_PWD )->value(); if((s_value != ssid) || (s_value2 != pass)){ s_value.toCharArray(ssid, 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"); lastminutes = -1; }else if (request->hasParam(PARAM_SAVE)){ EEPROM.commit(); EEPROMDataNotSaved = false; request->send(200, "text/plain", "OK"); }else if (request->hasParam(PARAM_RESET)){ request->send(200, "text/plain", "OK"); delay(1000); ESP.restart(); } request->send(200, "text/plain", "NOK"); } void html_resetAP(AsyncWebServerRequest *request) { String s_value = ""; s_value.toCharArray(appass, 30); EEPROM.put(151,appass); EEPROM.commit(); request->send(200, "text/plain", "OK"); } // Replaces placeholder with button section in your web page char * html_processor(const String& var){ if(var == "VERSION"){ return VERSION; }else if(var == "ID"){ return ChipID; }else if(var == "LOCALIP"){ return localip; } return (char *) "not defined"; } String toggleState(int toggle){ switch(toggle){ case 0: break; } return ""; }