Elektronik_Header_3LŘftersteuerung mit ESP-01


Logbuch QlockWiMu

Alle Änderungen gegenüber Manuel Brachers QlockWiFive Firmware für Wort-Uhren:

An advanced firmware for a DIY "word-clock".

@mc      ESP8266
@created 01.02.2017

Changes from original firmware of bracci by deHarry:
- 19.01.2019
Added support for BH1750 LightSensor (as replacement for LDR)
  The brightness adaption is managed by an BH1750 ambient light sensor which is conected via I2C bus.
  To enable the BH1750 uncomment define USE_BH1750 in Configuration.h.
  To make the BH1750 working you have to include the new class "BH1750_LightSensor" (.cpp, .h files) into the project.
  Be sure to have PullUps at I2C signals SDA and SCL, respectively - the BH1750 has no PullUps on board.

- 02.12.2019 - FW 20191202
Added support for entering NTP timeserver via WEB interface
  I had sporadic problems with the default ntp server and wanted to change it to another address easily and without recompiling.

- 05.01.2020
Reworked the time code to make the clock able to run without _permanent_ network connection and _without RTC-Chip_.
Problem: Some users want to have a wordclock based on the code from bracci (QlockWiFive), with all its stunning features, but
  don't want to have their WLAN running all the time. With the original firmware, QlockWiFive, the clock reverts to 12 o'clock
  when there is no NTP server available (provided, that no RTC chip is implemented).
  Therefore I added a software clock which is set once in 24 hours from WLAN (if connected) and which is driven from the
  secondly heartbeat signal of the DS3231RTC. This allows an accurate clock without having to read the time every minute
  from the RTC (which demonstrably slows down the internal counter of the RTC, at least on my cheap RTC modules - have a look at
  http://www.harald-sattler.de/html/ds3231_-_ungenau-.htm, in german -> use "google translate" at the bottom of the page)
  and preventing the clock from reverting to 12 o'clock midnight on 01.01.1970 after not reaching a time server on the internet.
  The solution is somewhat weird, since the clock has to have a RTC, but the time information of the RTC is not used.
  Instead the SQW output of the RTC chip is utilized to clock a software clock.
  To switch on the SQW signal, which is defaulted to OFF, the RTC has to be connected via I2C.
  Enabling the define USE_RTC_SQW also enables RTC_BACKUP to make use of the existing routines for initialization and reading.
  Only the register accesses to the RTC have to be suppressed to prevent the slowing down of the clock.
  To enable this SQW feature uncomment define USE_RTC_SQW in Configuration.h.
  --> not finished yet! <--

- 12.01.2020 - FW 20200112
Changed support for outdoor weather information to OpenWeatherMap service (OWM) https://openweathermap.org/ (by copying/merging
  the implementation of Th0rsten from his QlockWork into Braccis QlockWiFi. Thank you Th0rsten!) - see #define APIKEY 
  The API for current weather is described at OWM https://openweathermap.org/current.
  You have to get your own API-Key from OWM (you have to register with a valid email address) to get it working.
Added WEB interface option to enter the OWM API-Key
  nota bene: You can enter the ZIP code and country as well (e.g. "76131, DE"), the resulting weather data and lon/lat values are
  identical. But they translate the ZIP code into false city names (at least for my home city). This can be seen in the OWM response (debug).

- 21.01.2020 - FW 20200121
Added visualization of weather icon from OWM in WEB interface

- 24.01.2020 - FW 20200124
Get rid of Fahrenheit and other notations when location is in Germany ("xxx, DE" or "xxx, de")
Description of weather conditions in german when location is in Germany (clear sky -> Klarer Himmel)
Added pressure reading to list of weather conditions in WEB interface

- 25.01.2020 - FW 20200125
Finished SQW workaround for running without WLAN.
  When WLAN connection is lost during operation the A in the center of the display is lit (for a short time on minute update. Seen
  best with transition "fade". To be honest, it can be seen _only_ with fade transition, all other transitions are too fast).
  To set the time, WLAN connection has to be established at least once (no manual setting implemented, yet)
  -> Have to check whether reading temperature from RTC also slows down the RTC internal clock... -> look for 2x "!defined(USE_RTC_SQW)"

- 26.01.2020 - FW 20200127
Get completely rid of RTC readings when using SQW (RTC time was slow by 3 minutes in 10 hours) -> no temperature readout in WEB interface.
  The deviations seem to result from a too slow RTC-Module clock.
Implemented time correction "countCorrSecs".
  Measurements revealed a loss of one second every 345 seconds when SoftClock is triggered by SQW :(
  (It's ~2.898 ms per second)
  So I add one second every 345 seconds to compensate for that. Runs smoothly with DS3231 and SQW controlling the clock.

- 29.01.2020 - FW 20200129
Rearranged the checks and conditions for NTP updates after missing WLAN. There where issues when WLAN was accessible but NTP server was not.
  Now the automatic restarting of Station Mode works under all conditions of missing ressources.

- 02.02.2020 - FW 20200202
Idea: Implement a means of catching the time deviation of the free running clock when there is no WLAN/no NTP server. A calibration value
  is derived from the measurement and can be entered in the GUI to adjust the clock speed.
  To calibrate the clock, call "xxx/calibrate" from your WEB browser where xxx is the IP address of the clock.
  In turn, the time is captured and the check run is started. The passed time since start of the calibration run is displayed like normal (in words).
  Seconds display is switched on for the last 10 seconds of every minute, so one can compare the passed time against a stop watch.
  At least three hours should be measured to get a decent result (see HOURS2CHECK).

- 06.02.2020 - FW 20200206
Show only the last octet of the IP address at power on. If this octet has 3 digits srcoll it, 2 digits are shown statically for one second.
Calibration code implemented. Search for define ENABLE_CALIBRATION.
  The calibration is issued automatically. After 3 hours (see HOURS2CHECK) the calibration run is stopped and the calibration value is
  derived from the deviation between ESP clock and NTP clock. No need to put the clock into normal mode manually. During the test run
  the clock shows the normal time (without deviation, derived from NTP server).
  The GUI shows whether a RTC is installed, whether a calibration is running, the current calibration value and the remaining time for the test.
  The calibration value is stored via settings to EEPROM automatically and is applied from then on with every start.
  The calibration is only issued if the NTP server is local (i.e. the own router. Explanation see text at bottom of this file).
Changed recognition of "internal" NTP server to only check the first two octets of the IP to be "192.168.".

- 07.02.2020 - FW 20200207
Added possibility to make a calibration run even if no RTC module is present.
Added time display to the GUI.
Added some info about calibration and RTC present/not present to the GUI.

- 08.02.2020 - FW20200208
Check for RTC module only once in setup()

- 14.02.2020 - FW20200214
Added layout for 144 LED/m strips with only every second LED in use (preparations for 190er WordClock with ESP-01)
Added GUI for viewing debug values (call "IP-address/getDebugVals" in browser)

- 17.02.2020 - FW20200217
ESP time is only set once every random minute (to relieve NTP server). When NTP server is local (e.g. the own Router),
  the time is set every minute (look for 2020-02-17)

- 23.02.2020 - FW20200223
New matrix for 144 LEDs/m implemented, runs with ESP-01 and BH1750

- 02.03.2020 - FW20200302
New matrices for 2 CJMCU LED modules implemented, runs with Wemos D1 mini, compiled as Generic ESP8266 Module

- 12.05.2020 - FW20200512
Mating QlockWiFive with MAX98357A I2S audio amplifier (wake up by music instead of beeper).
It is advisable to use a Wemos D1 mini Pro, featuring 16 MByte of Flash memory,
feasible of storing up to 14 MByte of MP3 music (~ 6 minutes sound)
I use the routines of Earle F. Philhower, III, https://github.com/earlephilhower/ESP8266Audio to play MP3 files.

Redefined some IOs due to
- settled pin definitions in AudioOutputI2S lib (Rx) and
- boot problems (mode button).
Changed Button.cpp to not reference D0 as check for used button IO, replaced "D0" by literal "16" -> no need to define D0 for Wemos D1 mini/Pro.
Moved all HTML texts to flash (F() macro) to relieve RAM for the audio buffers. At some places I had to cast the input to assignments since there is
no copy constructor for this direction.
Update of DS3232RTC lib crashed firmware since I modified this lib -> Moved modification into code
Changed define HW_QLOCKWIFIVE_12 to HW_QLOCKWIFIVE_11 for 11x11 cm "Testboard" to better distiguish from "Holz-Wecker" (which is 12x12 cm)

- 15.05.2020
Display last IP octet with "lettersBig" if it has only two digits

- 02.06.2020 - FW20200602
Added layout for "Mini-Wecker", runs with Wemos D1 mini or Wemos D1 mini Pro (16 MB flash)

- 09.06.2020
Added MP3 sound for Mini-Wecker.
Prior of storing MP3 files in Flash you have to initialize SPIFFS. This has to be issued only once.
Use one of the usual INO files found on the net. I used the code from az-delivery. See
If layout is changed via GUI, restart ESP automatically.
This feature only applies to my "Test-Uhr" with layout HW_QLOCKWIFIVE_11 and HW_QLOCKWIFIVE_11L since this
hardware supports two different layouts (minutes in the corners and four in a row on top of the display).

- 24.06.2020
Lessons learned: Don't move Layouts to PROGMEM (to free RAM) -> boot loop

- 25.06.2020
Lessons learned: Don't put MP3 _file names_ into Flash -> raises exception.

- 26.06.2020
Added a seconds timer.
Put #ifdefs around layouts to get more free RAM. It's needed for MP3 playback!
Layouts are chosen from Configaration.h now.
Added a cyclic color test of the display, start test with "xxx/colorTest" from your WEB browser where xxx is
the IP address of the clock. Stop test with mode button.

- 27.06.2020 - FW20200627
Changed file handling for MP3 files in SPIFFS, so the stored MP3 file can be opened multiple times.
The file is now opened for reading just before starting playback.
Got rid of editing the code to change the MP3 song. Now the SPIFFS is iterated on startup and the file name is retrieved.
Currently only one (1) MP3 file at a time is allowed.

- 30.06.2020
Implemented a file manager to upload MP3 files via browser (adapted from https://fipsok.de), see Define FILEMANAGER
Start file manager with "xxx/spiffs.html" from your WEB browser where xxx is the IP address of the clock.
spiffs.html and spiffs.css have to be uploaded to SPIFFS prior of usage. SPIFFS has to be initialized for that.
Beware: SPIFFS has to be unmounted to successfully upload another MP3 file via filemanager

- 12.07.2020
Added software gain control to set the volume of the MP3 playback even below the hardware setting (100k resistor to GND)

- 17.07.2020
Added gain control via plus/minus buttons (during MP3 playback).
SPIFFS is unmounted after playing MP3 file... which in turn results in problems when using the file manager the next time :(
Playback of MP3 after having uploaded a song OTA only works after a reset of the clock ("xxx/reset").

- 18.07.2020
Added default gain control value (the loudness after reboot) to Settings. Can be set in the GUI. Adjusting the volume
manually (by sensor keys during MP3 playback) is not saved to settings.

- 03.08.2020
If gain value for MP3 playback is changed manually during playback, this changed volume level is stored to EEPROM after
playback has finished (or is stopped by pressing Mode button).
Changed seconds timer to start at 3 seconds minimum since lower values resulted in reboots.

- 05.08.2020
Changed SPIFFS to LitteFS (since SPIFFS is marked as deprecated)  - - - doesn't work, cancelled

- 06.08.2020
Moved MP3 playback into main loop (dedicated inner MP3-Loop is still there - to use it, undef MP3_INLINE).
Fixed memory leaks, derived from repeatedly starting MP3 playback (some buffers were not deleted after use)
No OWM weather info if MP3 is enabled. OWM inquiry lasts for 5..8 seconds, call is blocking.
Cancelled SPIFFs filemanager. It is not working reliable and eats up valuable RAM.

- 07.08.2020
Directly after the start of MP3 playback the clock is switched back to normal time display when MP3
playback is coded "inline". This prevents the blinking AL text which implies audible distortions.
ESP clock has to be set to 160 MHz to play MP3 with nearly no audible glitches. At 80 MHz one can hear
stuttering crackles. Even at 160 MHz there are glitches when the display is refreshed (new time).
This all is valid only for "inline" MP3 playback.
Suppress display of GUICLOCK when MP3 playback is enabled. Its value is not maintained if MP3 is enabled.
Fixed crash when one of the GUI buttons - except Settings - is pressed during MP3 playback. Settings crashes still :(

- 11.08.2020
Added a call to yield() in "pressed minus- and plus- button simultanously" since this resulted in a watchdog timeout with reboot.
Pressing plus + minus together starts MP3 playback.

- 12.08.2020
Play MP3 inline (clock is still working normally, but with (not so) sporadic audible crackles) or in a dedicated
inner loop (no audible disturbance but clock display is not updated during MP3 playback).
This decision can be changed in the GUI and is stored permanently in the settings.

- 13.08.2020
Fixed the crash from 07.08.2020 when Settings is clicked in GUI during MP3 playback.
Changed file storage to be based on LittleFS instead of SPIFFS (SPIFFS is defined deprecated since 2019).
(Re)Implemented a LittleFS based file manager to upload MP3 files via browser (adapted from https://fipsok.de), see Define FILEMANAGER
Start file manager with "xxx/fs.html" from your WEB browser where xxx is the IP address of the clock.
fs.html and style.css have to be uploaded to LittleFS prior of usage.
The occurences of SPIFFS in the files are replaced by LittleFS by means of "#define SPIFFS LittleFS".
(The upload plugin for Arduino IDE/Visual Studio has to be exchanged with the corresponding LittleFS plugin
from https://github.com/earlephilhower/arduino-esp8266littlefs-plugin).
Added button to start LittleFS filemanager from GUI page Settings, dto. button to switch back to GUI from filemanager.

- 14.08.2020
Display modes which may interfere with the MP3 playback (mood, slide, fade, events) are switched off during playback and are reenabled after playback end or stop to minimize audible disturbances. This belongs to the MP3 "inline" mode.

Display all MP3 files contained in LittleFS.
Add option to select which file should be used for alarms. Files have to be encoded with lower bitrate (e.g. 128 Bps) to store more than one file simultaneously.

- 17.08.2020
Finally fixed the crash when calling Settings in the GUI during MP3 playback.

- xx.xx.2020 - FW20200221
sporadic Error: After again reaching a NTP server, the time pre and post fading is different. The pre fading time is correct (NTP time),
   the post fading time is the old (softclock) time. The time fades to the NTP time, then switches back hard (without fading)
   to softclock time.


#define FIRMWARE_VERSION 20200817



Besucher seit