erste Version wo display nicht flackert ...
This commit is contained in:
717
ESPNTUhrPx.ino
Normal file
717
ESPNTUhrPx.ino
Normal file
@@ -0,0 +1,717 @@
|
||||
#define VERSION "V2.4"
|
||||
|
||||
// Pins for LED MATRIX
|
||||
#include <Ticker.h>
|
||||
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 4 // 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=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
|
||||
|
||||
//WebService
|
||||
#define TEMPLATE_PLACEHOLDER '`' //-> Damit % in CSS funktioniert ...
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESPAsyncTCP.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
//#include <DNSServer.h>
|
||||
AsyncWebServer webServer(80);
|
||||
//DNSServer dnsServer;
|
||||
IPAddress ip_local(192, 168, 13, 1);
|
||||
IPAddress ip_gateway(0, 0, 0, 0);
|
||||
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
|
||||
|
||||
//permanenter Speicher
|
||||
#include <ESP_EEPROM.h>
|
||||
|
||||
String ChipID = "ERROR";
|
||||
//i2c
|
||||
#include <Wire.h>
|
||||
#include <RV-3029-C2.h>
|
||||
RV3029 rtc;
|
||||
const int PINRTC_CLOCK = 12;
|
||||
boolean rtcEnabled = false;
|
||||
|
||||
#include <TimeLib.h>
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
// 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<z; c++){
|
||||
setPixelColor(x+c,y, red, green, blue);
|
||||
}*/
|
||||
//display.display(display_draw_time);
|
||||
}
|
||||
|
||||
//Zeichene eine Linie senkrecht x/y und z als länge
|
||||
void LineV(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.drawFastVLine(x,y,z,color);
|
||||
//display.display(display_draw_time);
|
||||
/*for(uint8_t c = 0; c<z; c++){
|
||||
setPixelColor(x,y+c, red, green, blue);
|
||||
}*/
|
||||
//display.display(display_draw_time);
|
||||
}
|
||||
|
||||
//eigene Schriften
|
||||
#include "D:\arduino\Projekte\_includes\char3x5.h"
|
||||
#include "D:\arduino\Projekte\_includes\char5x7.h"
|
||||
#include "D:\arduino\Projekte\_includes\char6x8.h"
|
||||
#include "D:\arduino\Projekte\_includes\char10x16.h"
|
||||
|
||||
void doClearLEDsSeconds(){
|
||||
|
||||
for(uint8_t x=0;x<5;x++){
|
||||
display.drawFastHLine(56,26+x,7,0);
|
||||
}
|
||||
/*for(uint16_t x=56;x<MATRIX_WIDTH;x++){
|
||||
for(uint16_t y=26;y<MATRIX_HEIGHT;y++){
|
||||
display.drawPixelRGB888(x,y, 0, 0, 0);
|
||||
//
|
||||
}
|
||||
//display.display(display_draw_time);
|
||||
}*/
|
||||
}
|
||||
|
||||
void doClearLEDsStatus(){
|
||||
for(uint16_t x=0;x<MATRIX_WIDTH;x++){
|
||||
display.drawPixelRGB888(x,0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void doClearLEDs(boolean incFirstLine = false){
|
||||
display.fillScreen(0);
|
||||
/*if(incFirstLine)
|
||||
display.clearDisplay();
|
||||
else{
|
||||
for(uint16_t x=0;x<MATRIX_WIDTH;x++){
|
||||
for(uint16_t y=1;y<MATRIX_HEIGHT;y++){
|
||||
display.drawPixelRGB888(x,y, 0, 0, 0);
|
||||
}
|
||||
//display.display(display_draw_time);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void showOVALZ(void){
|
||||
uint8_t zeile=20;
|
||||
uint8_t spalte=8;
|
||||
spalte += Out5x7Char('O',spalte,zeile,255,255,255)+1;
|
||||
spalte += Out5x7Char('V',spalte,zeile,255,255,255)+1;
|
||||
spalte += Out5x7Char('-',spalte,zeile,255,255,255)+1;
|
||||
spalte += Out5x7Char('A',spalte,zeile,255,255,255)+1;
|
||||
spalte += Out5x7Char('l',spalte,zeile,255,255,255)+1;
|
||||
spalte += Out5x7Char('z',spalte,zeile,255,255,255)+1;
|
||||
spalte += Out5x7Char('e',spalte,zeile,255,255,255)+1;
|
||||
spalte += Out5x7Char('n',spalte,zeile,255,255,255)+1;
|
||||
spalte += Out5x7Char('a',spalte,zeile,255,255,255)+1;
|
||||
spalte += Out5x7Char('u',spalte,zeile,255,255,255)+1;
|
||||
}
|
||||
|
||||
void showNTOOLS(void){
|
||||
uint8_t zeile=5;
|
||||
uint8_t spalte=10;
|
||||
spalte += Out5x7Char('N',spalte,zeile,0,0,255)+1;
|
||||
spalte += Out5x7Char('-',spalte,zeile,0,0,255)+1;
|
||||
spalte += Out5x7Char('T',spalte,zeile,0,0,255)+1;
|
||||
spalte += Out5x7Char('o',spalte,zeile,0,0,255)+1;
|
||||
spalte += Out5x7Char('o',spalte,zeile-1,0,0,255)+1;
|
||||
spalte += Out5x7Char('l',spalte,zeile,0,0,255)+1;
|
||||
spalte += Out5x7Char('s',spalte,zeile,0,0,255)+1;
|
||||
spalte += Out5x7Char('.',spalte,zeile,0,0,255)+1;
|
||||
spalte += Out5x7Char('d',spalte,zeile,0,0,255)+1;
|
||||
spalte += Out5x7Char('e',spalte,zeile,0,0,255)+1;
|
||||
}
|
||||
|
||||
uint8_t drawTactical(time_t t,uint8_t x = 0, uint8_t y = 0 ){
|
||||
uint16_t tmp = day(t);
|
||||
x += Out5x7Char((tmp/10)+0x30,x,y,tacCr,tacCg,tacCb)+1;
|
||||
tmp -= (tmp/10)*10;
|
||||
x += Out5x7Char((tmp)+0x30,x,y,tacCr,tacCg,tacCb)+1;
|
||||
|
||||
tmp = hour(t);
|
||||
x += Out5x7Char((tmp/10)+0x30,x,y,tacCr,tacCg,tacCb)+1;
|
||||
tmp -= (tmp/10)*10;
|
||||
x += Out5x7Char((tmp)+0x30,x,y,tacCr,tacCg,tacCb)+1;
|
||||
|
||||
tmp = minute(t);
|
||||
x += Out5x7Char((tmp/10)+0x30,x,y,tacCr,tacCg,tacCb)+1;
|
||||
tmp -= (tmp/10)*10;
|
||||
x += Out5x7Char((tmp)+0x30,x,y,tacCr,tacCg,tacCb)+1;
|
||||
|
||||
tmp = month(t);
|
||||
|
||||
switch(tmp){
|
||||
case 1:
|
||||
x += Out5x7Char('j',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('a',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('n',x,y,tacCr,tacCg,tacCb)+1;
|
||||
break;
|
||||
case 2:
|
||||
x += Out5x7Char('f',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('e',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('b',x,y,tacCr,tacCg,tacCb)+1;
|
||||
break;
|
||||
case 3:
|
||||
x += Out5x7Char('m',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('a',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('r',x,y,tacCr,tacCg,tacCb)+1;
|
||||
break;
|
||||
case 4:
|
||||
x += Out5x7Char('a',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('p',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('r',x,y,tacCr,tacCg,tacCb)+1;
|
||||
break;
|
||||
case 5:
|
||||
x += Out5x7Char('m',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('a',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('y',x,y,tacCr,tacCg,tacCb)+1;
|
||||
break;
|
||||
case 6:
|
||||
x += Out5x7Char('j',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('u',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('n',x,y,tacCr,tacCg,tacCb)+1;
|
||||
break;
|
||||
case 7:
|
||||
x += Out5x7Char('j',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('u',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('l',x,y,tacCr,tacCg,tacCb)+1;
|
||||
break;
|
||||
case 8:
|
||||
x += Out5x7Char('a',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('u',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('g',x,y,tacCr,tacCg,tacCb)+1;
|
||||
break;
|
||||
case 9:
|
||||
x += Out5x7Char('s',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('e',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('p',x,y,tacCr,tacCg,tacCb)+1;
|
||||
break;
|
||||
case 10:
|
||||
x += Out5x7Char('o',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('c',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('t',x,y,tacCr,tacCg,tacCb)+1;
|
||||
break;
|
||||
case 11:
|
||||
x += Out5x7Char('n',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('o',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('v',x,y,tacCr,tacCg,tacCb)+1;
|
||||
break;
|
||||
case 12:
|
||||
x += Out5x7Char('d',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('e',x,y,tacCr,tacCg,tacCb)+1;
|
||||
x += Out5x7Char('c',x,y,tacCr,tacCg,tacCb)+1;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
tmp = year(t)-2000;
|
||||
x += Out5x7Char((tmp/10)+0x30,x,y,tacCr,tacCg,tacCb)+1;
|
||||
tmp -= (tmp/10)*10;
|
||||
if(x > 59)
|
||||
x--;
|
||||
x += Out5x7Char((tmp)+0x30,x,y,tacCr,tacCg,tacCb);
|
||||
return x;
|
||||
}
|
||||
|
||||
void showTimeTactical(time_t t){
|
||||
uint16_t tmp = 0;
|
||||
uint8_t x = 0;
|
||||
uint8_t y = 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
|
||||
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;
|
||||
}
|
||||
|
||||
tmp = second(t);
|
||||
Out3x5Char((tmp/10)+0x30,x,y+11,timeCr,timeCg,timeCb);
|
||||
tmp -= (tmp/10)*10;
|
||||
x += 4;
|
||||
Out3x5Char((tmp)+0x30,x,y+11,timeCr,timeCg,timeCb);
|
||||
}
|
||||
|
||||
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() {
|
||||
ChipID = String(ESP.getChipId());
|
||||
display.begin(16);
|
||||
//display.setFlip(true);
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
String newHostname = "NTUVPx"+String(ChipID);
|
||||
|
||||
WiFi.begin(ssid,pass);
|
||||
WiFi.hostname(newHostname.c_str());
|
||||
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) {
|
||||
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, Minute, Second;
|
||||
setTime(timenow);
|
||||
Year = year(timenow);
|
||||
Month = month(timenow);
|
||||
Day = day(timenow);
|
||||
Hour = hour(timenow);
|
||||
Minute = minute(timenow);
|
||||
Second = second(timenow);
|
||||
if(isDayLight(Hour,Day,weekday(),Month))
|
||||
timenow += (SECS_PER_HOUR * 2);
|
||||
else
|
||||
timenow += (SECS_PER_HOUR);
|
||||
if(rtcEnabled){
|
||||
doSetTime(timenow);
|
||||
}
|
||||
lastTimeSyncTyp = 2;
|
||||
lastTimeSyncTime = now();
|
||||
display.drawPixelRGB888(2,0,0,255,0);
|
||||
display_doupdate();
|
||||
}else{
|
||||
display.drawPixelRGB888(2,0,255,0,255);
|
||||
display_doupdate();
|
||||
}
|
||||
//WiFi.localIP()
|
||||
}else{
|
||||
display.drawPixelRGB888(1,0,255,0,0);
|
||||
display_doupdate();
|
||||
WiFi.disconnect();
|
||||
delay(3000);
|
||||
|
||||
ESP.eraseConfig();
|
||||
WiFi.mode(WIFI_OFF);
|
||||
WiFi.mode(WIFI_AP);
|
||||
WiFi.softAPConfig(ip_local, ip_gateway, ip_subnet);
|
||||
APEnabled = WiFi.softAP("NTUhr VPx "+ChipID, "gibteskeins");
|
||||
}
|
||||
|
||||
|
||||
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("/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.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();
|
||||
}
|
||||
showTimeTactical(currentUNIXTime);
|
||||
display_doupdate();
|
||||
}
|
||||
}
|
||||
//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";
|
||||
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_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);
|
||||
}else if(((s_set == "color") | (s_set == "tcolor") | (s_set == "dcolor")) & (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]);
|
||||
}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]);
|
||||
}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]);*/
|
||||
}
|
||||
}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));
|
||||
}
|
||||
if(request->hasParam(PARAM_OPTIONS)) {
|
||||
s_value = request->getParam(PARAM_OPTIONS)->value();
|
||||
//options = s_value.toInt();
|
||||
//EEPROM.put(1,options);
|
||||
//autobrightness = bitRead(options,0);
|
||||
}
|
||||
}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_value.toCharArray(ssid, 30);
|
||||
s_value = request->getParam(PARAM_PWD )->value();
|
||||
s_value.toCharArray(pass, 30);
|
||||
EEPROM.put(101,ssid);
|
||||
EEPROM.put(201,pass);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
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;
|
||||
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");
|
||||
}
|
||||
|
||||
// Replaces placeholder with button section in your web page
|
||||
String html_processor(const String& var){
|
||||
if(var == "VERSION"){
|
||||
return String(VERSION);
|
||||
}else if(var == "ID"){
|
||||
return String(ChipID);
|
||||
}
|
||||
return String();
|
||||
}
|
||||
|
||||
String toggleState(int toggle){
|
||||
switch(toggle){
|
||||
case 0:
|
||||
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
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 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){
|
||||
request->send(200, "text/plain", "success");
|
||||
}
|
||||
1500
PxMatrix.h
Normal file
1500
PxMatrix.h
Normal file
File diff suppressed because it is too large
Load Diff
533
index_html.h
Normal file
533
index_html.h
Normal file
@@ -0,0 +1,533 @@
|
||||
const char html_page_index[] PROGMEM = R"rawliteral(
|
||||
<!DOCTYPE HTML><html>
|
||||
<head>
|
||||
<title>N-Tools.de Uhr</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta charset="UTF-8">
|
||||
<link rel="icon" href="data:,">
|
||||
<style>
|
||||
html {font-family: Roboto, Arial; display: inline-block; text-align: center;}
|
||||
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;
|
||||
}
|
||||
label {min-width: 150px;display: inline-block;text-align: left; padding-left: 5px;}
|
||||
input,select,option { display: inline-block;text-align:center;}
|
||||
h1,h2,h3{padding:0px;margin:0px;)}
|
||||
h1{font-size: 1.7rem;}
|
||||
.head{
|
||||
background: linear-gradient(to bottom, #1b62d8 0%, #003399 100%);
|
||||
text-align: right;
|
||||
margin: 0px;
|
||||
padding: 5px;
|
||||
box-shadow: 0 8px 32px 0 rgb(0 0 0 / 40%), 0 3px 20px 0 rgb(0 0 0 / 38%);
|
||||
color:#fff;
|
||||
}
|
||||
.site{
|
||||
|
||||
}
|
||||
.option {
|
||||
margin: 20px;
|
||||
padding: 10px;
|
||||
box-shadow: 0 16px 32px 0 rgb(0 0 0 / 40%), 0 6px 20px 0 rgb(0 0 0 / 38%);
|
||||
min-width: 160px;
|
||||
border-radius: 4px;
|
||||
background-color: #fff;
|
||||
display: inline-grid;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
opacity: 0.8;
|
||||
}
|
||||
.value {
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
}
|
||||
.act{
|
||||
background-color: #000;
|
||||
color: #fff;
|
||||
padding: 2px 5px 2px 5px;
|
||||
}
|
||||
.m50{
|
||||
min-width: 50%;
|
||||
}
|
||||
.fs25{
|
||||
font-size: 2.5rem;
|
||||
}
|
||||
.fs12{
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
.fs17{
|
||||
font-size: 1.7rem;
|
||||
}
|
||||
.fs075, .fs075 *{
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
.left{
|
||||
text-align: left;
|
||||
}
|
||||
.margin25left{
|
||||
margin-left: 25%;
|
||||
}
|
||||
.margin12left{
|
||||
margin-left: 12%;
|
||||
}
|
||||
#te{
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 10%;
|
||||
left: 10%;
|
||||
margin: auto;
|
||||
padding: 3%;
|
||||
box-shadow: 0 16px 32px 0 rgb(0 0 0 / 40%), 0 6px 20px 0 rgb(0 0 0 / 38%);
|
||||
min-height: 70%;
|
||||
width: 74%;
|
||||
border-radius: 8px;
|
||||
background-color: #fff;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
opacity: 1.0;
|
||||
}
|
||||
#te > .value{
|
||||
text-align: left;
|
||||
}
|
||||
#oe{
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 10%;
|
||||
left: 10%;
|
||||
margin: auto;
|
||||
padding: 3%;
|
||||
box-shadow: 0 16px 32px 0 rgb(0 0 0 / 40%), 0 6px 20px 0 rgb(0 0 0 / 38%);
|
||||
min-height: 70%;
|
||||
width: 74%;
|
||||
border-radius: 8px;
|
||||
background-color: #fff;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
opacity: 1.0;
|
||||
}
|
||||
#oe > .value{
|
||||
text-align: left;
|
||||
}
|
||||
#close{
|
||||
cursor: pointer;
|
||||
text-align: right;
|
||||
display: block;
|
||||
}
|
||||
#message{
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 10%;
|
||||
left: 35%;
|
||||
margin: auto;
|
||||
padding: 5px;
|
||||
box-shadow: 0 16px 32px 0 rgb(0 0 0 / 40%), 0 6px 20px 0 rgb(0 0 0 / 38%);
|
||||
width: 30%;
|
||||
border-radius: 4px;
|
||||
z-index: 9999;
|
||||
}
|
||||
|
||||
input[type=button], input[type=submit], input[type=reset] {
|
||||
background-color: #1b62d8;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
|
||||
color: #fff;
|
||||
position: relative;
|
||||
text-decoration: none;
|
||||
text-transform: uppercase;
|
||||
width: 100%;
|
||||
padding: 0.25rem 0.5rem;
|
||||
@media(min-width: 600px) {
|
||||
|
||||
margin: 0 1em 2em;
|
||||
|
||||
}
|
||||
|
||||
&:hover { text-decoration: none; }
|
||||
|
||||
box-shadow: inset 0 0 20px rgba(255, 255, 255, 0);
|
||||
outline: 1px solid;
|
||||
outline-color: rgba(255, 255, 255, .5);
|
||||
outline-offset: 0px;
|
||||
text-shadow: none;
|
||||
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
input[type=button]:hover {
|
||||
box-shadow: 0 16px 32px 0 rgb(0 0 0 / 40%), 0 6px 20px 0 rgb(0 0 0 / 38%);
|
||||
outline-color: rgba(255, 255, 255, 0);
|
||||
outline-offset: 15px;
|
||||
text-shadow: 1px 1px 2px #427388;
|
||||
}
|
||||
.wsnw{
|
||||
white-space: nowrap;
|
||||
}
|
||||
.center{
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="head" class="head">
|
||||
<h1>N-Tools Uhr VPx</h1>
|
||||
<h3>`VERSION`</h3>
|
||||
<h3>`ID`</h3>
|
||||
</div>
|
||||
<div id="site" class="site">
|
||||
<div id="message"></div>
|
||||
<div class='option' onclick="editTime(-1);">
|
||||
<div class='value'>
|
||||
<label class="center">aktuell:</label><br>
|
||||
<span class='act' id="actTime"></span><br>
|
||||
<span class='act' id="actTacTime"></span><br>
|
||||
<span class='act' id="actDate"></span>
|
||||
</div><br>
|
||||
<div class='fs075'>
|
||||
<label>letzter abgleich:</label>
|
||||
<span id="sync"></span>
|
||||
</div>
|
||||
</div><br>
|
||||
<br>
|
||||
<div class='option m50'>
|
||||
<label for="showWhat">Zeige</label>
|
||||
<select id="showWhat" onchange="setShowWhat();">
|
||||
<option value=0>taktische Uhrzeit</option>
|
||||
<option value=1>Uhrzeit</option>
|
||||
<option value=2>Datum / Uhrzeit</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class='option m50' onclick="return false">
|
||||
<label for="brigtness">Helligkeit LEDs</label>
|
||||
<span class="wsnw"><span id="brigtness"></span> %</span><br>
|
||||
<label for="lux">Umgebungshelligkeit</label>
|
||||
<span class="wsnw"><span id="lux"></span> LUX</span><br>
|
||||
<div class="left margin12left">
|
||||
<span class="wsnw">
|
||||
<label for="SSID">SSID:</label>
|
||||
<span id="SSID"></span>
|
||||
</span>
|
||||
<br>
|
||||
<input type="button" onclick="editOption();" value="Optionen ändern"><br>
|
||||
<br>
|
||||
<span class="wsnw">
|
||||
<input id="rtcactive" type='checkbox' onclick="return false" readonly>
|
||||
<label for="rtcactive">RTC okay</label>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<input id="d" type='text' style='width:80%;font-size:0.75rem;' value=''>
|
||||
<div class='option m50'>
|
||||
<input class="fs17" id="save" class="btn" type='button' value='dauerhaft speichern' onclick='save();'>
|
||||
</div>
|
||||
<div class='option m50'>
|
||||
<input class="fs17" id="reset" class="btn" type='button' value='neu starten' onclick='reset();'>
|
||||
</div>
|
||||
<div id="te">
|
||||
<div id="close" onclick="closeEdit();">X</div>
|
||||
<div class='value'>
|
||||
<h1><span id="el"></span></h1>
|
||||
<label for="eActTimeC">Uhrzeit: </label><input type="color" id="eActTimeC" value=""><br>
|
||||
<label for="eActTacTimeC">taktische Zeit: </label><input type="color" id="eActTacTimeC" value=""><br>
|
||||
<label for="eActDateC">Datum: </label><input type="color" id="eActDateC" value=""><br>
|
||||
<input type="button" class="btn fs12" onclick="setColor();closeEdit();" value="setzen"><br><br>
|
||||
<input type="button" id="doSetTime" class="btn fs12" onclick="doSetTime();" value="Uhrzeit nach diesem Gerät setzen"><br>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div id="oe">
|
||||
<div id="close" onclick="closeOptionEdit();">X</div>
|
||||
<div class='value'>
|
||||
<h1><span id="el">Optionen</span></h1>
|
||||
<input id="ebs" type='number' min="5" max="100" step="5" onchange="document.getElementById('eab').checked = false;"> %
|
||||
<label for="ebs">Helligkeitsfaktor (in Prozent)</label><br>
|
||||
<span>
|
||||
<label for="eSSID">SSID:</label>
|
||||
<input id="eSSID" type='text' onclick="return false">
|
||||
</span>
|
||||
<br>
|
||||
<span>
|
||||
<label for="ePASS">Passwort:</label>
|
||||
<input id="ePASS" type='text' onclick="return false">
|
||||
</span>
|
||||
<br>
|
||||
<input type="button" class="btn" onclick="setOption();" value="setzen"><br>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
var ti = new Date;
|
||||
var EEPROMDataChanged = false;
|
||||
|
||||
function RGBToHex(rgb) {
|
||||
// Choose correct separator
|
||||
let sep = rgb.indexOf(",") > -1 ? "," : " ";
|
||||
// Turn "rgb(r,g,b)" into [r,g,b]
|
||||
rgb = rgb.substr(4).split(")")[0].split(sep);
|
||||
|
||||
let r = (+rgb[0]).toString(16),
|
||||
g = (+rgb[1]).toString(16),
|
||||
b = (+rgb[2]).toString(16);
|
||||
|
||||
if (r.length == 1)
|
||||
r = "0" + r;
|
||||
if (g.length == 1)
|
||||
g = "0" + g;
|
||||
if (b.length == 1)
|
||||
b = "0" + b;
|
||||
console.log("#" + r + g + b);
|
||||
return "#" + r + g + b;
|
||||
}
|
||||
|
||||
|
||||
function closeEdit(){
|
||||
document.getElementById("te").style.display = "none";
|
||||
}
|
||||
|
||||
function editTime(_what){
|
||||
if(_what == -1){
|
||||
document.getElementById("el").innerHTML = 'Farben';
|
||||
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("te").style.display = "initial";
|
||||
}
|
||||
|
||||
function closeOptionEdit(){
|
||||
document.getElementById("oe").style.display = "none";
|
||||
}
|
||||
|
||||
function editOption(){
|
||||
document.getElementById('ebs').value = document.getElementById('brigtness').innerHTML;
|
||||
document.getElementById('eSSID').value = document.getElementById('SSID').innerHTML;
|
||||
|
||||
document.getElementById("oe").style.display = "initial";
|
||||
}
|
||||
|
||||
Number.prototype.AddZero= function(b,c){
|
||||
var l= (String(b || 10).length - String(this).length)+1;
|
||||
return l>0? new Array(l).join(c || '0')+this : this;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
function fetchHandle(res){
|
||||
if(!res.ok){
|
||||
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";
|
||||
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');
|
||||
elem.value=res;
|
||||
if(res == 'OK'){
|
||||
showOK();
|
||||
}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];
|
||||
|
||||
|
||||
}catch(e){
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function doSend(_value1,_value2=[],_value3=[]){
|
||||
var send_str = "/do?"+_value1[0]+"="+_value1[1];
|
||||
if(_value2.length > 0){
|
||||
send_str += "&"+_value2[0]+"="+_value2[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 doSetTime(_idx = -1){
|
||||
var d=new Date();
|
||||
d.setTime(d.getTime() - (d.getTimezoneOffset()*60*1000) + 1000);
|
||||
doSend(['set','time'],['to',Math.floor(d /1000)],['idx',_idx]);
|
||||
}
|
||||
|
||||
function setColor(){
|
||||
var elem=document.getElementById('eActTimeC');
|
||||
doSend(['set','color'],['to',elem.value.substring(1)]);
|
||||
elem=document.getElementById('eActTacTimeC');
|
||||
doSend(['set','tcolor'],['to',elem.value.substring(1)]);
|
||||
elem=document.getElementById('eActDateC');
|
||||
doSend(['set','dcolor'],['to',elem.value.substring(1)]);
|
||||
}
|
||||
|
||||
function setTimeFromUnix(_ti,_id){
|
||||
var elem=document.getElementById(_id);
|
||||
//var st = String(new Date(_ti*1000).toISOString().substr(0,19));
|
||||
var st = new Date(parseInt(_ti) * 1000);
|
||||
var sst = st.toISOString().slice(0,19);
|
||||
elem.value = sst;
|
||||
}
|
||||
|
||||
function showAktTimeFromUnix(_ti){
|
||||
var elem=document.getElementById('actTime');
|
||||
var elem2=document.getElementById('actTacTime');
|
||||
var elem3=document.getElementById('actDate');
|
||||
var st = new Date(parseInt(_ti) * 1000);
|
||||
st.setTime(st.getTime() + (st.getTimezoneOffset()*60*1000));
|
||||
//var sst = st.toUTCString();
|
||||
var sstTime = ("0" + st.getHours()).slice(-2) + ":" + ("0" + st.getMinutes()).slice(-2) + ":" + ("0" + st.getSeconds()).slice(-2);
|
||||
elem.innerHTML = sstTime;
|
||||
const formatter = new Intl.DateTimeFormat('en', { month: 'short' });
|
||||
const month = formatter.format(st);
|
||||
var sstTacTime = ("0" + st.getDate()).slice(-2) + "" + ("0" + st.getHours()).slice(-2) + "" + ("0" + st.getMinutes()).slice(-2) + month.toLowerCase() + ("" + st.getFullYear()).slice(-2);
|
||||
elem2.innerHTML = sstTacTime;
|
||||
var sstDate = ("0" + st.getDate()).slice(-2) + "." + ("0"+(st.getMonth()+1)).slice(-2) + "." +st.getFullYear();
|
||||
elem3.innerHTML = sstDate;
|
||||
}
|
||||
|
||||
function showTimeFromUnix(_ti,_id){
|
||||
var elem=document.getElementById(_id);
|
||||
var st = new Date(parseInt(_ti) * 1000);
|
||||
st.setTime(st.getTime() + (st.getTimezoneOffset()*60*1000));
|
||||
//var sst = st.toUTCString();
|
||||
var sst = ("0" + st.getDate()).slice(-2) + "." + ("0"+(st.getMonth()+1)).slice(-2) + "." +st.getFullYear() + " " + ("0" + st.getHours()).slice(-2) + ":" + ("0" + st.getMinutes()).slice(-2) + ":" + ("0" + st.getSeconds()).slice(-2);
|
||||
elem.innerHTML = sst;
|
||||
}
|
||||
|
||||
function setShowWhat(_what = -2){
|
||||
if(_what == -2){
|
||||
var elem=document.getElementById("showWhat");
|
||||
doSend(['set','option'],['showWhat',elem.value]);
|
||||
}else{
|
||||
doSend(['set','option'],['showWhat',_what]);
|
||||
}
|
||||
}
|
||||
|
||||
function setBrightness(){
|
||||
var elem=document.getElementById("ebs");
|
||||
doSend(['set','option'],['brightness',(elem.value / 100)]);
|
||||
}
|
||||
|
||||
function setWifi(){
|
||||
var elem=document.getElementById("eSSID");
|
||||
var elem2=document.getElementById("ePASS");
|
||||
doSend(['set','wifi'],['ssid',elem.value],['pwd',elem2.value]);
|
||||
}
|
||||
|
||||
|
||||
function setOption(){
|
||||
setBrightness();
|
||||
var option = 0;
|
||||
|
||||
if(document.getElementById("eab").checked)
|
||||
option += 1;
|
||||
doSend(['set','option'],['options',option]);
|
||||
|
||||
setWifi();
|
||||
closeOptionEdit();
|
||||
}
|
||||
|
||||
function save() {
|
||||
doSend(['save','']);
|
||||
}
|
||||
|
||||
function reset() {
|
||||
doSend(['reset','']);
|
||||
}
|
||||
|
||||
function poll() {
|
||||
doSend(['poll','']);
|
||||
setTimeout(function(){
|
||||
poll();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
|
||||
poll();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
)rawliteral";
|
||||
Reference in New Issue
Block a user