diff --git a/60LED_WS2812B_NTP_Clock.ino b/60LED_WS2812B_NTP_Clock.ino index 9c506cf..bdb7356 100644 --- a/60LED_WS2812B_NTP_Clock.ino +++ b/60LED_WS2812B_NTP_Clock.ino @@ -20,6 +20,7 @@ #include // For ESP32 IotWebConf provides a drop-in replacement for UpdateServer. # include +#include #endif @@ -182,7 +183,7 @@ void transformHtmltoStrip(RgbColor* outputColor, char* sInput) { #endif -//const char* ntpServer = "pool.ntp.org"; +const char* ntpServer = "pool.ntp.org"; const long gmtOffset_sec = 3600; //ToDo changable from user const int daylightOffset_sec = 3600; struct tm timeinfo; @@ -206,7 +207,7 @@ const char wifiInitialApPassword[] = "12345678"; // -- 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.7" +#define CONFIG_VERSION "V1.1.8" const char CUSTOMHTML_SCRIPT_INNER[] PROGMEM = "\n\ function colorCh(id)\n\ @@ -439,6 +440,9 @@ void iotWebConfConfigSaved() //Serial.println(allDotsOnParam.isChecked() ? "true" : "false"); #if NUM_LEDS == 60 followingHour = followingHourParam.isChecked() ? true : false; + if (!followingHour) { + hourOffset = 0 ; + } #endif //Serial.println(followingHourParam.isChecked() ? "true" : "false"); @@ -472,6 +476,7 @@ void iotWebConf_Setup() { iotWebConf.addParameterGroup(&ledGroup); iotWebConf.setConfigSavedCallback(&iotWebConfConfigSaved); + //iotWebConf.setWifiConnectionTimeoutMs(60000); iotWebConf.setWifiConnectionCallback(&syncNTP); //NTP call after connection established //iotWebConf.setFormValidator(&iotWebConfFormValidator); iotWebConf.getApTimeoutParameter()->visible = true; @@ -535,6 +540,7 @@ void syncNTP() { #endif } clockTick.enable(); //enable to check for ntp every 60 seconds + iotwebconfLoop.enable(); } } @@ -549,13 +555,30 @@ void setup() { 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) Serial.print(getCpuFrequencyMhz()); //Get CPU clock -#endif Serial.println(" Mhz"); + 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 ); @@ -568,19 +591,25 @@ void setup() { runner.addTask(brightness); #endif runner.addTask(bootAnim); - //runner.addTask(iotWebConf.Loop); + runner.addTask(iotwebconfLoop); bootAnim.enable(); iotWebConf_Setup(); //Serial.end(); +#ifdef ESP8266 ESP.wdtDisable(); - ESP.wdtEnable(2000); + ESP.wdtEnable(1000); +#endif +#if defined(ESP32) +#endif } void loop() { runner.execute(); - iotWebConf.doLoop(); //ToDo put in a task, measure the runtime + yield(); + //iotWebConfLoopCallback();//ToDo put in a task, measure the runtime + ESP.wdtFeed(); /* while (Serial.available()) Serial.read(); @@ -606,14 +635,14 @@ void ledRefreshCallback() { } strip.SetPixelColor(0, highnoonColor); //define high noon - if (singleSecond) { - strip.SetPixelColor(MOD(int(currentSec * NUM_LEDS / 60 + 0), NUM_LEDS), secondsColor); - } #if NUM_LEDS == 60 //3 dots hour strip.SetPixelColor(MOD(int(currentHour * NUM_LEDS / 12 - 1 + hourOffset), NUM_LEDS), hourColor); strip.SetPixelColor(MOD(int(currentHour * NUM_LEDS / 12 + 0 + hourOffset), NUM_LEDS), hourColor); strip.SetPixelColor(MOD(int(currentHour * NUM_LEDS / 12 + 1 + hourOffset), NUM_LEDS), hourColor); + if (singleSecond) { + strip.SetPixelColor(MOD(int(currentSec * NUM_LEDS / 60 + 0), NUM_LEDS), allDotsOn ? secondsColor : backlightColor); + } #else strip.SetPixelColor(MOD(int(currentHour * NUM_LEDS / 12 + 0 + hourOffset), NUM_LEDS) , hourColor); #endif @@ -642,8 +671,8 @@ void clockTickCallback() { } } if (followingHour) { - hourOffset = int (currentMin * NUM_LEDS / 60 / 12); //negative value - //Serial.println("hourOffset: " + String(hourOffset)); + hourOffset = int(currentMin * NUM_LEDS / 60 / 12); + //Serial.println("clockwise hourOffset: " + String(hourOffset)); } //Serial.println(String(interruptCounter) + " | Ring Index: " + String(currentHour / (12 / NUM_LEDS)) + ":" + String(currentMin / (60 / NUM_LEDS)) + ":" + String(currentSec / (60 / NUM_LEDS))); } @@ -666,8 +695,8 @@ void clockTickCallback() { } } if (followingHour) { - hourOffset = 0 + int((60 - currentMin * NUM_LEDS / 60) / 12); //negative value - //Serial.println("hourOffset: " + String(hourOffset)); + hourOffset = 0 - int((60 - currentMin * NUM_LEDS / 60) / 12); //negative value + //Serial.println("Anticlockwise hourOffset: " + String(hourOffset)); } //Serial.println(String(interruptCounter) + " | Ring Index: " + String(currentHour / (12 / NUM_LEDS)) + ":" + String(currentMin / (60 / NUM_LEDS)) + ":" + String(currentSec / (60 / NUM_LEDS))); }