diff --git a/60LED_WS2812B_NTP_Clock.ino b/60LED_WS2812B_NTP_Clock.ino index 85566ad..8063ea1 100644 --- a/60LED_WS2812B_NTP_Clock.ino +++ b/60LED_WS2812B_NTP_Clock.ino @@ -4,7 +4,7 @@ #include #include -#include +#include // UpdateServer includes #ifdef ESP8266 #include @@ -33,6 +33,11 @@ ESP8266 24LED 5V--10k-+-LDR--GND -ADC - 150k--220k-+-100k--GND + ----------------- + ESP8266 60LED + 5V--??k-+-LDR--??k-GND + - 39k--220k-+-100k--GND + -ADC */ #ifdef ESP8266 #define LDR_PIN A0 @@ -57,8 +62,6 @@ volatile bool allDotsOn = true; //lighten up all leds #if NUM_LEDS == 60 volatile bool followingHour = true; //move hour like an analog one #else -//#endif -//#if NUM_LEDS == 24 volatile bool followingHour = false; //disabled due limited resolution #endif volatile int hourOffset = 0; @@ -200,9 +203,9 @@ 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 +//#define COLOR_ATTR_LENGTH 60 // -- Configuration specific key. The value should be modified if config structure was changed. -#define CONFIG_VERSION "V1.1.5" +#define CONFIG_VERSION "V1.1.7" const char CUSTOMHTML_SCRIPT_INNER[] PROGMEM = "\n\ function colorCh(id)\n\ @@ -218,43 +221,6 @@ const char CUSTOMHTML_SCRIPT_INNER[] PROGMEM = "\n\ btn.onclick = function() { if (p.type === 'password') { p.type = 'text'; btn.value = '🔒'; } else { p.type = 'password'; btn.value = '🔓'; } }\n\ };\n\ });\n"; -const char IOTWEBCONF_HTML_FORM_COLOR_PARAM[] PROGMEM = - "
({v})" - "" - "
{e}
\n"; - -// -- Our custom class declaration. You should move it to a .h fine in your project. -class ColorWithValueParameter : public iotwebconf::NumberParameter -{ - public: - ColorWithValueParameter( - const char* label, const char* id, char* valueBuffer, int length, - const char* defaultValue - ) : iotwebconf::NumberParameter( - label, id, valueBuffer, length, defaultValue) - { - snprintf( - this->_colorAttr, COLOR_ATTR_LENGTH, - "oninput='colorCh(this.id)'"); - - this->customHtml = this->_colorAttr; - }; - protected: - // Overrides - virtual String renderHtml( - bool dataArrived, bool hasValueFromPost, String valueFromPost) override - { - return TextParameter::renderHtml("color", hasValueFromPost, valueFromPost); - }; - virtual String getHtmlTemplate() - { - return FPSTR(IOTWEBCONF_HTML_FORM_COLOR_PARAM); - }; - - private: - char _colorAttr[COLOR_ATTR_LENGTH]; -}; // -- We need to create our custom HtmlFormatProvider to add some javasripts. class CustomHtmlFormatProvider : public iotwebconf::HtmlFormatProvider @@ -266,26 +232,10 @@ class CustomHtmlFormatProvider : public iotwebconf::HtmlFormatProvider HtmlFormatProvider::getScriptInner() + String(FPSTR(CUSTOMHTML_SCRIPT_INNER)); } - /* - String getBodyInner() override - { - return - String(FPSTR(CUSTOMHTML_BODY_INNER)) + - HtmlFormatProvider::getBodyInner(); - } - */ + }; // -- Javascript block will be added to the header. -/* - const char CUSTOMHTML_SCRIPT_INNER[] PROGMEM = "\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 = '83%'; 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"; -*/ +//const char CUSTOMHTML_BODY_INNER[] PROGMEM = " "; //const char CUSTOMHTML_BODY_INNER[] PROGMEM = " "; DNSServer dnsServer; WebServer server(80); @@ -295,41 +245,80 @@ ESP8266HTTPUpdateServer httpUpdater; HTTPUpdateServer httpUpdater; #endif -char ntpServerParamValue[STRING_LEN]; -char maxBrightnessParamValue[NUMBER_LEN]; -char singleSecondParamValue[STRING_LEN]; -char allDotsOnParamValue[STRING_LEN]; -char followingHourParamValue[STRING_LEN]; -char hourColorParamValue[COLOR_ATTR_LENGTH]; -char minuteColorParamValue[COLOR_ATTR_LENGTH]; -char secondsColorParamValue[COLOR_ATTR_LENGTH]; -char highnoonColorParamValue[COLOR_ATTR_LENGTH]; -char backlightColorParamValue[COLOR_ATTR_LENGTH]; -char hourMarkingColorParamValue[COLOR_ATTR_LENGTH]; - IotWebConf iotWebConf(thingName, &dnsServer, &server, wifiInitialApPassword, CONFIG_VERSION); -IotWebConfParameterGroup timeGroup = IotWebConfParameterGroup("Time", "Time settings"); -IotWebConfTextParameter ntpServerParam = IotWebConfTextParameter("NTP Server", "ntpServer", ntpServerParamValue, STRING_LEN, "pool.ntp.org"); -IotWebConfParameterGroup ledGroup = IotWebConfParameterGroup("LED", "LED settings"); -IotWebConfNumberParameter maxBrightnessParam = IotWebConfNumberParameter("Max BRIGHTNESS", "max brightness", maxBrightnessParamValue, NUMBER_LEN, "200", "20..254", "min='20' max='254' step='1'"); -#if NUM_LEDS == 60 -IotWebConfCheckboxParameter singleSecondParam = IotWebConfCheckboxParameter("Show Seconds", "singleSecond", singleSecondParamValue, STRING_LEN, true); -#else -IotWebConfCheckboxParameter singleSecondParam = IotWebConfCheckboxParameter("Show Seconds", "singleSecond", singleSecondParamValue, STRING_LEN, false); -#endif -IotWebConfCheckboxParameter allDotsOnParam = IotWebConfCheckboxParameter("all Dots lighten on", "allDotsOn", allDotsOnParamValue, STRING_LEN, true); -#if NUM_LEDS == 60 -IotWebConfCheckboxParameter followingHourParam = IotWebConfCheckboxParameter("following Hour", "followingHour", followingHourParamValue, STRING_LEN, true); -#else -IotWebConfCheckboxParameter followingHourParam = IotWebConfCheckboxParameter("following Hour", "followingHour", followingHourParamValue, STRING_LEN, false); -#endif -ColorWithValueParameter hourColorParam = ColorWithValueParameter("Stundenfarbe", "hourColorParam", hourColorParamValue, COLOR_ATTR_LENGTH, "#FFD700"); -ColorWithValueParameter minuteColorParam = ColorWithValueParameter("Minutenfarbe", "minuteColorParam", minuteColorParamValue, COLOR_ATTR_LENGTH, "#800000"); -ColorWithValueParameter secondsColorParam = ColorWithValueParameter("Sekundenfarbe", "secondsColorParam", secondsColorParamValue, COLOR_ATTR_LENGTH, "#000000"); -ColorWithValueParameter highnoonColorParam = ColorWithValueParameter("12Uhr Farbe", "highnoonColorParam", highnoonColorParamValue, COLOR_ATTR_LENGTH, "#C0C0C0"); -ColorWithValueParameter backlightColorParam = ColorWithValueParameter("Hintergrundfarbe", "backlightColorParam", backlightColorParamValue, COLOR_ATTR_LENGTH, "#1E2823"); -ColorWithValueParameter hourMarkingColorParam = ColorWithValueParameter("Stundenmarkierung", "hourMarkingColorParam", hourMarkingColorParamValue, COLOR_ATTR_LENGTH, "#787878"); +iotwebconf::ParameterGroup timeGroup = iotwebconf::ParameterGroup("Time", "Time settings"); +iotwebconf::TextTParameter ntpServerParam = + iotwebconf::Builder>("ntpServer"). + label("NTP Server"). + defaultValue("pool.ntp.org"). + build(); +iotwebconf::ParameterGroup ledGroup = iotwebconf::ParameterGroup("LED", "LED settings"); +iotwebconf::IntTParameter maxBrightnessParam = + iotwebconf::Builder>("Max Brightness"). + label("Max brightness"). + defaultValue(200). + min(MINIMAL_BRIGHTNESS). + max(MAX_BRIGHTNESS). + step(1). + build(); +iotwebconf::CheckboxTParameter singleSecondParam = + iotwebconf::Builder("singleSecond"). + label("single Second visible"). +#if NUM_LEDS == 60 + defaultValue(true). + build(); +#else + defaultValue(false). + build(); +#endif + +iotwebconf::CheckboxTParameter allDotsOnParam = + iotwebconf::Builder("allDotsOn"). + label("all Dots lighten on"). + defaultValue(true). + build(); + +iotwebconf::CheckboxTParameter followingHourParam = + iotwebconf::Builder("followingHour"). + label("following Hour"). +#if NUM_LEDS == 60 + defaultValue(true). + build(); +#else + defaultValue(false). + build(); +#endif +iotwebconf::ColorTParameter hourColorParam = + iotwebconf::Builder("Stundenfarbe"). + label("Stundenfarbe"). + defaultValue("#FFD700"). + build(); +iotwebconf::ColorTParameter minuteColorParam = + iotwebconf::Builder("Minutenfarbe"). + label("Minutenfarbe"). + defaultValue("#800000"). + build(); +iotwebconf::ColorTParameter secondsColorParam = + iotwebconf::Builder("Sekundenfarbe"). + label("Sekundenfarbe"). + defaultValue("#000000"). + build(); +iotwebconf::ColorTParameter highnoonColorParam = + iotwebconf::Builder("12 Uhr Farbe"). + label("12 Uhr Farbe"). + defaultValue("#C0C0C0"). + build(); +iotwebconf::ColorTParameter backlightColorParam = + iotwebconf::Builder("Hintergrundfarbe"). + label("Hintergrundfarbe"). + defaultValue("#1E2823"). + build(); +iotwebconf::ColorTParameter hourMarkingColorParam = + iotwebconf::Builder("Stundenmarkierung"). + label("Stundenmarkierung"). + defaultValue("#787878"). + build(); // -- An instance must be created from the class defined above. CustomHtmlFormatProvider customHtmlFormatProvider; @@ -364,7 +353,7 @@ String printLocalTime() { if (!getLocalTime(&timeinfo, 200)) { Serial.println("Failed to obtain time"); NTPreachable = false; - return ""; + return "N/A"; } //Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S"); @@ -386,7 +375,7 @@ void iotWebConfHandleRoot() { // -- Captive portal request were already served. return; } - char sTemp[12]; + //char sTemp[12]; String s = ""; s += ""; //s += CUSTOMHTML_BODY_INNER; @@ -398,45 +387,39 @@ void iotWebConfHandleRoot() { s += printLocalTime(); s += ""; s += ""; s += ""; s += ""; if (singleSecond) { s += ""; } if (allDotsOn) { s += ""; } s += "
NTP Server:"; - s += ntpServerParamValue; + s += ntpServerParam.value(); s += "
Current Brightness value: "; s += String(strip.GetBrightness()); s += "
Max Brightness value: "; - s += atoi(maxBrightnessParamValue); + s += maxBrightnessParam.value(); s += "
Show Seconds: "; - s += (singleSecond ? "Yes" : "No"); + s += (singleSecondParam.isChecked() ? "Yes" : "No"); s += "
All Dots On: "; - s += (allDotsOn ? "Yes" : "No"); + s += (allDotsOnParam.isChecked() ? "Yes" : "No"); s += "
Following Hour: "; - s += (followingHour ? "Yes" : "No"); + s += (followingHourParam.isChecked() ? "Yes" : "No"); s += "
"; s += "
High noon:
Hour color:
Minute color:
Seconds color:
Backlight:
Hour Marking:
"; s += "

"; s += "Go to configure page to change values."; @@ -448,7 +431,7 @@ void iotWebConfHandleRoot() { void iotWebConfConfigSaved() { //ToDo ntpServerParamValue; - MAX_BRIGHTNESS = atoi(maxBrightnessParamValue); + MAX_BRIGHTNESS = maxBrightnessParam.value(); singleSecond = singleSecondParam.isChecked() ? true : false; //Serial.println(singleSecondParam.isChecked() ? "true" : "false"); allDotsOn = allDotsOnParam.isChecked() ? true : false; @@ -458,12 +441,12 @@ void iotWebConfConfigSaved() #endif //Serial.println(followingHourParam.isChecked() ? "true" : "false"); - transformHtmltoStrip(&highnoonColor, (char*)&highnoonColorParamValue); - transformHtmltoStrip(&hourColor, (char*)&hourColorParamValue); - transformHtmltoStrip(&minuteColor, (char*)&minuteColorParamValue); - transformHtmltoStrip(&secondsColor, (char*)&secondsColorParamValue); - transformHtmltoStrip(&backlightColor, (char*)&backlightColorParamValue); - transformHtmltoStrip(&hourMarkingColor, (char*)&hourMarkingColorParamValue); + transformHtmltoStrip(&highnoonColor, (char*)&highnoonColorParam.value()); + transformHtmltoStrip(&hourColor, (char*)&hourColorParam.value()); + transformHtmltoStrip(&minuteColor, (char*)&minuteColorParam.value()); + transformHtmltoStrip(&secondsColor, (char*)&secondsColorParam.value()); + transformHtmltoStrip(&backlightColor, (char*)&backlightColorParam.value()); + transformHtmltoStrip(&hourMarkingColor, (char*)&hourMarkingColorParam.value()); Serial.println("Configuration was updated."); } @@ -519,7 +502,7 @@ void syncNTP() { //init and get the time #ifdef ESP8266 //sntp_servermode_dhcp(0); - configTime(MYTZ, ntpServerParamValue); + configTime(MYTZ, ntpServerParam.value()); #endif #ifdef ESP32 configTime(0, 0, ntpServer); @@ -545,11 +528,12 @@ void syncNTP() { Serial.println("NTP mapped: " + String(int(currentHour * NUM_LEDS / 12)) + ":" + String(int(currentMin * NUM_LEDS / 60)) + ":" + String(int(currentSec * NUM_LEDS / 60))); bootAnim.disable(); ledRefresh.enable(); - clockTick.enable(); + //clockTick.enable(); #ifdef LDR_PIN brightness.enable(); #endif } + clockTick.enable(); //enable to check for ntp every 60 seconds } } @@ -587,6 +571,8 @@ void setup() { iotWebConf_Setup(); //Serial.end(); + ESP.wdtDisable(); + ESP.wdtEnable(2000); } void loop()