TODO:
1 - feedback and commands to sender while using LoRa
2 - for USE_DALLAS_18B20 don't rely on device id - measure temperature for all sensors connected (even though there is only one temperature sensor on HA) - multisensors later
3 - RTC GPIO only for deep sleep and check with are LOW on boot and after boot (ESP32 datasheet)
  - GPIO 1 on S2 not good - move PIR to GPIO7 on my custom PCB! Keep GPIO 4 for FW upgrade (search for "ie=0" in datasheet.pdf in section "IO MUX")

button operation:
1: very short push:   - normal forced run then sleep
2: very short < x <3s - FW upgrade
3: 3s< x < 6s         - start CP 
4: x >6s              - Erasing ALL stored data on ESP, goes to sleep

2024-04-28
  3.9.7   - introduced esp32047 - Larisa, WeAct C3 based

2024-04-27
  3.9.6   - corrected get_volts() again - in DEBUG only

2024-04-27
  3.9.5   - corrected get_volts() again
            NO NEED TO RECOMPILE between 3.9.3 and 3.9.5 for sensors apart from 42,43,83
            moved "automatic adjustment of ADC_BITS" to common part of devices_config
            moved "EMERGENCY - LOW BATTERY - don't start WiFi or ESPnow" to be common for both MAX17048 and ADC measurement

2024-04-24
  3.9.4   - modified get_volts(), max iteration = 50

2024-04-19
  3.9.3   - some errors corrected
          - complete setup for WeAct Studio ESP32 C3, esp32083
          - LED ON/OFF works only for PWM LED (maybe it can be corrected later?)

2024-04-19
  3.9.2   - ACT_BLUE_LED_GPIO_INVERTED - WeAct Studio ESP32 C3 with LED=8 has LED GPIO inverted - active LOW
          - built in LED is not working during fw_update and CP on WeAct Studio ESP32 C3 - don't know why

2024-04-19
  3.9.1   - improved data_recv.command execution (avoiding execution when not needed)

2024-04-18
  3.9.0   - firmware moved to internet
          - automatic ftp of binary file to ftp

2024-04-14
  3.8.5   - implemented "define DONE_GPIO 7" for using with TPL511x but that does not save energy in case of these sensors  (check DEVICE_ID == 82)
            plus no power on black/blue PCB would mean no MAX17048 measurements
          - corrected bootCount calculations/manipulations
          - sleep_for_1s() instead of restarts on received commands over MQTT/ESPnow - every command received except fw update, ota server and 0, causes esp to go to sleep for 1s only to apply the changes - instead of restart - that should save some battery


2024-04-14
  3.8.4   - corrected WiFi IP address (WiFi.localIP().toString().c_str())
          - received commands: 
            - all in switch/case instead of ifs
            

2024-04-14
  3.8.3e  - added S3 bare module with CDC/USB-OTG as esp32093
          - removed Krzychu from platformio.ini and devices_config.h
          - modified a bit PPK2_GPIO part while testing S3
          - measured S3 delays (on boot and tail)

2024-04-10
  3.8.3d  - esp32039 - garage front mot.: PIRs changed from: 1 to 7
          - esp32101 - Dining: PIRs changed from: 1 to 7, added 10k pull up resistor for GPIO0

2024-04-10
  3.8.3c  - esp32036 - Lidia: PIRs changed from: 1 to 7, added 10k pull up resistor for GPIO0, changed to Milena
          - esp32038 - Toilet b.: PIRs changed from: 1 to 7, added 10k pull up resistor for GPIO0
          

2024-04-10
  3.8.3b  - esp32100 - Office: PIRs changed from: 1 to 7  and 2 to 15, added 10k pull up resistor for GPIO0

2024-04-10
  3.8.3a  - esp32028 - Garage: PIRs changed from: 1 to 7  and 2 to 15, added 10k pull up resistor for GPIO0

2024-04-10
  3.8.3   - DON'T restart on receiving ANY commmand (unless needed) including set sleep time, change gw, light_high_sensitivity etc.

2024-04-10
  3.8.2   - DON'T restart on receiving MOTION ENABLE/DISABLE to conserve the battery 

2024-04-08
  3.8.1a   - esp32035 - Tailor: PIR changed from 1 to 7 
           - esp32033 - Living: PIR changed from 1 to 7 

2024-01-11
  3.8.1   - start rewiring some sensors - use proper GPIO for PIR and PUSHBUTTONS - check ESP32 documentation!
            esp32031 - Printers: PIR changed from 1 to 7 
            esp32042 - push.buttons: assigned FW_UPGRADE_GPIO to lowest button = GPIO8 - before it was fake so always rebooting - only 5 usefull buttons now

2024-01-11
  3.7.1   - extra checks for GPIO motion, fw, push b.

2024-01-10
  3.7.0   - for ESP32 (S,S2,S3): added support for FW_UPGRADE_GPIO_ACTIVE both HIGH and LOW, HIGH by default - ALWAYS USE RESISTOR for ESP32, S2 and S3 
            ACTIVE LOW can be only if:
             - MOTION and PUSHBUTTONS are NOT in use (they are both HIGH and ESPIDF accepts only either: ANY HIGH or ALL LOW as wakeup cause for these MCUs)
             - Boot GPIO is not allowed to be ACTIVE HIGH (as it is always pulled up)
             - be careful with FW_UPGRADE_GPIO NOT to be the same as PUSHBUTTONS or MOTION_SENSOR_GPIO
          - load_config at the very beginning to be able to stare LED very early - PMW value is in config (otherwise LED has PWM=0)
          - example: esp32082 (S2)
2024-01-10
  3.6.0   - for ESP32C3: added support for FW_UPGRADE_GPIO_ACTIVE both HIGH and LOW, HIGH by default
            (so not needed to define per device if HIGH is ok)
          - for all MCUs (supported) added check if FW_UPGRADE_GPIO is RTC and if not, error compiling it
          - ESP32C3 does not require external resistors - other MCUs (S, S2) resistor is MANDATORY (check S3)
            (actually even C3 is very light pulled so resistor would be better)
          - example: esp32083 (C3)

2024-01-10
  3.5.3   - integrated WeAct Studio ESP32 C3 - no difference from other C3, LED GIPIO=8 (blue) but not blinking during FW update 
            https://mischianti.org/weact-studio-esp32-c3-core-high-resolution-pinout-and-specs/
          - FW_UPGRADE_GPIO: GPIO0 does not work as code expectc ACTIVE HIGH 
          - initiate_all_leds(); moved to the beginning
          - small correction with printing SSID
          
2024-01-10
  3.5.2   - splitting receiver from sendor on gitlab
          - move changelog.txt to main folder

2023-12-02
  3.5.2    - wemos S3 mini done
           - Captive Portal timeout 10min
           - esp32045 Toilet up 2 new sensor (no battery, no LED, no charging)

2023-10-08
  3.5.1    - SLEEP_TIME_H_BATTERY_EMPTY  1

2023-08-27
  3.5.0    - SLEEP_TIME_H_BATTERY_EMPTY  6, ota_enabled accepted

2023-08-22
  3.5.b4   - correction in USE_MAX31855 (rather than 3.4.b3 -> USE_MAX17048)

2023-08-22
  3.5.b1   - ota_enabled - flag to exclude/include sensor device from OTA - usefull if you mark ALL devices to perform OTA but you don't want to perform on some (i.e. dining/living etc.)

2023-08-18
  3.4.b3   - correcting thermocouple USE_MAX17048 == 1 in flags

2023-08-18
  3.4.b2   - correcting names

2023-08-18
  3.4.b1   - flags introduced to reduce/control amount of sensors/entity_id on HA 

2023-08-18
  3.3.0   - INA3221 integrated

2023-08-16
  3.2.1   - units from both INA260 and INA3221 are: V, A, W
          - integrated INA3221: 3 channel current/voltage/power measrement - but only 1 channel is programmed due to only v1,i1,p1 on HA 

2023-08-07
  3.2.b5  - change W to mW (although there is a warning in HA as illegal unit - problem solved by disabling: "config["dev_cla"] = "power"")

2023-08-05
  3.2.b4  - wemos S3 mini lolin integrated but it does not print - too short working time and it has no UART, but all works 
          - changes in hibernate (reverted few changes)
2023-07-31
  3.2.b3  - change mW to W

2023-07-25
  3.2.b2  - don't print anything in DEBUG in set_error_XX_led_level()
          - print DS18B20 address even without DEBUG

2023-07-21
  3.2.b1  - added INA260 (current/volts/power measurements)
          - set properly WiFi protocols in case other were in use (common library/captive portal)

2023-07-16
  3.1.b3  - FW_UPGRADE_GPIO IS obligatory AGAIN (otherwise no reset no restart no CP possible from button)

2023-07-16
  3.1.b2  - corrections for PUSH_BUTTONS_ONLY and FW_UPGRADE_GPIO
          
2023-07-16
  3.1.b1  - added more PIR sensors (multi PIR sensor) to avoid black spots - #define MOTION_ENABLED,  #define NUMBER_OF_MOTION_SENSORS 
          - improvements in setup() and hibernate()
          - FW_UPGRADE_GPIO is not obligatory anymore but still compile error in devices_config.h kept

2023-07-14
  3.0.b5  - some cleaning 

2023-07-11
  3.0.b4  - some cleaning 

2023-07-11
  3.0.b3  - delay() are smaller now (inside LED mainly but not only)
          - changes in send_data_espnow() - print messages
          

2023-07-09
  3.0.b2  - testing LoRa
  
2023-07-09
  3.0.b1 - testing LoRa 

2023-07-08
  2.20.6 - another improvements in setup()

2023-07-07
  2.20.5 - when command received, checking if target state is already there - if so, no changes

2023-07-07
  2.20.4 - few improvements in setup()

2023-07-07
  2.20.3 - few improvements in hibernate()

2023-06-30
  2.20.2 - TRV with charging onboard - testing

2023-06-28
  2.20.1  - cleaning/replacing Serial.print() and Serial.println() with Serial.printf() - exception in ds18b20

2023-06-27
  2.20.0  - command=24 resets ontime/pretty_ontime, ADC finished and accepted 

2023-06-23
  2.20.b1 - added ADC battery measurements (Volts and %) - check esp32042 as an example

2023-06-21
  2.19.b2 - valid flag in data structure - continuing

2023-06-20
  2.19.b1 - valid flag in data structure - don't publish to HA if valid = 0 (default value = 1) 

2023-06-19
  2.18.0  - pool thermometer became esp32043

2023-06-19
  2.18.b2  - pool thermometer - more work (finished?)

2023-06-14
  2.18.b1  - pool thermometer + some reworks with PUSH_BUTTONS_ONLY and LCD

2023-06-07
  2.17.0   - get_lux rework accepted

2023-06-03
  2.17.b4  - rework get_lux again

2023-06-02
  2.17.b3  - rework get_lux again

2023-06-02
  2.17.b2  - rework get_lux to avoid saturation

2023-05-30
  2.17.b1  - sleep_time_s - testing

2023-05-20
  2.16.0  - accepted

2023-05-19
  2.16.0b1 - new myData structure - working_time_ms

2023-05-18
  2.15.5  - Adafruit implementation of TSL2561 instead of SparkFunTSL2561

2023-05-17
  2.15.4  - new firmware server path on Macbook Pro "/Volumes/scripts/001..."
          - OTA web server on ESP32 in case no way to reach firmware server - call it with MQTT command 202

2023-05-17
  2.15.3   - measure=lux.h - if (lux > 30000) light_high = true;

2023-04-07
  2.15.2   - cleaning config

2023-03-25
  2.15.1   - g_bootCount updates (resets to 0, increase after g_bootCount before sending)

2023-03-19
  2.15.0   - set hostname properly

2023-03-04
  2.14.b1 - touch pad implementation started

2023-02-25
  2.13.b3 - corrections in USE_MAX31855 - extra delays

2023-02-23
  2.13.b2 - DEBOUNCE_MS_ANY_GPIO=5, DEBOUNCE_MS_FW_GPIO=200, DEBOUNCE_MS_PUSHBUTTON=100

2023-02-23
  2.13.b1 - push buttons implemented

2023-02-23
  2.12.b1 - light_high_sensitivity:  0 - low, light meas. time 13ms, 1 - high, light meas. time 403ms
          - commands: 5 = high, 6 = low

2023-02-21
  2.11.0 - lux measurements with auto gain (function from bedroom sketch) 

2023-02-20
  2.10.0  - ESP32S integrated
          - thermocouple sensor integrated (041) with MAX31855 (only ESP32S working due to SPI implementation in the library)
          - commands to set SLEEP_TIME_S: 
            30-1s
            31-3s
            32-5s
            33-10s
            34-15s
            35-30s
            36-60s
            37-90s
            38-120s
            39-180s
            40-300s
            41-600s
            42-900s
            43-1800s
            44-3600s

2023-02-17
  2.9.3   -  possibility to force sensor device to specific GW (commands: 21, 22, 23)

2023-02-16
  2.9.2   -  reset bootcount on restart command asap so that after start it shows 1

2023-02-16
  2.9.1a  -  2 gateways for krzych 

2023-02-16
  2.9.0   - failure with Git(hub) 

2023-02-15
  2.8.3b  - restart after enabling/disabling motion 

2023-02-15
  2.8.3a  - only 1 gateway for krzych 

2023-02-13
  2.8.3   - if no lux sensor, set LED only from HA - don't apply anything default

2023-02-13
  2.8.2   - don't restart on motion_enabled change

2023-02-13
  2.8.1   - motion_enabled implemented 

2023-02-13
  2.8.0   - short push of the FW update button: normal forced run, FW update only if the push is long (so that ESP senses button after wake up)

2023-02-13
  2.7.3   - correction in PWM 

2023-02-12
  2.7.2   - correction in PWM - g_led_pwm = 50/255; if no lux sensor in use

2023-02-12
  2.7.1   - correction in PWM

2023-02-12
  2.7.0   - PWM for LED with automation both local on ESP and from HA

2023-02-12
  2.6.6   - cleaning devices_config.h and platformio.ini

2023-02-01
  2.6.5   - revert 2.6.4

2023-02-01
  2.6.4   - don't restart on erase_all_data() command - go to sleep 

2023-01-27
  2.6.2   - 3 gateways for CLIENT 

2023-01-27
  2.6.1   - CALIBRATE_TEMPERATURE and CALIBRATE_HUMIDITY added

2023-01-26
  2.6.0   - all seem to work

2023-01-26
  2.6.0b5 - sensor devices act on commands from receiver ;-)

2023-01-24
  2.6.0b1 - receiver sends confirmation to sender with command (u_int8_t),  sender acts on the command accordingly
          - timeout set on sender side to be WAIT_FOR_COMMAND_MS=100ms

2023-01-21:
  2.5.0   - "unknow" changes ;-(

2022-12-31:
  2.4.1   - correction for ENABLE_3V_GPIO
          - 1h SLEEP_TIME_S for TRVs 

2022-12-31:
  2.4.0   - add charging_int as result of charging_state()
          - pinMode for charging and power at the beginning of setup()
          - u_int8_t charging_state(); instead of void, at the beginning of setup()
          - hibernate() not anymore hibernate but deep sleep ;-( - current still 38uA
          - since charging is checked at the beginning, no 1 reboot delay to report it properly
          - resetting ontime when charging != NC
          - correction in html page

2022-12-11:
  2.3.1   - don't blink in tasks if LED GPIOs are not defined or it segfaults (this is mainly for C3 - no need for upgrading other boards to 2.3.1)
          - max sleep time in Captive Portal: 86400s (24h)

2022-12-10:
  2.3.0   - wifi_ok added to myData to indicate if WiFi is configured on device sensor
  2.2.0   - platformio.ini scripted - choosing boards in platformio.ini now - not in devices_config.h (but still full board config is in devices_config.h) 

2022-12-09:
  2.1.0   - sorted (?) AP and CP that were not starting (removed STA connection just before AP connection -> now AP works) 
          - sorted lack of some GPIO configured for html page
          - RED LED ON if wifi not configured (although ESPNow works without WiFi configured)

2022-12-08:
  2.0.1   - use last 2 bytes of fake MAC in case DEVICE_ID > 99 

2022-12-08:
  2.0.0   - captive portal improved with all data
          - change MAC to fake to keep the same device on HA irrespective of new MCU
          - led_blink_erase - red led blinks during erasing all data
          - html page in separate file

2022-12-07:
  2.0.0b8 - wifi (ssd, password, sleeptime) in config
  2.0.0b7 - preferences vanished, config file in json (encrypted or not - configurable) in /config.dat - ontime, bootCount, channel, last_gw done - not yet wifi (ssid and password)

2022-12-06:
  2.0.0b1 - complete rework including Captive Portal etc (based on HomeKit HomeSpan sensors) - work started, esp32100 tested and working


// ============================ END OF VERSION 1.x.x ==========================
2022-12-02:
  1.24.b1 - no more fixed WiFi channel, all senders send to 1 of GW from the pool, each GW has fixed fake MAC address, based on their availability - not according to signal strength

2022-11-10:
  1.23.1  - added ESP32S

2022-11-06:
  1.23.0  - board type makes model in MQTT device

2022-11-06:
  1.22.6  - bootCount changed to unsigned int

2022-11-06:
  1.22.5  - more info printed (MCU type, boot and wake up reasons)

2022-10-30:
  1.22.4  - replace VERSION with ZH_PROG_VERSION as some libs use VERSION

2022-10-30:
  1.22.3  - mistake in turning ON RED LED - solved

2022-10-23:
  1.22.2a  - TRV4 sleep time 6h

2022-10-20:
  1.22.2   - C3 added in devices_config.h check: #if (BOARD_TYPE == 4)

2022-10-20:
  1.22.1   - new sender_type = battery for TRV battery sensors

2022-10-19:
  1.22.0   - added ESP32-C3, different wake up from GPIO (hibernate) and different cause of wake up (setup)
           - ESP32-C3 can wake up on HIGH or LOW, set up done on HIGH to be compatible with S/S2 boards
           - BOOTLOADER GPIO for ESP32-C3 is GPIO_9
           - SDA = GPIO_8
           - SCL = GPIO_9 - same as bootloader GPIO

2022-10-17:
  1.21.6   - sorting LED when FW_UPGRADE_GPIO pressed:
            1 - red when pressed
            2 - after 3s red off, blue on
            3 - after next 3s red on, blue off

2022-10-17:
  1.21.5   - correction in wifi settings for wifi and espnow - both have all protocols enabled

2022-10-17:
  1.21.4   - improved wifi settings for both wifi (all protocols) and espnow (LR only):

2022-10-17:
  1.21.3   - testing long range esp_wifi_set_protocol( WIFI_IF_AP, WIFI_PROTOCOL_LR );

2022-10-16:
  1.21.2  - don't check MOTION_SENSOR_GPIO after wake up - just base on wake up reason
            it was bringing too many false positive motion=1

2022-10-16:
  1.21.1  - added additional function to FW_UPGRADE_GPIO button:
            - 1 short press: fw_update
            - 1 press for 3 seconds (red goes to green at the end, then release it) - ESP.reset() - it resets MAX17048 and bootCount
            - 1 press for 6 seconds (green goes to red at the end, then release it) - format FS, - it resets ontime, bootCount and MAX17048
              as sensors without charger would never reset ontime, even after changing/charging the battery
2022-10-01:
  1.21.0  - change UPDATE_FIRMWARE_HOST to baboon server

2022-09-15:
  1.20.1  - USE_CUSTOM_I2C_GPIO

2022-09-15:
  1.20.0  - 5 devices finished (36, 100, 101, 102, 104), few minor improvements

2022-09-15:
  1.20.b10 - software reset on 3s press of FW_UPGRADE_GPIO (until red led turns off and blue/green turns on)

2022-09-15:
  1.20.b6 - corrections

2022-09-14:
  1.20.b1 - making universal sketch for devices that can be either: env, motion or env+motion

2022-08-07:
  1.19.b2 - corrections and cleaning the code

2022-08-06:
  1.18.3  - major rework battery
          - send update to HA before FW upgrade starts
  1.18.2  - lipo.reset() on FW_UPGRADE_GPIO or reset/power
  1.18.1  - adding MAX17048 data from new boards
  1.18.0  - correction in ext1 wakeup gpio mask - it calculates mask instead of hard coded pins

2022-08-05:
  1.17.0  - official release 1.17.0 including both: env and motion sensors

2022-08-05:
  1.16.0  - current load: 45uA in both: standby and cooling
          - FW update on button press
2022-08-04:
  1.15.1  - battery monitoring (Volts) over ADC
  1.15.0  - PIR motion detector wake up on GPIO and on heartbeat
          - no FW update yet
