From db6cd39b01c56d1cc812df62a061994422349abf Mon Sep 17 00:00:00 2001 From: coelner Date: Sun, 30 Jan 2022 15:44:36 +0100 Subject: [PATCH] further doing --- 60LED_WS2812B_NTP_Clock.ino | 172 +++++++++++++----------------------- iotwebconf.ino | 30 ------- main.ino | 81 +++++++++++++++++ 3 files changed, 142 insertions(+), 141 deletions(-) create mode 100644 main.ino diff --git a/60LED_WS2812B_NTP_Clock.ino b/60LED_WS2812B_NTP_Clock.ino index 33bcb66..51e31a3 100644 --- a/60LED_WS2812B_NTP_Clock.ino +++ b/60LED_WS2812B_NTP_Clock.ino @@ -60,6 +60,35 @@ void brightnessAdjustmentCallback(); void brightnessFadingCallback(); void iotWebConfLoopCallback(); + +const char* ntpServer = "pool.ntp.org"; +const long gmtOffset_sec = 3600; //ToDo changable from user +const int daylightOffset_sec = 3600; +struct tm timeinfo; + +volatile int currentSec = 59; +volatile int currentMin = 1; +volatile int currentHour = 2; +volatile bool NTPreachable = false; + +volatile int MAX_BRIGHTNESS = 200; +#ifdef LDR_PIN +// variable for storing the potentiometer value +volatile unsigned int ldrValue = 0; +volatile unsigned int targetBrightness = MAX_BRIGHTNESS; +#endif + +// WebPortal +const char thingName[] = "NTP-Clock-RGBLED"; +const char wifiInitialApPassword[] = "12345678"; +#define STRING_LEN 63 +#define NUMBER_LEN 4 +// -- Maximal length the input-range attributes can have. +//#define COLOR_ATTR_LENGTH 60 +// -- Configuration specific key. The value should be modified if config structure was changed. +#define CONFIG_VERSION "V1.1.8" + + #ifdef RGBW #define MINIMAL_BRIGHTNESS 5 #define LDR_SCALE 4 @@ -119,9 +148,9 @@ void transformHtmltoStrip(RgbwColor* outputColor, char* sInput) { //Serial.printf("StripColor: R:%i G:%i B:%i W:%i\n", stripColor.R, stripColor.G, stripColor.B, stripColor.W); memcpy(outputColor, &stripColor, sizeof(stripColor)); } +#endif - -#else +#ifndef RGBW #define MINIMAL_BRIGHTNESS 20 #define LDR_SCALE 16 #define colorSaturation 192 @@ -169,34 +198,6 @@ void transformHtmltoStrip(RgbColor* outputColor, char* sInput) { } #endif - -const char* ntpServer = "pool.ntp.org"; -const long gmtOffset_sec = 3600; //ToDo changable from user -const int daylightOffset_sec = 3600; -struct tm timeinfo; - -volatile int currentSec = 59; -volatile int currentMin = 1; -volatile int currentHour = 2; -volatile bool NTPreachable = false; - -volatile int MAX_BRIGHTNESS = 200; -#ifdef LDR_PIN -// variable for storing the potentiometer value -volatile unsigned int ldrValue = 0; -volatile unsigned int targetBrightness = MAX_BRIGHTNESS; -#endif - -// WebPortal -const char thingName[] = "NTP-Clock-RGBLED"; -const char wifiInitialApPassword[] = "12345678"; -#define STRING_LEN 63 -#define NUMBER_LEN 4 -// -- Maximal length the input-range attributes can have. -//#define COLOR_ATTR_LENGTH 60 -// -- Configuration specific key. The value should be modified if config structure was changed. -#define CONFIG_VERSION "V1.1.8" - DNSServer dnsServer; WebServer server(80); #ifdef ESP8266 @@ -279,6 +280,36 @@ iotwebconf::ColorTParameter hourMarkingColorParam = label("Stundenmarkierung"). defaultValue("#787878"). build(); +const char CUSTOMHTML_SCRIPT_INNER[] PROGMEM = "\n\ + function colorCh(id)\n\ + {\n\ + var x=document.getElementById(id);\n\ + var s=document.getElementById(id + 'Val');\n\ + s.innerHTML = x.value;\n\ + }\n\n\ + document.addEventListener('DOMContentLoaded', function(event) {\n\ + let elements = document.querySelectorAll('input[type=\"password\"]');\n\ + for (let p of elements) {\n\ + let btn = document.createElement('INPUT'); btn.type = 'button'; btn.value = '🔓'; btn.style.width = 'auto'; p.style.width = '80%'; p.parentNode.insertBefore(btn,p.nextSibling);\n\ + btn.onclick = function() { if (p.type === 'password') { p.type = 'text'; btn.value = '🔒'; } else { p.type = 'password'; btn.value = '🔓'; } }\n\ + };\n\ + });\n"; + +// -- We need to create our custom HtmlFormatProvider to add some javasripts. +class CustomHtmlFormatProvider : public iotwebconf::HtmlFormatProvider +{ + protected: + String getScriptInner() override + { + return + HtmlFormatProvider::getScriptInner() + + String(FPSTR(CUSTOMHTML_SCRIPT_INNER)); + } + +}; +// -- Javascript block will be added to the header. +//const char CUSTOMHTML_BODY_INNER[] PROGMEM = " "; +//const char CUSTOMHTML_BODY_INNER[] PROGMEM = " "; // -- An instance must be created from the class defined above. CustomHtmlFormatProvider customHtmlFormatProvider; @@ -292,84 +323,3 @@ Task brightnessFading(333, TASK_FOREVER, &brightnessFadingCallback); #endif Task iotwebconfLoop(1000, TASK_FOREVER, &iotWebConfLoopCallback); Scheduler runner; - -void setup() { -#ifdef LDR_PIN - pinMode(LDR_PIN, INPUT_PULLUP); -#endif - pinMode(DATA_PIN, OUTPUT); - - Serial.begin(SERIAL_BAUD); - Serial.flush(); - delay(100); - Serial.println(); - Serial.print("\n\n\nCPU Frequency is: "); -#ifdef ESP8266 - Serial.print(ESP.getCpuFreqMHz()); - Serial.println(" Mhz"); - Serial.print("Chip ID: "); - Serial.println(ESP.getFlashChipId()); -#elif defined(ESP32) - setCpuFrequencyMhz(160); - Serial.print(getCpuFrequencyMhz()); //Get CPU clock - Serial.println(" Mhz"); - uint32_t Freq = getXtalFrequencyMhz(); - Serial.print("XTAL Freq = "); - Serial.print(Freq); - uint32_t chipId = 0; - for (int i = 0; i < 17; i = i + 8) { - chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i; - } - - Serial.printf("ESP32 Chip model = %s Rev %d\n", ESP.getChipModel(), ESP.getChipRevision()); - Serial.printf("This chip has %d cores\n", ESP.getChipCores()); - Serial.print("Chip ID: "); Serial.println(chipId); -#endif - Serial.print("MAC address: "); - Serial.println(WiFi.macAddress()); //Get CPU clock - -#ifdef RGBW - Serial.println("RGBW"); -#else - Serial.println("RGB"); -#endif - - strip.Begin(); - strip.ClearTo(white); - strip.SetBrightness( MINIMAL_BRIGHTNESS ); - strip.Show(); - - runner.init(); - runner.addTask(ledRefresh); - runner.addTask(clockTick); -#ifdef LDR_PIN - runner.addTask(brightnessAdjustment); - runner.addTask(brightnessFading); -#endif - runner.addTask(bootAnim); - runner.addTask(iotwebconfLoop); - bootAnim.enable(); - iotwebconfLoop.enable(); - - iotWebConf_Setup(); - //Serial.end(); -#ifdef ESP8266 - ESP.wdtDisable(); - ESP.wdtEnable(1000); -#endif -#if defined(ESP32) -#endif -} - -void loop() -{ - runner.execute(); - yield(); -#ifdef ESP8266 - ESP.wdtFeed(); -#endif - /* - while (Serial.available()) - Serial.read(); - */ -} diff --git a/iotwebconf.ino b/iotwebconf.ino index 9a2c71a..d4c9ae9 100644 --- a/iotwebconf.ino +++ b/iotwebconf.ino @@ -1,33 +1,3 @@ -const char CUSTOMHTML_SCRIPT_INNER[] PROGMEM = "\n\ - function colorCh(id)\n\ - {\n\ - var x=document.getElementById(id);\n\ - var s=document.getElementById(id + 'Val');\n\ - s.innerHTML = x.value;\n\ - }\n\n\ - document.addEventListener('DOMContentLoaded', function(event) {\n\ - let elements = document.querySelectorAll('input[type=\"password\"]');\n\ - for (let p of elements) {\n\ - let btn = document.createElement('INPUT'); btn.type = 'button'; btn.value = '🔓'; btn.style.width = 'auto'; p.style.width = '80%'; p.parentNode.insertBefore(btn,p.nextSibling);\n\ - btn.onclick = function() { if (p.type === 'password') { p.type = 'text'; btn.value = '🔒'; } else { p.type = 'password'; btn.value = '🔓'; } }\n\ - };\n\ - });\n"; - -// -- We need to create our custom HtmlFormatProvider to add some javasripts. -class CustomHtmlFormatProvider : public iotwebconf::HtmlFormatProvider -{ - protected: - String getScriptInner() override - { - return - HtmlFormatProvider::getScriptInner() + - String(FPSTR(CUSTOMHTML_SCRIPT_INNER)); - } - -}; -// -- Javascript block will be added to the header. -//const char CUSTOMHTML_BODY_INNER[] PROGMEM = " "; -//const char CUSTOMHTML_BODY_INNER[] PROGMEM = " "; /** Handle web requests to "/" path. diff --git a/main.ino b/main.ino new file mode 100644 index 0000000..9582435 --- /dev/null +++ b/main.ino @@ -0,0 +1,81 @@ + +void setup() { +#ifdef LDR_PIN + pinMode(LDR_PIN, INPUT_PULLUP); +#endif + pinMode(DATA_PIN, OUTPUT); + + Serial.begin(SERIAL_BAUD); + Serial.flush(); + delay(100); + Serial.println(); + Serial.print("\n\n\nCPU Frequency is: "); +#ifdef ESP8266 + Serial.print(ESP.getCpuFreqMHz()); + Serial.println(" Mhz"); + Serial.print("Chip ID: "); + Serial.println(ESP.getFlashChipId()); +#elif defined(ESP32) + setCpuFrequencyMhz(160); + Serial.print(getCpuFrequencyMhz()); //Get CPU clock + Serial.println(" Mhz"); + uint32_t Freq = getXtalFrequencyMhz(); + Serial.print("XTAL Freq = "); + Serial.print(Freq); + uint32_t chipId = 0; + for (int i = 0; i < 17; i = i + 8) { + chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i; + } + + Serial.printf("ESP32 Chip model = %s Rev %d\n", ESP.getChipModel(), ESP.getChipRevision()); + Serial.printf("This chip has %d cores\n", ESP.getChipCores()); + Serial.print("Chip ID: "); Serial.println(chipId); +#endif + Serial.print("MAC address: "); + Serial.println(WiFi.macAddress()); //Get CPU clock + +#ifdef RGBW + Serial.println("RGBW"); +#else + Serial.println("RGB"); +#endif + + strip.Begin(); + strip.ClearTo(white); + strip.SetBrightness( MINIMAL_BRIGHTNESS ); + strip.Show(); + + runner.init(); + runner.addTask(ledRefresh); + runner.addTask(clockTick); +#ifdef LDR_PIN + runner.addTask(brightnessAdjustment); + runner.addTask(brightnessFading); +#endif + runner.addTask(bootAnim); + runner.addTask(iotwebconfLoop); + bootAnim.enable(); + iotwebconfLoop.enable(); + + iotWebConf_Setup(); + //Serial.end(); +#ifdef ESP8266 + ESP.wdtDisable(); + ESP.wdtEnable(1000); +#endif +#if defined(ESP32) +#endif +} + +void loop() +{ + runner.execute(); + yield(); +#ifdef ESP8266 + ESP.wdtFeed(); +#endif + /* + while (Serial.available()) + Serial.read(); + */ +}