Neue Version von Hubert
This commit is contained in:
File diff suppressed because it is too large
Load Diff
+94096
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+94096
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
+1784230
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+1784356
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1793844
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
+100170
File diff suppressed because it is too large
Load Diff
+1704660
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,686 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#include <EEPROM.h>
|
||||
#include <time.h>
|
||||
#include <WiFiManager.h>
|
||||
|
||||
|
||||
// ================= LED =================
|
||||
#define PIN D4
|
||||
#define NUMPIXELS 110
|
||||
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
// ================= SERVER =================
|
||||
ESP8266WebServer server(80);
|
||||
|
||||
// ================= NTP =================
|
||||
String ntpServer = "de.pool.ntp.org";
|
||||
String tzString = "CET-1CEST,M3.5.0/02,M10.5.0/03";
|
||||
|
||||
// ================= SETTINGS =================
|
||||
struct Settings {
|
||||
int brightness;
|
||||
int nightBrightness;
|
||||
bool autoNight;
|
||||
int nightStart;
|
||||
int nightEnd;
|
||||
uint32_t color;
|
||||
uint32_t bgColor;
|
||||
bool backgroundMode;
|
||||
char ntpServer[64];
|
||||
char tzString[64];
|
||||
} settings;
|
||||
|
||||
// ================= VAR =================
|
||||
uint32_t currentColor = 0x00FFFF;
|
||||
uint32_t lastColor = 0x00FFFF;
|
||||
uint32_t bgColor = 0x000000;
|
||||
bool backgroundMode = false;
|
||||
bool forceInstant = false;
|
||||
bool updateNeeded = true;
|
||||
|
||||
int brightness = 120;
|
||||
int nightBrightness = 10;
|
||||
bool autoNight = true;
|
||||
int nightStart = 22;
|
||||
int nightEnd = 6;
|
||||
|
||||
uint32_t targetBuffer[NUMPIXELS];
|
||||
uint32_t currentBuffer[NUMPIXELS];
|
||||
|
||||
int lastMinute = -1;
|
||||
|
||||
// ================= EEPROM =================
|
||||
void saveSettings(){
|
||||
settings.brightness = brightness;
|
||||
settings.nightBrightness = nightBrightness;
|
||||
settings.autoNight = autoNight;
|
||||
settings.nightStart = nightStart;
|
||||
settings.nightEnd = nightEnd;
|
||||
settings.color = currentColor;
|
||||
settings.bgColor = bgColor;
|
||||
settings.backgroundMode = backgroundMode;
|
||||
strncpy(settings.ntpServer, ntpServer.c_str(), sizeof(settings.ntpServer));
|
||||
strncpy(settings.tzString, tzString.c_str(), sizeof(settings.tzString));
|
||||
|
||||
EEPROM.put(0, settings);
|
||||
EEPROM.commit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void loadSettings(){
|
||||
EEPROM.begin(512);
|
||||
EEPROM.get(0, settings);
|
||||
|
||||
// Prüfen, ob EEPROM leer ist (über Helligkeit)
|
||||
if(settings.brightness == 0 || settings.brightness == 255){
|
||||
// Standardwerte setzen
|
||||
brightness = 120;
|
||||
nightBrightness = 10;
|
||||
autoNight = true;
|
||||
nightStart = 22;
|
||||
nightEnd = 6;
|
||||
currentColor = 0x00FFFF;
|
||||
bgColor = 0x000000;
|
||||
backgroundMode = false;
|
||||
ntpServer = "de.pool.ntp.org";
|
||||
tzString = "CET-1CEST,M3.5.0/02,M10.5.0/03";
|
||||
} else {
|
||||
brightness = settings.brightness;
|
||||
nightBrightness = settings.nightBrightness;
|
||||
autoNight = settings.autoNight;
|
||||
nightStart = settings.nightStart;
|
||||
nightEnd = settings.nightEnd;
|
||||
currentColor = settings.color;
|
||||
bgColor = settings.bgColor;
|
||||
backgroundMode = settings.backgroundMode;
|
||||
ntpServer = String(settings.ntpServer);
|
||||
tzString = String(settings.tzString);
|
||||
}
|
||||
|
||||
// Zeitkonfiguration sofort anwenden
|
||||
configTime(tzString.c_str(), ntpServer.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ================= HELFER =================
|
||||
void clearTarget(){
|
||||
for(int i=0;i<NUMPIXELS;i++) targetBuffer[i]=0;
|
||||
}
|
||||
|
||||
void setRange(int a,int b){
|
||||
for(int i=a;i<=b;i++) targetBuffer[i]=currentColor;
|
||||
}
|
||||
|
||||
void setRangeColor(int a,int b, uint32_t col){
|
||||
for(int i=a;i<=b;i++) targetBuffer[i] = col;
|
||||
}
|
||||
|
||||
|
||||
uint32_t blend(uint32_t c1, uint32_t c2, float t){
|
||||
uint8_t r1=(c1>>16)&255, g1=(c1>>8)&255, b1=c1&255;
|
||||
uint8_t r2=(c2>>16)&255, g2=(c2>>8)&255, b2=c2&255;
|
||||
|
||||
return pixels.Color(
|
||||
r1 + (r2 - r1) * t,
|
||||
g1 + (g2 - g1) * t,
|
||||
b1 + (b2 - b1) * t
|
||||
);
|
||||
}
|
||||
|
||||
uint32_t applyBrightness(uint32_t c, float brightnessFactor){
|
||||
uint8_t r = ((c >> 16) & 255) * brightnessFactor;
|
||||
uint8_t g = ((c >> 8) & 255) * brightnessFactor;
|
||||
uint8_t b = (c & 255) * brightnessFactor;
|
||||
|
||||
return pixels.Color(r,g,b);
|
||||
}
|
||||
|
||||
uint8_t gamma8(uint8_t x){
|
||||
if(x<5) return 0;
|
||||
float f = x / 255.0;
|
||||
f = pow(f, 2.2); // Gamma 2.2
|
||||
return (uint8_t)(f * 255);
|
||||
}
|
||||
|
||||
uint32_t applyGammaBrightness(uint32_t c, float brightnessFactor){
|
||||
|
||||
uint8_t r = ((c >> 16) & 255) * brightnessFactor;
|
||||
uint8_t g = ((c >> 8) & 255) * brightnessFactor;
|
||||
uint8_t b = (c & 255) * brightnessFactor;
|
||||
|
||||
// 🔥 Gamma Korrektur
|
||||
r = gamma8(r);
|
||||
g = gamma8(g);
|
||||
b = gamma8(b);
|
||||
|
||||
return pixels.Color(r,g,b);
|
||||
}
|
||||
|
||||
void updateDisplayNow(){
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
if(t){
|
||||
showTimeWords(t->tm_hour, t->tm_min);
|
||||
}
|
||||
}
|
||||
|
||||
void showInstant(){
|
||||
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
|
||||
float b = getBrightness(t) / 255.0;
|
||||
|
||||
for(int i=0;i<NUMPIXELS;i++){
|
||||
uint32_t c = applyGammaBrightness(targetBuffer[i], b);
|
||||
pixels.setPixelColor(i, c);
|
||||
}
|
||||
|
||||
pixels.show();
|
||||
}
|
||||
|
||||
// ================= WORTUHR =================
|
||||
|
||||
// ES IST
|
||||
void word_ES(){ setRange(0,1); }
|
||||
void word_IST(){ setRange(3,5); }
|
||||
|
||||
// Minuten
|
||||
void word_FUENF_M(){ setRange(7,10); }
|
||||
void word_ZEHN_M(){ setRange(18,20); }
|
||||
void word_ZWANZIG(){ setRange(11,17); }
|
||||
void word_VIERTEL(){ setRange(22,28); }
|
||||
void word_VOR(){ setRange(30,32); }
|
||||
void word_NACH(){ setRange(40,43); }
|
||||
void word_HALB(){ setRange(33,36); }
|
||||
|
||||
// Stunden
|
||||
void word_EINS(){ setRange(62,65); }
|
||||
void word_EIN(){ setRange(62,64); }
|
||||
void word_ZWEI(){ setRange(55,58); }
|
||||
void word_DREI(){ setRange(66,69); }
|
||||
void word_VIER(){ setRange(73,76); }
|
||||
void word_FUENF_H(){ setRange(51,54); }
|
||||
void word_SECHS(){ setRange(83,87); }
|
||||
void word_SIEBEN(){ setRange(88,93); }
|
||||
void word_ACHT(){ setRange(77,80); }
|
||||
void word_NEUN(){ setRange(44,47); }
|
||||
void word_ZEHN_H(){ setRange(106,109); }
|
||||
void word_ELF(){ setRange(103,105); }
|
||||
void word_ZWOELF(){ setRange(94,98); }
|
||||
|
||||
// UHR
|
||||
void word_UHR(){ setRange(99,101); }
|
||||
|
||||
// ================= TEXT =================
|
||||
String hourToText(int h){
|
||||
String arr[]={"Zwölf","Eins","Zwei","Drei","Vier","Fünf","Sechs","Sieben","Acht","Neun","Zehn","Elf"};
|
||||
return arr[h%12];
|
||||
}
|
||||
|
||||
String hourText(int h,bool full){
|
||||
int hh = h % 12;
|
||||
|
||||
if(hh == 1){
|
||||
return full ? "ein" : "eins";
|
||||
}
|
||||
return hourToText(h);
|
||||
}
|
||||
|
||||
String getTimeText(int h,int m){
|
||||
int m5=(m/5)*5;
|
||||
if(m5>=25) h++;
|
||||
|
||||
String t="Es ist ";
|
||||
|
||||
switch(m5){
|
||||
case 0: t+= hourText(h, true)+" Uhr"; break;
|
||||
case 5: t+="fünf nach "+hourToText(h); break;
|
||||
case 10: t+="zehn nach "+hourToText(h); break;
|
||||
case 15: t+="viertel nach "+hourToText(h); break;
|
||||
case 20: t+="zwanzig nach "+hourToText(h); break;
|
||||
case 25: t+="fünf vor halb "+hourToText(h); break;
|
||||
case 30: t+="halb "+hourToText(h); break;
|
||||
case 35: t+="fünf nach halb "+hourToText(h); break;
|
||||
case 40: t+="zwanzig vor "+hourToText(h); break;
|
||||
case 45: t+="viertel vor "+hourToText(h); break;
|
||||
case 50: t+="zehn vor "+hourToText(h); break;
|
||||
case 55: t+="fünf vor "+hourToText(h); break;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
// ================= NACHTMODUS =================
|
||||
int getBrightness(struct tm *t){
|
||||
if(!autoNight) return brightness;
|
||||
|
||||
int h=t->tm_hour;
|
||||
if(nightStart > nightEnd){
|
||||
if(h >= nightStart || h < nightEnd) return nightBrightness;
|
||||
} else {
|
||||
if(h >= nightStart && h < nightEnd) return nightBrightness;
|
||||
}
|
||||
return brightness;
|
||||
}
|
||||
|
||||
|
||||
void fadeToTargetSmooth(int steps = 10, int delayMs = 5){
|
||||
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
|
||||
float bTarget = getBrightness(t) / 255.0;
|
||||
|
||||
for(int s = 0; s <= steps; s++){
|
||||
float tBlend = (float)s / steps;
|
||||
|
||||
for(int i=0;i<NUMPIXELS;i++){
|
||||
|
||||
uint32_t c = blend(currentBuffer[i], targetBuffer[i], tBlend);
|
||||
|
||||
uint32_t finalColor = applyGammaBrightness(c, bTarget);
|
||||
|
||||
pixels.setPixelColor(i, finalColor);
|
||||
}
|
||||
|
||||
pixels.show();
|
||||
delay(delayMs);
|
||||
}
|
||||
}
|
||||
// ================= ANZEIGE =================
|
||||
void showTimeWords(int h, int m){
|
||||
|
||||
// 🔥 aktuellen Zustand als Start für Fade holen
|
||||
for(int i=0;i<NUMPIXELS;i++){
|
||||
currentBuffer[i] = pixels.getPixelColor(i);
|
||||
}
|
||||
|
||||
// 🔥 Zielbuffer komplett neu aufbauen
|
||||
for(int i=0;i<NUMPIXELS;i++){
|
||||
if(backgroundMode){
|
||||
targetBuffer[i] = bgColor; // frei wählbarer Hintergrund
|
||||
} else {
|
||||
targetBuffer[i] = 0; // aus
|
||||
}
|
||||
}
|
||||
|
||||
// Grundtext
|
||||
word_ES();
|
||||
word_IST();
|
||||
|
||||
int m5 = (m/5)*5;
|
||||
bool full = (m5 == 0);
|
||||
|
||||
if(m5 >= 25) h++;
|
||||
|
||||
// Minuten
|
||||
switch(m5){
|
||||
case 0: word_UHR(); break;
|
||||
case 5: word_FUENF_M(); word_NACH(); break;
|
||||
case 10: word_ZEHN_M(); word_NACH(); break;
|
||||
case 15: word_VIERTEL(); word_NACH(); break;
|
||||
case 20: word_ZWANZIG(); word_NACH(); break;
|
||||
case 25: word_FUENF_M(); word_VOR(); word_HALB(); break;
|
||||
case 30: word_HALB(); break;
|
||||
case 35: word_FUENF_M(); word_NACH(); word_HALB(); break;
|
||||
case 40: word_ZWANZIG(); word_VOR(); break;
|
||||
case 45: word_VIERTEL(); word_VOR(); break;
|
||||
case 50: word_ZEHN_M(); word_VOR(); break;
|
||||
case 55: word_FUENF_M(); word_VOR(); break;
|
||||
}
|
||||
|
||||
// Stunden
|
||||
int hh = h % 12;
|
||||
|
||||
if(hh == 1 && full) word_EIN();
|
||||
else if(hh == 1) word_EINS();
|
||||
else if(hh == 2) word_ZWEI();
|
||||
else if(hh == 3) word_DREI();
|
||||
else if(hh == 4) word_VIER();
|
||||
else if(hh == 5) word_FUENF_H();
|
||||
else if(hh == 6) word_SECHS();
|
||||
else if(hh == 7) word_SIEBEN();
|
||||
else if(hh == 8) word_ACHT();
|
||||
else if(hh == 9) word_NEUN();
|
||||
else if(hh == 10) word_ZEHN_H();
|
||||
else if(hh == 11) word_ELF();
|
||||
else word_ZWOELF();
|
||||
|
||||
// 🔥 jetzt alles weich darstellen (inkl. Gamma & Brightness)
|
||||
if(forceInstant){
|
||||
showInstant();
|
||||
forceInstant = false;
|
||||
}else{
|
||||
fadeToTargetSmooth(10,5);
|
||||
}
|
||||
}
|
||||
// ================= WEB =================
|
||||
void handleNTP() {
|
||||
if (server.hasArg("val")) {
|
||||
ntpServer = server.arg("val");
|
||||
// Konfiguration sofort mit neuem Server aktualisieren
|
||||
configTime(tzString.c_str(), ntpServer.c_str());
|
||||
Serial.println("NTP Server geändert: " + ntpServer);
|
||||
}
|
||||
server.send(200, "text/plain", "OK");
|
||||
}
|
||||
|
||||
void handleTZ() {
|
||||
if (server.hasArg("val")) {
|
||||
tzString = server.arg("val");
|
||||
// Konfiguration sofort mit neuer Zeitzone aktualisieren
|
||||
configTime(tzString.c_str(), ntpServer.c_str());
|
||||
Serial.println("Zeitzone geändert: " + tzString);
|
||||
}
|
||||
server.send(200, "text/plain", "OK");
|
||||
}
|
||||
|
||||
void handleColor(){
|
||||
if(server.hasArg("c")){
|
||||
lastColor=currentColor;
|
||||
currentColor=strtoul(server.arg("c").c_str(),NULL,16);
|
||||
forceInstant = true;
|
||||
updateDisplayNow();
|
||||
|
||||
}
|
||||
server.send(200,"text/plain","OK");
|
||||
}
|
||||
|
||||
void handleBGColor(){
|
||||
if(server.hasArg("c")){
|
||||
bgColor=strtoul(server.arg("c").c_str(),NULL,16);
|
||||
forceInstant = true;
|
||||
updateNeeded = true;
|
||||
}
|
||||
server.send(200,"text/plain","OK");
|
||||
}
|
||||
|
||||
|
||||
void handleBrightness(){
|
||||
brightness=server.arg("val").toInt();
|
||||
forceInstant = true;
|
||||
updateNeeded = true;
|
||||
server.send(200,"text/plain","OK");
|
||||
}
|
||||
|
||||
void handleNight(){
|
||||
autoNight=server.arg("val").toInt();
|
||||
forceInstant = true;
|
||||
updateNeeded = true;
|
||||
server.send(200,"text/plain","OK");
|
||||
}
|
||||
|
||||
void handleBG(){
|
||||
backgroundMode=server.arg("val").toInt();
|
||||
forceInstant = true;
|
||||
updateNeeded = true;
|
||||
server.send(200,"text/plain","OK");
|
||||
}
|
||||
|
||||
void handleSave(){
|
||||
saveSettings();
|
||||
server.send(200,"text/plain","saved");
|
||||
}
|
||||
|
||||
void handleNightStart(){
|
||||
int val = server.arg("val").toInt();
|
||||
if(val >= 0 && val <= 23) {
|
||||
nightStart = val;
|
||||
forceInstant = true;
|
||||
updateNeeded = true;
|
||||
server.send(200, "text/plain", "OK");
|
||||
} else {
|
||||
server.send(400, "text/plain", "Ungueltiger Wert");
|
||||
}
|
||||
}
|
||||
|
||||
void handleNightEnd(){
|
||||
int val = server.arg("val").toInt();
|
||||
|
||||
if(val >= 0 && val <= 23) {
|
||||
nightEnd = val;
|
||||
forceInstant = true;
|
||||
updateNeeded = true;
|
||||
server.send(200, "text/plain", "OK");
|
||||
} else {
|
||||
server.send(400, "text/plain", "Ungueltiger Wert");
|
||||
}
|
||||
}
|
||||
|
||||
void handleNightBrightness(){
|
||||
nightBrightness = server.arg("val").toInt();
|
||||
forceInstant = true;
|
||||
updateNeeded = true;
|
||||
server.send(200, "text/plain", "OK");
|
||||
}
|
||||
|
||||
void handleStatus() {
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
char hexCol[10];
|
||||
snprintf(hexCol, sizeof(hexCol), "#%06X", currentColor);
|
||||
char hexBg[10];
|
||||
snprintf(hexBg, sizeof(hexBg), "#%06X",bgColor);
|
||||
|
||||
String ntpStat = (now > 100000) ? "OK" : "SYNC...";
|
||||
Serial.println(ntpStat);
|
||||
String json = "{";
|
||||
json += "\"txt\":\"" + getTimeText(t->tm_hour, t->tm_min) + "\",";
|
||||
json += "\"ip\":\"" + WiFi.localIP().toString() + "\",";
|
||||
json += "\"ntp\":\"" + ntpStat + "\",";
|
||||
json += "\"ntpServer\":\"" + ntpServer + "\",";
|
||||
json += "\"tzString\":\"" + tzString + "\",";
|
||||
json += "\"brightness\":" + String(brightness) + ",";
|
||||
json += "\"nightBrightness\":" + String(nightBrightness) + ",";
|
||||
json += "\"color\":\"" + String(hexCol) + "\",";
|
||||
json += "\"bgColor\":\"" + String(hexBg) + "\",";
|
||||
json += "\"night\":" + String(autoNight ? 1 : 0) + ",";
|
||||
json += "\"nightStart\":" + String(nightStart) + ",";
|
||||
json += "\"nightEnd\":" + String(nightEnd) + ",";
|
||||
json += "\"bg\":" + String(backgroundMode ? 1 : 0); // Hier KEIN Komma am Ende
|
||||
json += "}";
|
||||
|
||||
server.send(200, "application/json", json);
|
||||
}
|
||||
|
||||
// ================= HTML =================
|
||||
void handleRoot(){
|
||||
String html = R"rawliteral(
|
||||
<html>
|
||||
<head>
|
||||
<meta charset='UTF-8'>
|
||||
<meta name='viewport' content='width=device-width, initial-scale=1'>
|
||||
<style>
|
||||
body{font-family:Arial,sans-serif; background:#fff; margin:0; color:#333; display:flex; flex-direction:column; align-items:center}
|
||||
.card{width:90%; max-width:400px; margin:10px; padding:15px; border-radius:12px; background:#f2f2f2; box-shadow: 0 2px 5px rgba(0,0,0,0.1)}
|
||||
.big{font-size:26px; text-align:center; font-weight:bold; color:#0055ff}
|
||||
#status{font-size:0.85em; color:#666; text-align:center}
|
||||
.grid{display:flex; gap:10px; align-items:center; margin-top:10px}
|
||||
.sub-label{font-size:0.85em; margin-top:10px; display:block; color:#555}
|
||||
input[type='number']{width:55px; padding:8px; border-radius:6px; border:1px solid #ccc; text-align:center}
|
||||
input[type='range'], input[type='color']{width:100%; cursor:pointer}
|
||||
button{width:100%; padding:12px; border-radius:8px; border:none; background:#0055ff; color:#fff; font-weight:bold; cursor:pointer}
|
||||
label{font-weight:bold; display:block; margin-bottom:5px}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class='card big' id='txt'>--:--</div>
|
||||
<div class='card' id='status'>Verbinde...</div>
|
||||
|
||||
<div class='card'>
|
||||
<label>Wort-LED Farbe</label>
|
||||
<input type='color' id='col' onchange='c(this.value)'>
|
||||
</div>
|
||||
|
||||
<div class='card'>
|
||||
<label>Standard Helligkeit</label>
|
||||
<input type='range' id='br' min='0' max='255' oninput='b(this.value)'>
|
||||
</div>
|
||||
|
||||
<div class='card'>
|
||||
<input type='checkbox' id='night' onchange='n(this.checked)'> <b>Nachtmodus (Auto)</b>
|
||||
|
||||
<span class='sub-label'>Zeitraum:</span>
|
||||
<div class='grid'>
|
||||
Von: <input type='number' id='nS' min='0' max='23' oninput='ns(this.value)' autocomplete='off'> Uhr
|
||||
Bis: <input type='number' id='nE' min='0' max='23' oninput='ne(this.value)' autocomplete='off'> Uhr
|
||||
</div>
|
||||
|
||||
<span class='sub-label'>Nacht-Helligkeit:</span>
|
||||
<input type='range' id='nbr' min='0' max='255' oninput='nb(this.value)'>
|
||||
</div>
|
||||
|
||||
<div class='card'>
|
||||
<input type='checkbox' id='bg' onchange='bgf(this.checked)'> <b>Hintergrund</b>
|
||||
<span class='sub-label'>Farbe</span>
|
||||
<input type='color' id='bgcol' onchange='bgc(this.value)'>
|
||||
</div>
|
||||
|
||||
<div class='card'>
|
||||
<label>Zeit-Quellen</label>
|
||||
<span class='sub-label'>NTP Server:</span>
|
||||
<input type='text' id='ntpS' onchange='setNTP(this.value)' style='width:100%'>
|
||||
|
||||
<span class='sub-label'>Zeitzone (POSIX TZ):</span>
|
||||
<input type='text' id='tzS' onchange='setTZ(this.value)' style='width:100%'>
|
||||
<a href='https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv' target='_blank' style='font-size:0.7em'>TZ-Datenbank Hilfe</a>
|
||||
</div>
|
||||
|
||||
<div class='card'>
|
||||
<button onclick='save()'>Einstellungen im EEPROM speichern</button>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
function c(v){fetch('/color?c='+v.substring(1))}
|
||||
function bgc(v){fetch('/bgcolor?c='+v.substring(1))}
|
||||
function b(v){fetch('/brightness?val='+v)}
|
||||
function n(v){fetch('/night?val='+(v?1:0))}
|
||||
function nb(v){fetch('/nightBrightness?val='+v)} // NEU: Nacht-Helligkeit
|
||||
function bgf(v){fetch('/bg?val='+(v?1:0))}
|
||||
function save(){fetch('/save').then(()=>alert('Gespeichert!'))}
|
||||
function setNTP(v){ fetch('/setNTP?val=' + encodeURIComponent(v)); }
|
||||
function setTZ(v){ fetch('/setTZ?val=' + encodeURIComponent(v)); }
|
||||
function setNTP(v){ fetch('/setNTP?val=' + encodeURIComponent(v)); }
|
||||
function setTZ(v){ fetch('/setTZ?val=' + encodeURIComponent(v)); }
|
||||
|
||||
function ns(v){
|
||||
if(v === "") return; // Warten, bis eine Zahl drin steht
|
||||
let val = parseInt(v);
|
||||
if(val < 0) val = 0; if(val > 23) val = 23;
|
||||
fetch('/nightStart?val=' + val);
|
||||
}
|
||||
|
||||
function ne(v){
|
||||
if(v === "") return;
|
||||
let val = parseInt(v);
|
||||
if(val < 0) val = 0; if(val > 23) val = 23;
|
||||
fetch('/nightEnd?val=' + val);
|
||||
}
|
||||
|
||||
|
||||
function update(){
|
||||
fetch('/status').then(r=>r.json()).then(d=>{
|
||||
// Hilfsfunktion zum sicheren Setzen von Werten
|
||||
const setVal = (id, val, isCheck = false) => {
|
||||
const el = document.getElementById(id);
|
||||
if(!el) return; // Falls Element nicht existiert, überspringen
|
||||
if(document.activeElement === el) return; // Falls User gerade tippt, überspringen
|
||||
|
||||
if(isCheck) el.checked = (val == 1);
|
||||
else el.value = val;
|
||||
};
|
||||
|
||||
// Texte immer aktualisieren
|
||||
const txt = document.getElementById('txt');
|
||||
const stat = document.getElementById('status');
|
||||
if(txt) txt.innerHTML = d.txt;
|
||||
if(stat) stat.innerHTML = "IP: " + d.ip + " | NTP: " + d.ntp;
|
||||
|
||||
// Alle Eingabefelder sicher aktualisieren
|
||||
setVal('col', d.color);
|
||||
setVal('bgcol', d.bgColor);
|
||||
setVal('br', d.brightness);
|
||||
setVal('nbr', d.nightBrightness);
|
||||
setVal('nS', d.nightStart);
|
||||
setVal('nE', d.nightEnd);
|
||||
setVal('ntpS', d.ntpServer);
|
||||
setVal('tzS', d.tzString);
|
||||
|
||||
// Checkboxen
|
||||
setVal('night', d.night, true);
|
||||
setVal('bg', d.bg, true);
|
||||
|
||||
}).catch(err => {
|
||||
console.error("Update-Fehler:", err);
|
||||
const stat = document.getElementById('status');
|
||||
if(stat) stat.innerHTML = "Verbindung unterbrochen...";
|
||||
});
|
||||
}
|
||||
|
||||
setInterval(update, 2000);
|
||||
update();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
)rawliteral";
|
||||
server.send(200, "text/html", html);
|
||||
}
|
||||
|
||||
|
||||
// ================= SETUP =================
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
|
||||
WiFiManager wm;
|
||||
wm.autoConnect("Wortuhr");
|
||||
|
||||
configTime(tzString.c_str(), ntpServer.c_str());
|
||||
for(int i=0;i<NUMPIXELS;i++){
|
||||
currentBuffer[i] = 0;
|
||||
}
|
||||
|
||||
pixels.begin();
|
||||
loadSettings();
|
||||
|
||||
server.on("/",handleRoot);
|
||||
server.on("/status",handleStatus);
|
||||
server.on("/color",handleColor);
|
||||
server.on("/bgcolor",handleBGColor);
|
||||
server.on("/brightness",handleBrightness);
|
||||
server.on("/night",handleNight);
|
||||
server.on("/nightStart",handleNightStart);
|
||||
server.on("/nightEnd",handleNightEnd);
|
||||
server.on("/nightBrightness",handleNightBrightness);
|
||||
server.on("/bg",handleBG);
|
||||
server.on("/save",handleSave);
|
||||
server.on("/setNTP", handleNTP);
|
||||
server.on("/setTZ", handleTZ);
|
||||
|
||||
server.begin();
|
||||
}
|
||||
|
||||
// ================= LOOP =================
|
||||
void loop(){
|
||||
server.handleClient();
|
||||
|
||||
time_t now=time(nullptr);
|
||||
struct tm *t=localtime(&now);
|
||||
|
||||
if(t && t->tm_min !=lastMinute){
|
||||
lastMinute=t->tm_min;
|
||||
updateNeeded = true;
|
||||
}
|
||||
|
||||
if(updateNeeded){
|
||||
showTimeWords(t->tm_hour,t->tm_min);
|
||||
updateNeeded = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,378 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#include <EEPROM.h>
|
||||
#include <time.h>
|
||||
#include <WiFiManager.h>
|
||||
|
||||
// ================= LED =================
|
||||
#define PIN D4
|
||||
#define NUMPIXELS 110
|
||||
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
// ================= SERVER & NTP =================
|
||||
ESP8266WebServer server(80);
|
||||
String ntpServer = "de.pool.ntp.org";
|
||||
String tzString = "CET-1CEST,M3.5.0/02,M10.5.0/03";
|
||||
|
||||
// ================= SETTINGS =================
|
||||
struct Settings {
|
||||
int brightness;
|
||||
int nightBrightness;
|
||||
bool autoNight;
|
||||
int nightStart;
|
||||
int nightEnd;
|
||||
uint32_t color;
|
||||
uint32_t bgColor;
|
||||
bool backgroundMode;
|
||||
char ntpServer[64];
|
||||
char tzString[64];
|
||||
bool nightBackgroundDisabled; // Neu
|
||||
} settings;
|
||||
|
||||
// ================= VAR =================
|
||||
uint32_t currentColor = 0x00FFFF;
|
||||
uint32_t lastColor = 0x00FFFF;
|
||||
uint32_t bgColor = 0x000000;
|
||||
bool backgroundMode = false;
|
||||
bool nightBackgroundDisabled = false; // Neu
|
||||
bool forceInstant = false;
|
||||
bool updateNeeded = true;
|
||||
int brightness = 120;
|
||||
int nightBrightness = 10;
|
||||
bool autoNight = true;
|
||||
int nightStart = 22;
|
||||
int nightEnd = 6;
|
||||
uint32_t targetBuffer[NUMPIXELS];
|
||||
uint32_t currentBuffer[NUMPIXELS];
|
||||
int lastMinute = -1;
|
||||
int lastH = -1;
|
||||
|
||||
// ================= EEPROM =================
|
||||
void saveSettings(){
|
||||
settings.brightness = brightness;
|
||||
settings.nightBrightness = nightBrightness;
|
||||
settings.autoNight = autoNight;
|
||||
settings.nightStart = nightStart;
|
||||
settings.nightEnd = nightEnd;
|
||||
settings.color = currentColor;
|
||||
settings.bgColor = bgColor;
|
||||
settings.backgroundMode = backgroundMode;
|
||||
settings.nightBackgroundDisabled = nightBackgroundDisabled; // Neu
|
||||
strncpy(settings.ntpServer, ntpServer.c_str(), sizeof(settings.ntpServer));
|
||||
strncpy(settings.tzString, tzString.c_str(), sizeof(settings.tzString));
|
||||
EEPROM.put(0, settings);
|
||||
EEPROM.commit();
|
||||
}
|
||||
|
||||
void loadSettings(){
|
||||
EEPROM.begin(512);
|
||||
EEPROM.get(0, settings);
|
||||
if(settings.brightness == 0 || settings.brightness == 255){
|
||||
brightness = 120;
|
||||
nightBrightness = 10;
|
||||
autoNight = true;
|
||||
nightStart = 22;
|
||||
nightEnd = 6;
|
||||
currentColor = 0x00FFFF;
|
||||
bgColor = 0x000000;
|
||||
backgroundMode = false;
|
||||
nightBackgroundDisabled = false;
|
||||
ntpServer = "de.pool.ntp.org";
|
||||
tzString = "CET-1CEST,M3.5.0/02,M10.5.0/03";
|
||||
} else {
|
||||
brightness = settings.brightness;
|
||||
nightBrightness = settings.nightBrightness;
|
||||
autoNight = settings.autoNight;
|
||||
nightStart = settings.nightStart;
|
||||
nightEnd = settings.nightEnd;
|
||||
currentColor = settings.color;
|
||||
bgColor = settings.bgColor;
|
||||
backgroundMode = settings.backgroundMode;
|
||||
nightBackgroundDisabled = settings.nightBackgroundDisabled;
|
||||
ntpServer = String(settings.ntpServer);
|
||||
tzString = String(settings.tzString);
|
||||
}
|
||||
configTime(tzString.c_str(), ntpServer.c_str());
|
||||
}
|
||||
|
||||
// ================= HELFER =================
|
||||
bool isNightTime(struct tm *t){
|
||||
if(!autoNight) return false;
|
||||
int h = t->tm_hour;
|
||||
if(nightStart > nightEnd){
|
||||
return (h >= nightStart || h < nightEnd);
|
||||
} else {
|
||||
return (h >= nightStart && h < nightEnd);
|
||||
}
|
||||
}
|
||||
|
||||
void setRange(int a,int b){
|
||||
for(int i=a;i<=b;i++) targetBuffer[i]=currentColor;
|
||||
}
|
||||
|
||||
uint32_t blend(uint32_t c1, uint32_t c2, float t){
|
||||
uint8_t r1=(c1>>16)&255, g1=(c1>>8)&255, b1=c1&255;
|
||||
uint8_t r2=(c2>>16)&255, g2=(c2>>8)&255, b2=c2&255;
|
||||
return pixels.Color(r1+(r2-r1)*t, g1+(g2-g1)*t, b1+(b2-b1)*t);
|
||||
}
|
||||
|
||||
uint8_t gamma8(uint8_t x) {
|
||||
if (x == 0) return 0;
|
||||
// Verwende einen leicht angepassten Exponenten für den Nachtmodus
|
||||
float f = (float)x / 255.0;
|
||||
return (uint8_t)(pow(f, 2.0) * 255.0 + 0.5);
|
||||
}
|
||||
|
||||
uint32_t applyGammaBrightness(uint32_t c, float brightnessFactor) {
|
||||
// Wenn der Faktor extrem klein ist, erzwingen wir eine Mindesthelligkeit für aktive LEDs
|
||||
if (brightnessFactor < 0.01 && brightnessFactor > 0) brightnessFactor = 0.01;
|
||||
|
||||
uint8_t r = (uint8_t)(((c >> 16) & 255) * brightnessFactor);
|
||||
uint8_t g = (uint8_t)(((c >> 8) & 255) * brightnessFactor);
|
||||
uint8_t b = (uint8_t)((c & 255) * brightnessFactor);
|
||||
|
||||
return pixels.Color(gamma8(r), gamma8(g), gamma8(b));
|
||||
}
|
||||
|
||||
int getBrightness(struct tm *t){
|
||||
return isNightTime(t) ? nightBrightness : brightness;
|
||||
}
|
||||
|
||||
void showInstant(){
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
float b = getBrightness(t) / 255.0;
|
||||
for(int i=0;i<NUMPIXELS;i++){
|
||||
pixels.setPixelColor(i, applyGammaBrightness(targetBuffer[i], b));
|
||||
}
|
||||
pixels.show();
|
||||
}
|
||||
|
||||
void fadeToTargetSmooth(int steps = 30, int delayMs = 15) {
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
float bTarget = getBrightness(t) / 255.0;
|
||||
|
||||
// Im Nachtmodus faden wir langsamer (mehr Schritte), um das Springen zu kaschieren
|
||||
if (isNightTime(t)) {
|
||||
steps = 60;
|
||||
delayMs = 25;
|
||||
}
|
||||
|
||||
for (int s = 0; s <= steps; s++) {
|
||||
float tBlend = (float)s / steps;
|
||||
for (int i = 0; i < NUMPIXELS; i++) {
|
||||
uint32_t c = blend(currentBuffer[i], targetBuffer[i], tBlend);
|
||||
pixels.setPixelColor(i, applyGammaBrightness(c, bTarget));
|
||||
}
|
||||
pixels.show();
|
||||
yield(); // Verhindert WDT-Reset beim ESP8266
|
||||
delay(delayMs);
|
||||
}
|
||||
}
|
||||
|
||||
// ================= WORTUHR LOGIK =================
|
||||
void word_ES(){ setRange(0,1); } void word_IST(){ setRange(3,5); }
|
||||
void word_FUENF_M(){ setRange(7,10); } void word_ZEHN_M(){ setRange(18,20); }
|
||||
void word_ZWANZIG(){ setRange(11,17); } void word_VIERTEL(){ setRange(22,28); }
|
||||
void word_VOR(){ setRange(30,32); } void word_NACH(){ setRange(40,43); }
|
||||
void word_HALB(){ setRange(33,36); } void word_EINS(){ setRange(62,65); }
|
||||
void word_EIN(){ setRange(62,64); } void word_ZWEI(){ setRange(55,58); }
|
||||
void word_DREI(){ setRange(66,69); } void word_VIER(){ setRange(73,76); }
|
||||
void word_FUENF_H(){ setRange(51,54); } void word_SECHS(){ setRange(83,87); }
|
||||
void word_SIEBEN(){ setRange(88,93); } void word_ACHT(){ setRange(77,80); }
|
||||
void word_NEUN(){ setRange(44,47); } void word_ZEHN_H(){ setRange(106,109); }
|
||||
void word_ELF(){ setRange(103,105); } void word_ZWOELF(){ setRange(94,98); }
|
||||
void word_UHR(){ setRange(99,101); }
|
||||
|
||||
String getTimeText(int h, int m){
|
||||
int m5=(m/5)*5; if(m5>=25) h++;
|
||||
String arr[]={"Zwölf","Eins","Zwei","Drei","Vier","Fünf","Sechs","Sieben","Acht","Neun","Zehn","Elf"};
|
||||
String hT = arr[h%12]; if(m5==0 && h%12==1) hT = "ein";
|
||||
String t = "Es ist ";
|
||||
switch(m5){
|
||||
case 0: t+= hT + " Uhr"; break;
|
||||
case 5: t+= "fünf nach " + arr[h%12]; break;
|
||||
case 10: t+= "zehn nach " + arr[h%12]; break;
|
||||
case 15: t+= "viertel nach " + arr[h%12]; break;
|
||||
case 20: t+= "zwanzig nach " + arr[h%12]; break;
|
||||
case 25: t+= "fünf vor halb " + arr[h%12]; break;
|
||||
case 30: t+= "halb " + arr[h%12]; break;
|
||||
case 35: t+= "fünf nach halb " + arr[h%12]; break;
|
||||
case 40: t+= "zwanzig vor " + arr[h%12]; break;
|
||||
case 45: t+= "viertel vor " + arr[h%12]; break;
|
||||
case 50: t+= "zehn vor " + arr[h%12]; break;
|
||||
case 55: t+= "fünf vor " + arr[h%12]; break;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
void showTimeWords(int h, int m){
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
|
||||
for(int i=0;i<NUMPIXELS;i++) currentBuffer[i] = pixels.getPixelColor(i);
|
||||
|
||||
// HG Logik mit Nacht-Aus-Option
|
||||
uint32_t activeBg = 0;
|
||||
if(backgroundMode) {
|
||||
if(nightBackgroundDisabled && isNightTime(t)) {
|
||||
activeBg = 0;
|
||||
} else {
|
||||
activeBg = bgColor;
|
||||
}
|
||||
}
|
||||
for(int i=0;i<NUMPIXELS;i++) targetBuffer[i] = activeBg;
|
||||
|
||||
word_ES(); word_IST();
|
||||
int m5 = (m/5)*5; bool full = (m5 == 0); if(m5 >= 25) h++;
|
||||
switch(m5){
|
||||
case 0: word_UHR(); break;
|
||||
case 5: word_FUENF_M(); word_NACH(); break;
|
||||
case 10: word_ZEHN_M(); word_NACH(); break;
|
||||
case 15: word_VIERTEL(); word_NACH(); break;
|
||||
case 20: word_ZWANZIG(); word_NACH(); break;
|
||||
case 25: word_FUENF_M(); word_VOR(); word_HALB(); break;
|
||||
case 30: word_HALB(); break;
|
||||
case 35: word_FUENF_M(); word_NACH(); word_HALB(); break;
|
||||
case 40: word_ZWANZIG(); word_VOR(); break;
|
||||
case 45: word_VIERTEL(); word_VOR(); break;
|
||||
case 50: word_ZEHN_M(); word_VOR(); break;
|
||||
case 55: word_FUENF_M(); word_VOR(); break;
|
||||
}
|
||||
int hh = h % 12;
|
||||
if(hh == 1 && full) word_EIN();
|
||||
else if(hh == 1) word_EINS(); else if(hh == 2) word_ZWEI(); else if(hh == 3) word_DREI();
|
||||
else if(hh == 4) word_VIER(); else if(hh == 5) word_FUENF_H(); else if(hh == 6) word_SECHS();
|
||||
else if(hh == 7) word_SIEBEN(); else if(hh == 8) word_ACHT(); else if(hh == 9) word_NEUN();
|
||||
else if(hh == 10) word_ZEHN_H(); else if(hh == 11) word_ELF(); else word_ZWOELF();
|
||||
|
||||
if(forceInstant){ showInstant(); forceInstant = false; }
|
||||
else { fadeToTargetSmooth(20, 10); }
|
||||
}
|
||||
|
||||
// ================= WEB HANDLERS =================
|
||||
void handleStatus() {
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
char hexCol[10], hexBg[10];
|
||||
snprintf(hexCol, sizeof(hexCol), "#%06X", currentColor);
|
||||
snprintf(hexBg, sizeof(hexBg), "#%06X", bgColor);
|
||||
String ntpStat = (now > 100000) ? "OK" : "SYNC...";
|
||||
String json = "{";
|
||||
json += "\"txt\":\"" + getTimeText(t->tm_hour, t->tm_min) + "\",";
|
||||
json += "\"ip\":\"" + WiFi.localIP().toString() + "\",";
|
||||
json += "\"ntp\":\"" + ntpStat + "\",";
|
||||
json += "\"ntpServer\":\"" + ntpServer + "\",";
|
||||
json += "\"tzString\":\"" + tzString + "\",";
|
||||
json += "\"brightness\":" + String(brightness) + ",";
|
||||
json += "\"nightBrightness\":" + String(nightBrightness) + ",";
|
||||
json += "\"color\":\"" + String(hexCol) + "\",";
|
||||
json += "\"bgColor\":\"" + String(hexBg) + "\",";
|
||||
json += "\"night\":" + String(autoNight ? 1 : 0) + ",";
|
||||
json += "\"nightStart\":" + String(nightStart) + ",";
|
||||
json += "\"nightEnd\":" + String(nightEnd) + ",";
|
||||
json += "\"bg\":" + String(backgroundMode ? 1 : 0) + ",";
|
||||
json += "\"nightBgOff\":" + String(nightBackgroundDisabled ? 1 : 0);
|
||||
json += "}";
|
||||
server.send(200, "application/json", json);
|
||||
}
|
||||
|
||||
void handleRoot(){
|
||||
String html = R"rawliteral(
|
||||
<html><head><meta charset='UTF-8'><meta name='viewport' content='width=device-width, initial-scale=1'>
|
||||
<style>
|
||||
body{font-family:Arial,sans-serif; background:#fff; margin:0; color:#333; display:flex; flex-direction:column; align-items:center}
|
||||
.card{width:90%; max-width:400px; margin:10px; padding:15px; border-radius:12px; background:#f2f2f2; box-shadow: 0 2px 5px rgba(0,0,0,0.1)}
|
||||
.big{font-size:26px; text-align:center; font-weight:bold; color:#0055ff}
|
||||
input[type='range'], input[type='color'], input[type='text']{width:100%; margin-bottom:10px}
|
||||
button{width:100%; padding:12px; border-radius:8px; background:#0055ff; color:#fff; border:none; cursor:pointer}
|
||||
label{font-weight:bold; display:block; margin-bottom:5px}
|
||||
</style></head><body>
|
||||
<div class='card big' id='txt'>Lade...</div>
|
||||
<div class='card' id='status'>Verbinde...</div>
|
||||
<div class='card'><label>Farbe Worte</label><div> </div><input type='color' id='col' onchange="f('/color?c='+this.value.substring(1))">
|
||||
<label>Helligkeit</label><input type='range' id='br' min='0' max='255' oninput="f('/brightness?val='+this.value)"></div>
|
||||
<div class='card'><input type='checkbox' id='bg' onchange="f('/bg?val='+(this.checked?1:0))"> <b>Hintergrund</b><br><div> </div>
|
||||
<input type='color' id='bgcol' onchange="f('/bgcolor?c='+this.value.substring(1))"></div>
|
||||
<div class='card'><input type='checkbox' id='night' onchange="f('/night?val='+(this.checked?1:0))"> <b>Nachtmodus</b><br> <div> </div>
|
||||
Von: <input type='number' id='nS' style='width:50px' oninput="f('/nightStart?val='+this.value)"> Uhr
|
||||
Bis: <input type='number' id='nE' style='width:50px' oninput="f('/nightEnd?val='+this.value)"> Uhr<br><div> </div>
|
||||
<label>Nacht-Helligkeit</label><input type='range' id='nbr' min='0' max='255' oninput="f('/nightBrightness?val='+this.value)">
|
||||
<br><input type='checkbox' id='nightBgOff' onchange="f('/nightBgOff?val='+(this.checked?1:0))"> HG in Nacht aus</div>
|
||||
|
||||
<div class='card'><label>NTP Server:</label><input type='text' id='ntpS' onchange="f('/setNTP?val='+this.value)">
|
||||
<label>Zeitzone:</label><input type='text' id='tzS' onchange="f('/setTZ?val='+this.value)"></div>
|
||||
<div class='card'><button onclick="f('/save');alert('Gespeichert!')">EEPROM Speichern</button></div>
|
||||
<script>
|
||||
function f(u){fetch(u)}
|
||||
function u(){fetch('/status').then(r=>r.json()).then(d=>{
|
||||
document.getElementById('txt').innerText=d.txt;
|
||||
document.getElementById('status').innerText="IP: "+d.ip+" | NTP: "+d.ntp;
|
||||
const s=(i,v,c=false)=>{const e=document.getElementById(i);if(e&&document.activeElement!==e){if(c)e.checked=(v==1);else e.value=v;}};
|
||||
s('col',d.color);s('br',d.brightness);s('night',d.night,true);s('nS',d.nightStart);s('nE',d.nightEnd);
|
||||
s('nbr',d.nightBrightness);s('bg',d.bg,true);s('bgcol',d.bgColor);s('ntpS',d.ntpServer);s('tzS',d.tzString);
|
||||
s('nightBgOff',d.nightBgOff,true);
|
||||
})}
|
||||
setInterval(u, 2500); u();
|
||||
</script></body></html>)rawliteral";
|
||||
server.send(200, "text/html", html);
|
||||
}
|
||||
|
||||
void handleColor(){ if(server.hasArg("c")){ currentColor=strtoul(server.arg("c").c_str(),NULL,16); forceInstant=true; showTimeWords(lastH, lastMinute); } server.send(200); }
|
||||
void handleBGColor(){ if(server.hasArg("c")){ bgColor=strtoul(server.arg("c").c_str(),NULL,16); forceInstant=true; updateNeeded=true; } server.send(200); }
|
||||
void handleBrightness(){ brightness=server.arg("val").toInt(); forceInstant=true; updateNeeded=true; server.send(200); }
|
||||
void handleNight(){ autoNight=server.arg("val").toInt(); forceInstant=true; updateNeeded=true; server.send(200); }
|
||||
void handleNightStart(){ nightStart=server.arg("val").toInt(); forceInstant=true; updateNeeded=true; server.send(200); }
|
||||
void handleNightEnd(){ nightEnd=server.arg("val").toInt(); forceInstant=true; updateNeeded=true; server.send(200); }
|
||||
void handleNightBrightness(){ nightBrightness=server.arg("val").toInt(); forceInstant=true; updateNeeded=true; server.send(200); }
|
||||
void handleNightBgOff(){ nightBackgroundDisabled=server.arg("val").toInt(); forceInstant=true; updateNeeded=true; server.send(200); }
|
||||
void handleBG(){ backgroundMode=server.arg("val").toInt(); forceInstant=true; updateNeeded=true; server.send(200); }
|
||||
void handleNTP(){ ntpServer=server.arg("val"); configTime(tzString.c_str(), ntpServer.c_str()); server.send(200); }
|
||||
void handleTZ(){ tzString=server.arg("val"); configTime(tzString.c_str(), ntpServer.c_str()); server.send(200); }
|
||||
void handleSave(){ saveSettings(); server.send(200); }
|
||||
|
||||
// ================= SETUP & LOOP =================
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
WiFiManager wm; wm.autoConnect("Wortuhr");
|
||||
loadSettings();
|
||||
server.on("/", handleRoot);
|
||||
server.on("/status", handleStatus);
|
||||
server.on("/color", handleColor);
|
||||
server.on("/bgcolor", handleBGColor);
|
||||
server.on("/brightness", handleBrightness);
|
||||
server.on("/night", handleNight);
|
||||
server.on("/nightStart", handleNightStart);
|
||||
server.on("/nightEnd", handleNightEnd);
|
||||
server.on("/nightBrightness", handleNightBrightness);
|
||||
server.on("/nightBgOff", handleNightBgOff);
|
||||
server.on("/bg", handleBG);
|
||||
server.on("/setNTP", handleNTP);
|
||||
server.on("/setTZ", handleTZ);
|
||||
server.on("/save", handleSave);
|
||||
server.begin();
|
||||
pixels.begin();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
server.handleClient();
|
||||
|
||||
time_t now = time(nullptr);
|
||||
struct tm *t = localtime(&now);
|
||||
|
||||
if(t) {
|
||||
int currentM5 = (t->tm_min / 5) * 5;
|
||||
if(currentM5 != lastMinute || t->tm_hour != lastH){
|
||||
lastMinute = currentM5;
|
||||
lastH = t->tm_hour;
|
||||
updateNeeded = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(updateNeeded){
|
||||
showTimeWords(lastH, (t ? t->tm_min : 0));
|
||||
updateNeeded = false;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,528 @@
|
||||
/**
|
||||
* @file wordclock.ino
|
||||
* @author telegnom (ccc@telegnom.org)
|
||||
* @date 2019-02-23
|
||||
* @version 1.1
|
||||
*
|
||||
* @brief firmware for the c3e wordclock
|
||||
*
|
||||
* requires the time.h and timezone.h libraries
|
||||
* https://github.com/PaulStoffregen/Time/
|
||||
* https://github.com/JChristensen/Timezone/
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <FastLED.h>
|
||||
#include <TimeLib.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include <Timezone.h>
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <WiFiManager.h>
|
||||
|
||||
// #define BRIGHTNESS 200
|
||||
#define BRIGHTNESS_HIGH 200
|
||||
#define BRIGHTNESS_LOW 100
|
||||
#define BRIGHTNESS_HIGH_TIME 8
|
||||
#define BRIGHTNESS_LOW_TIME 20
|
||||
|
||||
#define NUM_LEDS 43
|
||||
#define DATA_PIN 5
|
||||
|
||||
CRGB leds[NUM_LEDS];
|
||||
|
||||
// NTP Servers:
|
||||
static const char ntpServerName[] = "pool.ntp.org";
|
||||
|
||||
// defining words
|
||||
|
||||
#define M_ES 0
|
||||
#define M_IST 1
|
||||
#define M_FUENF 2
|
||||
#define M_ZEHN 3
|
||||
#define M_ZWANZIG 4
|
||||
#define M_VIERTEL 5
|
||||
#define M_VOR 6
|
||||
#define M_NACH 8
|
||||
#define M_HALB 7
|
||||
#define M_UHR 21
|
||||
#define H_EINS 11
|
||||
#define H_ZWEI 12
|
||||
#define H_DREI 13
|
||||
#define H_VIER 14
|
||||
#define H_FUENF 10
|
||||
#define H_SECHS 15
|
||||
#define H_SIEBEN 17
|
||||
#define H_ACHT 16
|
||||
#define H_NEUN 9
|
||||
#define H_ZEHN 19
|
||||
#define H_ELF 20
|
||||
#define H_ZWOELF 18
|
||||
|
||||
TimeChangeRule myDST = {"CEST", Last, Sun, Mar, 2, 120}; //Daylight time = UTC - 4 hours
|
||||
TimeChangeRule mySTD = {"CET", Last, Sun, Oct, 2, 60}; //Standard time = UTC - 5 hours
|
||||
Timezone myTZ(myDST, mySTD);
|
||||
|
||||
int clockWords[22][10] = {
|
||||
{0,-1,-1,-1,-1,-1,-1,-1,-1,-1}, // es 0
|
||||
{1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, // ist 1
|
||||
{2,3,-1,-1,-1,-1,-1,-1,-1,-1}, // fuenf 2
|
||||
{7,8,-1,-1,-1,-1,-1,-1,-1,-1}, // zehn 3
|
||||
{4,5,6,-1,-1,-1,-1,-1,-1,-1}, // zwanzig 4
|
||||
{9,10,11,-1,-1,-1,-1,-1,-1,-1}, // viertel 5
|
||||
{12,-1,-1,-1,-1,-1,-1,-1,-1,-1}, // vor 6
|
||||
{13,14,-1,-1,-1,-1,-1,-1,-1,-1}, // nach 8
|
||||
{15,16,-1,-1,-1,-1,-1,-1,-1,-1}, // halb 7
|
||||
{17,18,-1,-1,-1,-1,-1,-1,-1,-1}, // neun 9
|
||||
{19,20,-1,-1,-1,-1,-1,-1,-1,-1}, // fuenf 10
|
||||
{23,24,-1,-1,-1,-1,-1,-1,-1,-1}, // eins 11
|
||||
{21,22,-1,-1,-1,-1,-1,-1,-1,-1}, // zwei 12
|
||||
{25,26,-1,-1,-1,-1,-1,-1,-1,-1}, // drei 13
|
||||
{27,28,-1,-1,-1,-1,-1,-1,-1,-1}, // vier 14
|
||||
{31,32,-1,-1,-1,-1,-1,-1,-1,-1}, // sechs 15
|
||||
{29,30,-1,-1,-1,-1,-1,-1,-1,-1}, // acht 16
|
||||
{33,34,35,-1,-1,-1,-1,-1,-1,-1}, // sieben 17
|
||||
{36,37,38,-1,-1,-1,-1,-1,-1,-1}, // zwölf 18
|
||||
{41,42,-1,-1,-1,-1,-1,-1,-1,-1}, // zehn 19
|
||||
{40,-1,-1,-1,-1,-1,-1,-1,-1,-1}, // elf 20
|
||||
{39,-1,-1,-1,-1,-1,-1,-1,-1}, // uhr 21
|
||||
};
|
||||
|
||||
WiFiUDP Udp;
|
||||
unsigned int localPort = 8888; // local port to listen for UDP packets
|
||||
time_t getNtpTime();
|
||||
time_t loctime;
|
||||
uint8_t color = 0;
|
||||
int lastmin = 100;
|
||||
void printDigits(int digits);
|
||||
void sendNTPpacket(IPAddress &address);
|
||||
uint8_t brightness = BRIGHTNESS_HIGH;
|
||||
|
||||
void clear(bool show=true)
|
||||
{
|
||||
for(int i = 0; i<NUM_LEDS;i++) {
|
||||
leds[i] = 0x000000;
|
||||
}
|
||||
if (show) {
|
||||
FastLED.show();
|
||||
}
|
||||
}
|
||||
|
||||
void noWifi()
|
||||
{
|
||||
for(int i=0; i<NUM_LEDS; i++)
|
||||
{
|
||||
leds[i] = CHSV((255/(NUM_LEDS-1))*i, 255, brightness);
|
||||
FastLED.show();
|
||||
}
|
||||
}
|
||||
|
||||
void printDigits(uint8_t digits, bool colon = true)
|
||||
{
|
||||
// utility for digital clock display: prints preceding colon and leading 0
|
||||
if (colon)
|
||||
{
|
||||
Serial.print(":");
|
||||
}
|
||||
if (digits < 10)
|
||||
Serial.print('0');
|
||||
Serial.print(digits);
|
||||
}
|
||||
|
||||
void digitalClockDisplay()
|
||||
{
|
||||
// digital clock display of the time
|
||||
printDigits((uint8_t) hour(loctime));
|
||||
printDigits((uint8_t) minute(loctime));
|
||||
printDigits((uint8_t) second(loctime));
|
||||
Serial.print(" ");
|
||||
Serial.print(day(loctime));
|
||||
Serial.print(".");
|
||||
Serial.print(month(loctime));
|
||||
Serial.print(".");
|
||||
Serial.print(year(loctime));
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
|
||||
clear();
|
||||
for (int initcount=0; initcount <= NUM_LEDS; initcount++) {
|
||||
clear();
|
||||
leds[initcount] = CHSV((255/NUM_LEDS)*initcount, 255, brightness);
|
||||
FastLED.show();
|
||||
delay(100);
|
||||
}
|
||||
clear();
|
||||
Serial.begin(115200);
|
||||
WiFiManager wifiManager;
|
||||
while (!Serial) ; // Needed for Leonardo only
|
||||
delay(250);
|
||||
Serial.println("WordClock by telegnom");
|
||||
Serial.print("Setup Wifi ... ");
|
||||
wifiManager.autoConnect("WordClock");
|
||||
Serial.println('[ ok ]');
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
noWifi();
|
||||
delay(500);
|
||||
}
|
||||
|
||||
Serial.print("IP number assigned by DHCP is ");
|
||||
Serial.println(WiFi.localIP());
|
||||
Serial.println("Starting UDP");
|
||||
Udp.begin(localPort);
|
||||
Serial.print("Local port: ");
|
||||
Serial.println(Udp.localPort());
|
||||
Serial.println("waiting for sync");
|
||||
setSyncProvider(getNtpTime);
|
||||
setSyncInterval(600);
|
||||
}
|
||||
|
||||
int prevDisplay = 100; // when the digital clock was displayed
|
||||
|
||||
void loop()
|
||||
{
|
||||
// time_t utc = now();
|
||||
loctime = myTZ.toLocal(now());
|
||||
if (timeStatus() != timeNotSet) {
|
||||
// if (prevDisplay != second(localtime))
|
||||
if (prevDisplay != second(loctime)) { //update the display only if time has changed
|
||||
prevDisplay = second(loctime);
|
||||
if (second()%10 == 0)
|
||||
{
|
||||
digitalClockDisplay();
|
||||
if (lastmin != minute(loctime))
|
||||
{
|
||||
setClock();
|
||||
}
|
||||
prevDisplay = second(loctime);
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void set_word(int word, time_t current_time = loctime) {
|
||||
int wordlen = sizeof(clockWords[word])/sizeof(clockWords[word][0]);
|
||||
if (lastmin != minute(loctime))
|
||||
{
|
||||
color += 40;
|
||||
}
|
||||
for (int i=0; i<wordlen; i++)
|
||||
{
|
||||
if (clockWords[word][i] >= 0)
|
||||
{
|
||||
leds[clockWords[word][i]] = CHSV(color, 255, brightness);
|
||||
Serial.print(clockWords[word][i]);
|
||||
Serial.print(" ");
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void set_brightness()
|
||||
{
|
||||
switch(int(hour(loctime)))
|
||||
{
|
||||
case BRIGHTNESS_HIGH_TIME:
|
||||
brightness = BRIGHTNESS_HIGH;
|
||||
break;
|
||||
case BRIGHTNESS_LOW_TIME:
|
||||
brightness = BRIGHTNESS_LOW;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void setClock() {
|
||||
Serial.println("Updating display...");
|
||||
time_t current_time = loctime;
|
||||
clear(false);
|
||||
set_brightness(); // ***Should set brightness
|
||||
set_word(M_ES); // switch es on
|
||||
set_word(M_IST); // switch ist on
|
||||
getMinuteWord(); //get word for "minute"
|
||||
getHourWord(); // get word for hour
|
||||
FastLED.show(); //writing to led stipe
|
||||
lastmin = minute(loctime);
|
||||
Serial.println("... display updated.");
|
||||
}
|
||||
|
||||
int getHour()
|
||||
{
|
||||
int h = int(hour(loctime));
|
||||
int m = int(minute(loctime));
|
||||
/*
|
||||
get current hour if minute < 20
|
||||
Es ist viertel nach zehn
|
||||
get next hour if minute >=25
|
||||
Es ist fuenf vor halb elf
|
||||
adjust hour to correct word around midnight:
|
||||
23:25 --> Es ist fuenf vor halb zwoelf
|
||||
*/
|
||||
Serial.println(m);
|
||||
if (m >= 25)
|
||||
{
|
||||
if (h < 23)
|
||||
{
|
||||
return h+1;
|
||||
} else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
} else
|
||||
{
|
||||
return h;
|
||||
}
|
||||
}
|
||||
|
||||
void getHourWord()
|
||||
{
|
||||
switch(getHour())
|
||||
{
|
||||
case 12:
|
||||
case 0:
|
||||
set_word(H_ZWOELF);
|
||||
Serial.println("zwoelf");
|
||||
break;
|
||||
case 1:
|
||||
case 13:
|
||||
// special case to get sigular @ "ein uhr"
|
||||
if (int(minute(loctime)) < 5)
|
||||
{
|
||||
set_word(H_EINS);
|
||||
Serial.println("ein");
|
||||
} else
|
||||
{
|
||||
set_word(H_EINS);
|
||||
Serial.println("eins");
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
case 14:
|
||||
set_word(H_ZWEI);
|
||||
Serial.println("zwei");
|
||||
break;
|
||||
case 3:
|
||||
case 15:
|
||||
set_word(H_DREI);
|
||||
Serial.println("drei");
|
||||
break;
|
||||
case 4:
|
||||
case 16:
|
||||
set_word(H_VIER);
|
||||
Serial.println("vier");
|
||||
break;
|
||||
case 5:
|
||||
case 17:
|
||||
set_word(H_FUENF);
|
||||
Serial.println("fuenf");
|
||||
break;
|
||||
case 6:
|
||||
case 18:
|
||||
set_word(H_SECHS);
|
||||
Serial.println("sechs");
|
||||
break;
|
||||
case 7:
|
||||
case 19:
|
||||
set_word(H_SIEBEN);
|
||||
Serial.println("sieben");
|
||||
break;
|
||||
case 8:
|
||||
case 20:
|
||||
set_word(H_ACHT);
|
||||
Serial.println("acht");
|
||||
break;
|
||||
case 9:
|
||||
case 21:
|
||||
set_word(H_NEUN);
|
||||
Serial.println("neun");
|
||||
break;
|
||||
case 10:
|
||||
case 22:
|
||||
set_word(H_ZEHN);
|
||||
Serial.println("zehn");
|
||||
break;
|
||||
case 11:
|
||||
case 23:
|
||||
set_word(H_ELF);
|
||||
Serial.println("elf");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void getMinuteWord()
|
||||
{
|
||||
/*
|
||||
get word for current "minute"
|
||||
*/
|
||||
switch(int(minute(loctime)))
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
set_word(M_UHR);
|
||||
Serial.println("uhr");
|
||||
break;
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
set_word(M_FUENF);
|
||||
set_word(M_NACH);
|
||||
Serial.println("fuenf nach");
|
||||
break;
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
set_word(M_ZEHN);
|
||||
set_word(M_NACH);
|
||||
Serial.println("zehn nach");
|
||||
break;
|
||||
case 15:
|
||||
case 16:
|
||||
case 17:
|
||||
case 18:
|
||||
case 19:
|
||||
set_word(M_VIERTEL);
|
||||
set_word(M_NACH);
|
||||
Serial.println("viertel nach");
|
||||
break;
|
||||
case 20:
|
||||
case 21:
|
||||
case 22:
|
||||
case 23:
|
||||
case 24:
|
||||
set_word(M_ZWANZIG);
|
||||
set_word(M_NACH);
|
||||
Serial.println("zwanzig nach");
|
||||
break;
|
||||
case 25:
|
||||
case 26:
|
||||
case 27:
|
||||
case 28:
|
||||
case 29:
|
||||
set_word(M_FUENF);
|
||||
set_word(M_VOR);
|
||||
set_word(M_HALB);
|
||||
Serial.println("fuenf vor halb");
|
||||
break;
|
||||
case 30:
|
||||
case 31:
|
||||
case 32:
|
||||
case 33:
|
||||
case 34:
|
||||
set_word(M_HALB);
|
||||
Serial.println("halb");
|
||||
break;
|
||||
case 35:
|
||||
case 36:
|
||||
case 37:
|
||||
case 38:
|
||||
case 39:
|
||||
set_word(M_FUENF);
|
||||
set_word(M_NACH);
|
||||
set_word(M_HALB);
|
||||
Serial.println("fuenf nach halb");
|
||||
break;
|
||||
case 40:
|
||||
case 41:
|
||||
case 42:
|
||||
case 43:
|
||||
case 44:
|
||||
set_word(M_ZWANZIG);
|
||||
set_word(M_VOR);
|
||||
Serial.println("zehn nach halb");
|
||||
break;
|
||||
case 45:
|
||||
case 46:
|
||||
case 47:
|
||||
case 48:
|
||||
case 49:
|
||||
set_word(M_VIERTEL);
|
||||
set_word(M_VOR);
|
||||
Serial.println("viertel vor");
|
||||
break;
|
||||
case 50:
|
||||
case 51:
|
||||
case 52:
|
||||
case 53:
|
||||
case 54:
|
||||
set_word(M_ZEHN);
|
||||
set_word(M_VOR);
|
||||
Serial.println("zehn vor");
|
||||
break;
|
||||
case 55:
|
||||
case 56:
|
||||
case 57:
|
||||
case 58:
|
||||
case 59:
|
||||
case 60:
|
||||
set_word(M_FUENF);
|
||||
set_word(M_VOR);
|
||||
Serial.println("fuenf vor");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*-------- NTP code ----------*/
|
||||
|
||||
const int NTP_PACKET_SIZE = 48; // NTP time is in the first 48 bytes of message
|
||||
byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming & outgoing packets
|
||||
|
||||
time_t getNtpTime()
|
||||
{
|
||||
IPAddress ntpServerIP; // NTP server's ip address
|
||||
|
||||
while (Udp.parsePacket() > 0) ; // discard any previously received packets
|
||||
Serial.println("Transmit NTP Request");
|
||||
// get a random server from the pool
|
||||
WiFi.hostByName(ntpServerName, ntpServerIP);
|
||||
Serial.print(ntpServerName);
|
||||
Serial.print(": ");
|
||||
Serial.println(ntpServerIP);
|
||||
sendNTPpacket(ntpServerIP);
|
||||
uint32_t beginWait = millis();
|
||||
while (millis() - beginWait < 1500) {
|
||||
int size = Udp.parsePacket();
|
||||
if (size >= NTP_PACKET_SIZE) {
|
||||
Serial.println("Receive NTP Response");
|
||||
Udp.read(packetBuffer, NTP_PACKET_SIZE); // read packet into the buffer
|
||||
unsigned long secsSince1900;
|
||||
// convert four bytes starting at location 40 to a long integer
|
||||
secsSince1900 = (unsigned long)packetBuffer[40] << 24;
|
||||
secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
|
||||
secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
|
||||
secsSince1900 |= (unsigned long)packetBuffer[43];
|
||||
return secsSince1900 - 2208988800UL;
|
||||
}
|
||||
}
|
||||
Serial.println("No NTP Response :-(");
|
||||
return 0; // return 0 if unable to get the time
|
||||
}
|
||||
|
||||
// send an NTP request to the time server at the given address
|
||||
void sendNTPpacket(IPAddress &address)
|
||||
{
|
||||
// set all bytes in the buffer to 0
|
||||
memset(packetBuffer, 0, NTP_PACKET_SIZE);
|
||||
packetBuffer[0] = 0b11100011; // LI, Version, Mode
|
||||
packetBuffer[1] = 0; // Stratum, or type of clock
|
||||
packetBuffer[2] = 6; // Polling Interval
|
||||
packetBuffer[3] = 0xEC; // Peer Clock Precision
|
||||
packetBuffer[12] = 49;
|
||||
packetBuffer[13] = 0x4E;
|
||||
packetBuffer[14] = 49;
|
||||
packetBuffer[15] = 52;
|
||||
Udp.beginPacket(address, 123); //NTP requests are to port 123
|
||||
Udp.write(packetBuffer, NTP_PACKET_SIZE);
|
||||
Udp.endPacket();
|
||||
}
|
||||
Reference in New Issue
Block a user