diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b636b9dc..bb32fd57 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p Please ensure to specify the following: * Arduino IDE version (e.g. 1.8.19) or Platform.io version -* Board Core Version (e.g. Arduino SAMDUE core v1.6.12, ESP32 core v2.0.2, ESP8266 core v3.0.2, ArduinoCore-mbed v3.0.1, etc.) +* Board Core Version (e.g. Arduino SAMDUE core v1.6.12, ESP32 core v2.0.4, ESP8266 core v3.0.2, ArduinoCore-mbed v3.1.1, etc.) * Contextual information (e.g. what you were trying to achieve) * Simplest possible steps to reproduce * Anything that might be relevant in your opinion, such as: @@ -28,12 +28,12 @@ Please ensure to specify the following: ``` Arduino IDE version: 1.8.19 RASPBERRY_PI_PICO board -ArduinoCore-mbed v3.0.1 +ArduinoCore-mbed v3.1.1 OS: Ubuntu 20.04 LTS -Linux xy-Inspiron-3593 5.13.0-39-generic #44~20.04.1-Ubuntu SMP Thu Mar 24 16:43:35 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux +Linux xy-Inspiron-3593 5.15.0-46-generic #49~20.04.1-Ubuntu SMP Thu Aug 4 19:15:44 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux Context: -The board couldn't autoreconnect to Local Blynk Server after router power recycling. +The board couldn't connect to network Steps to reproduce: 1. ... @@ -51,3 +51,5 @@ There are usually some outstanding feature requests in the [existing issues list ### Sending Pull Requests Pull Requests with changes and fixes are also welcome! + + diff --git a/README.md b/README.md index 9c72bfaf..d5d54513 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,7 @@ This [**Ethernet_Manager** library](https://github.com/khoih-prog/Ethernet_Manag #### Supported Ethernet shields/modules: -1. W5x00 using [`Ethernet`](https://www.arduino.cc/en/Reference/Ethernet), [`EthernetLarge`](https://github.com/OPEnSLab-OSU/EthernetLarge), [`Ethernet2`](https://github.com/adafruit/Ethernet2) or [`Ethernet3`](https://github.com/sstaub/Ethernet3) library +1. W5x00 using [`Ethernet_Generic`](https://github.com/khoih-prog/Ethernet_Generic) library 2. ENC28J60 using [`EthernetENC`](https://github.com/jandrassy/EthernetENC) or [`UIPEthernet`](https://github.com/UIPEthernet/UIPEthernet) library 3. Teensy 4.1 built-in Ethernet using [`NativeEthernet`](https://github.com/vjmuzik/NativeEthernet) library 4. LAN8720 Ethernet used in WT32_ETH01 boards @@ -228,29 +228,29 @@ This [**Ethernet_Manager** library](https://github.com/khoih-prog/Ethernet_Manag 1. [`Arduino IDE 1.8.19+` for Arduino](https://github.com/arduino/Arduino). [![GitHub release](https://img.shields.io/github/release/arduino/Arduino.svg)](https://github.com/arduino/Arduino/releases/latest) 2. [`Arduino AVR core 1.8.5+`](https://github.com/arduino/ArduinoCore-avr) for Arduino (Use Arduino Board Manager) AVR boards. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-avr.svg)](https://github.com/arduino/ArduinoCore-avr/releases/latest) - 3. [`Teensy core v1.56+`](https://www.pjrc.com/teensy/td_download.html) for Teensy (4.1, 4.0, 3.6, 3.5, 3,2, 3.1, 3.0) boards. + 3. [`Teensy core v1.57+`](https://www.pjrc.com/teensy/td_download.html) for Teensy (4.1, 4.0, 3.6, 3.5, 3,2, 3.1, 3.0) boards. 4. [`Arduino SAM DUE core v1.6.12+`](https://github.com/arduino/ArduinoCore-sam) for SAM DUE ARM Cortex-M3 boards. 5. [`Arduino SAMD core 1.8.13+`](https://github.com/arduino/ArduinoCore-samd) for SAMD ARM Cortex-M0+ boards. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-samd.svg)](https://github.com/arduino/ArduinoCore-samd/releases/latest) 6. [`Adafruit SAMD core 1.7.10+`](https://github.com/adafruit/ArduinoCore-samd) for SAMD ARM Cortex-M0+ and M4 boards (Nano 33 IoT, etc.). [![GitHub release](https://img.shields.io/github/release/adafruit/ArduinoCore-samd.svg)](https://github.com/adafruit/ArduinoCore-samd/releases/latest) - 7. [`Seeeduino SAMD core 1.8.2+`](https://github.com/Seeed-Studio/ArduinoCore-samd) for SAMD21/SAMD51 boards (XIAO M0, Wio Terminal, etc.). [![Latest release](https://img.shields.io/github/release/Seeed-Studio/ArduinoCore-samd.svg)](https://github.com/Seeed-Studio/ArduinoCore-samd/releases/latest/) + 7. [`Seeeduino SAMD core 1.8.3+`](https://github.com/Seeed-Studio/ArduinoCore-samd) for SAMD21/SAMD51 boards (XIAO M0, Wio Terminal, etc.). [![Latest release](https://img.shields.io/github/release/Seeed-Studio/ArduinoCore-samd.svg)](https://github.com/Seeed-Studio/ArduinoCore-samd/releases/latest/) 8. [`Adafruit nRF52 v1.3.0+`](https://github.com/adafruit/Adafruit_nRF52_Arduino) for nRF52 boards such as Adafruit NRF52840_FEATHER, NRF52832_FEATHER, NRF52840_FEATHER_SENSE, NRF52840_ITSYBITSY, NRF52840_CIRCUITPLAY, NRF52840_CLUE, NRF52840_METRO, NRF52840_PCA10056, PARTICLE_XENON, **NINA_B302_ublox**, etc. [![GitHub release](https://img.shields.io/github/release/adafruit/Adafruit_nRF52_Arduino.svg)](https://github.com/adafruit/Adafruit_nRF52_Arduino/releases/latest) - 9. [`ESP32 Core 2.0.2+`](https://github.com/espressif/arduino-esp32) for ESP32-based boards. [![Latest release](https://img.shields.io/github/release/espressif/arduino-esp32.svg)](https://github.com/espressif/arduino-esp32/releases/latest/) + 9. [`ESP32 Core 2.0.4+`](https://github.com/espressif/arduino-esp32) for ESP32-based boards. [![Latest release](https://img.shields.io/github/release/espressif/arduino-esp32.svg)](https://github.com/espressif/arduino-esp32/releases/latest/) 10. [`ESP8266 Core 3.0.2+`](https://github.com/esp8266/Arduino) for ESP8266-based boards. [![Latest release](https://img.shields.io/github/release/esp8266/Arduino.svg)](https://github.com/esp8266/Arduino/releases/latest/). To use ESP8266 core 2.7.1+ for LittleFS. -11. [`ArduinoCore-mbed mbed_rp2040, mbed_nano, mbed_portenta core 3.0.1+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino (Use Arduino Board Manager) **Portenta_H7, RP2040-based boards, such as Nano_RP2040_Connect, RASPBERRY_PI_PICO**. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest) -12. [`Earle Philhower's arduino-pico core v1.13.1+`](https://github.com/earlephilhower/arduino-pico) for RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, etc. [![GitHub release](https://img.shields.io/github/release/earlephilhower/arduino-pico.svg)](https://github.com/earlephilhower/arduino-pico/releases/latest) +11. [`ArduinoCore-mbed mbed_rp2040, mbed_nano, mbed_portenta core 3.1.1+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino (Use Arduino Board Manager) **Portenta_H7, RP2040-based boards, such as Nano_RP2040_Connect, RASPBERRY_PI_PICO**. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest) +12. [`Earle Philhower's arduino-pico core v2.5.2+`](https://github.com/earlephilhower/arduino-pico) for RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, etc. [![GitHub release](https://img.shields.io/github/release/earlephilhower/arduino-pico.svg)](https://github.com/earlephilhower/arduino-pico/releases/latest) 13. [`Functional-Vlpp library v1.0.2+`](https://github.com/khoih-prog/functional-vlpp) to use server's lambda function. To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/Functional-Vlpp.svg?)](https://www.ardu-badge.com/Functional-Vlpp) 14. Depending on which Ethernet card you're using: - - [`Ethernet_Generic library v2.0.1+`](https://github.com/khoih-prog/Ethernet_Generic) for W5100, W5200 and W5500/WIZ550io/WIZ850io/USR-ES1 with Wiznet W5500 chip. [![GitHub release](https://img.shields.io/github/release/khoih-prog/Ethernet_Generic.svg)](https://github.com/khoih-prog/Ethernet_Generic/releases/latest) - - [`EthernetENC library v2.0.2+`](https://github.com/jandrassy/EthernetENC) for ENC28J60. [![GitHub release](https://img.shields.io/github/release/jandrassy/EthernetENC.svg)](https://github.com/jandrassy/EthernetENC/releases/latest). **New and Better** - - [`UIPEthernet library v2.0.11+`](https://github.com/UIPEthernet/UIPEthernet) for ENC28J60. [![GitHub release](https://img.shields.io/github/release/UIPEthernet/UIPEthernet.svg)](https://github.com/UIPEthernet/UIPEthernet/releases/latest) + - [`Ethernet_Generic library v2.5.2+`](https://github.com/khoih-prog/Ethernet_Generic) for W5100, W5200 and W5500/WIZ550io/WIZ850io/USR-ES1 with Wiznet W5500 chip. [![GitHub release](https://img.shields.io/github/release/khoih-prog/Ethernet_Generic.svg)](https://github.com/khoih-prog/Ethernet_Generic/releases/latest) + - [`EthernetENC library v2.0.3+`](https://github.com/jandrassy/EthernetENC) for ENC28J60. [![GitHub release](https://img.shields.io/github/release/jandrassy/EthernetENC.svg)](https://github.com/jandrassy/EthernetENC/releases/latest). **New and Better** + - [`UIPEthernet library v2.0.12+`](https://github.com/UIPEthernet/UIPEthernet) for ENC28J60. [![GitHub release](https://img.shields.io/github/release/UIPEthernet/UIPEthernet.svg)](https://github.com/UIPEthernet/UIPEthernet/releases/latest) - [`NativeEthernet Library version stable111+`](https://github.com/vjmuzik/NativeEthernet) for Teensy 4.1 built-in Ethernet. - - [`QNEthernet Library version v0.14.0+`](https://github.com/ssilverman/QNEthernet) for Teensy 4.1 built-in Ethernet. **New** + - [`QNEthernet Library version v0.15.0+`](https://github.com/ssilverman/QNEthernet) for Teensy 4.1 built-in Ethernet. **New** 15. Depending on which board you're using: - [`DueFlashStorage library v1.0.0+`](https://github.com/sebnil/DueFlashStorage) for SAM DUE. To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/DueFlashStorage.svg?)](https://www.ardu-badge.com/DueFlashStorage) - [`FlashStorage_SAMD library v1.3.2+`](https://github.com/khoih-prog/FlashStorage_SAMD) for SAMD21 and SAMD51 boards (ZERO, MKR, NANO_33_IOT, M0, M0 Pro, AdaFruit Itsy-Bitsy M4, etc.). [![GitHub release](https://img.shields.io/github/release/khoih-prog/FlashStorage_SAMD.svg)](https://github.com/khoih-prog/FlashStorage_SAMD/releases/latest) - [`Adafruit's LittleFS/InternalFS`](www.adafruit.com) for nRF52 -16. [`EthernetWebServer library v2.1.2+`](https://github.com/khoih-prog/EthernetWebServer). To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/EthernetWebServer.svg?)](https://www.ardu-badge.com/EthernetWebServer). -17. [`WebServer_WT32_ETH01 library v1.4.1+`](https://github.com/khoih-prog/WebServer_WT32_ETH01) for WT32_ETH01 boards. To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/WebServer_WT32_ETH01.svg?)](https://www.ardu-badge.com/WebServer_WT32_ETH01). +16. [`EthernetWebServer library v2.2.2+`](https://github.com/khoih-prog/EthernetWebServer). To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/EthernetWebServer.svg?)](https://www.ardu-badge.com/EthernetWebServer). +17. [`WebServer_WT32_ETH01 library v1.5.0+`](https://github.com/khoih-prog/WebServer_WT32_ETH01) for WT32_ETH01 boards. To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/WebServer_WT32_ETH01.svg?)](https://www.ardu-badge.com/WebServer_WT32_ETH01). 18. [`ESP_DoubleResetDetector library v1.3.1+`](https://github.com/khoih-prog/ESP_DoubleResetDetector) for ESP32 and ESP8266. To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/ESP_DoubleResetDetector.svg?)](https://www.ardu-badge.com/ESP_DoubleResetDetector). 19. [`DoubleResetDetector_Generic library v1.8.1+`](https://github.com/khoih-prog/DoubleResetDetector_Generic) for other boards (not ESP32 or ESP8266). To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/DoubleResetDetector_Generic.svg?)](https://www.ardu-badge.com/DoubleResetDetector_Generic). 20. [`LittleFS_esp32 v1.0.6+`](https://github.com/lorol/LITTLEFS) for ESP32-based boards using LittleFS with ESP32 core v1.0.5-. To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/LittleFS_esp32.svg?)](https://www.ardu-badge.com/LittleFS_esp32). **Notice**: This [`LittleFS_esp32 library`](https://github.com/lorol/LITTLEFS) has been integrated to Arduino [ESP32 core v1.0.6+](https://github.com/espressif/arduino-esp32/tree/master/libraries/LITTLEFS) and you don't need to install it if using ESP32 core v1.0.6+ @@ -276,7 +276,7 @@ The best way is to use `Arduino Library Manager`. Search for `Ethernet_Manager`, 1. Install [VS Code](https://code.visualstudio.com/) 2. Install [PlatformIO](https://platformio.org/platformio-ide) -3. Install [**Ethernet_Manager** library](https://platformio.org/lib/show/11568/Ethernet_Manager) by using [Library Manager](https://platformio.org/lib/show/11568/Ethernet_Manager/installation). Search for Ethernet_Manager in [Platform.io Author's Libraries](https://platformio.org/lib/search?query=author:%22Khoi%20Hoang%22) +3. Install [**Ethernet_Manager** library](https://registry.platformio.org/libraries/khoih-prog/Ethernet_Manager) by using [Library Manager](https://registry.platformio.org/libraries/khoih-prog/Ethernet_Manager/installation). Search for Ethernet_Manager in [Platform.io Author's Libraries](https://platformio.org/lib/search?query=author:%22Khoi%20Hoang%22) 4. Use included [platformio.ini](platformio/platformio.ini) file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at [Project Configuration File](https://docs.platformio.org/page/projectconf.html) @@ -388,13 +388,13 @@ Whenever the above-mentioned compiler error issue is fixed with the new Arduino #### 5. For Adafruit SAMD boards - ***To be able to compile, run and automatically detect and display BOARD_NAME on Adafruit SAMD (Itsy-Bitsy M4, etc) boards***, you have to copy the whole [Adafruit SAMD Packages_Patches](Packages_Patches/adafruit/hardware/samd/1.7.9) directory into Adafruit samd directory (~/.arduino15/packages/adafruit/hardware/samd/1.7.9). + ***To be able to compile, run and automatically detect and display BOARD_NAME on Adafruit SAMD (Itsy-Bitsy M4, etc) boards***, you have to copy the whole [Adafruit SAMD Packages_Patches](Packages_Patches/adafruit/hardware/samd/1.7.10) directory into Adafruit samd directory (~/.arduino15/packages/adafruit/hardware/samd/1.7.10). -Supposing the Adafruit SAMD core version is 1.7.9. This file must be copied into the directory: +Supposing the Adafruit SAMD core version is 1.7.10. This file must be copied into the directory: -- `~/.arduino15/packages/adafruit/hardware/samd/1.7.9/platform.txt` -- `~/.arduino15/packages/adafruit/hardware/samd/1.7.9/cores/arduino/Print.h` -- `~/.arduino15/packages/adafruit/hardware/samd/1.7.9/cores/arduino/Print.cpp` +- `~/.arduino15/packages/adafruit/hardware/samd/1.7.10/platform.txt` +- `~/.arduino15/packages/adafruit/hardware/samd/1.7.10/cores/arduino/Print.h` +- `~/.arduino15/packages/adafruit/hardware/samd/1.7.10/cores/arduino/Print.cpp` Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied into the directory: @@ -405,14 +405,14 @@ This file must be copied into the directory: #### 6. For Seeeduino SAMD boards - ***To be able to compile, run and automatically detect and display BOARD_NAME on Seeeduino SAMD (XIAO M0, Wio Terminal, etc) boards***, you have to copy the whole [Seeeduino SAMD Packages_Patches](Packages_Patches/Seeeduino/hardware/samd/1.8.2) directory into Seeeduino samd directory (~/.arduino15/packages/Seeeduino/hardware/samd/1.8.2). + ***To be able to compile, run and automatically detect and display BOARD_NAME on Seeeduino SAMD (XIAO M0, Wio Terminal, etc) boards***, you have to copy the whole [Seeeduino SAMD Packages_Patches](Packages_Patches/Seeeduino/hardware/samd/1.8.3) directory into Seeeduino samd directory (~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3). -Supposing the Seeeduino SAMD core version is 1.8.2. This file must be copied into the directory: +Supposing the Seeeduino SAMD core version is 1.8.3. This file must be copied into the directory: -- `~/.arduino15/packages/Seeeduino/hardware/samd/1.8.2/platform.txt` -- `~/.arduino15/packages/Seeeduino/hardware/samd/1.8.2/cores/arduino/Arduino.h` -- `~/.arduino15/packages/Seeeduino/hardware/samd/1.8.2/cores/arduino/Print.h` -- `~/.arduino15/packages/Seeeduino/hardware/samd/1.8.2/cores/arduino/Print.cpp` +- `~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3/platform.txt` +- `~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3/cores/arduino/Arduino.h` +- `~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3/cores/arduino/Print.h` +- `~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3/cores/arduino/Print.cpp` Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied into the directory: @@ -432,12 +432,12 @@ To use LAN8720 on some STM32 boards - **Discovery (DISCO_F746NG)** - **STM32F4 boards (BLACK_F407VE, BLACK_F407VG, BLACK_F407ZE, BLACK_F407ZG, BLACK_F407VE_Mini, DIYMORE_F407VGT, FK407M1)** -you have to copy the files [stm32f4xx_hal_conf_default.h](Packages_Patches/STM32/hardware/stm32/2.2.0/system/STM32F4xx) and [stm32f7xx_hal_conf_default.h](Packages_Patches/STM32/hardware/stm32/2.2.0/system/STM32F7xx) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system) to overwrite the old files. +you have to copy the files [stm32f4xx_hal_conf_default.h](Packages_Patches/STM32/hardware/stm32/2.3.0/system/STM32F4xx) and [stm32f7xx_hal_conf_default.h](Packages_Patches/STM32/hardware/stm32/2.3.0/system/STM32F7xx) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.3.0/system) to overwrite the old files. -Supposing the STM32 stm32 core version is 2.2.0. These files must be copied into the directory: +Supposing the STM32 stm32 core version is 2.3.0. These files must be copied into the directory: -- `~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h` for STM32F4. -- `~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system/STM32F7xx/stm32f7xx_hal_conf_default.h` for Nucleo-144 STM32F7. +- `~/.arduino15/packages/STM32/hardware/stm32/2.3.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h` for STM32F4. +- `~/.arduino15/packages/STM32/hardware/stm32/2.3.0/system/STM32F7xx/stm32f7xx_hal_conf_default.h` for Nucleo-144 STM32F7. Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz, theses files must be copied into the corresponding directory: @@ -448,12 +448,12 @@ theses files must be copied into the corresponding directory: #### 7.2 For STM32 boards to use Serial1 -**To use Serial1 on some STM32 boards without Serial1 definition (Nucleo-144 NUCLEO_F767ZI, Nucleo-64 NUCLEO_L053R8, etc.) boards**, you have to copy the files [STM32 variant.h](Packages_Patches/STM32/hardware/stm32/2.2.0) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.2.0). You have to modify the files corresponding to your boards, this is just an illustration how to do. +**To use Serial1 on some STM32 boards without Serial1 definition (Nucleo-144 NUCLEO_F767ZI, Nucleo-64 NUCLEO_L053R8, etc.) boards**, you have to copy the files [STM32 variant.h](Packages_Patches/STM32/hardware/stm32/2.3.0) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.3.0). You have to modify the files corresponding to your boards, this is just an illustration how to do. -Supposing the STM32 stm32 core version is 2.2.0. These files must be copied into the directory: +Supposing the STM32 stm32 core version is 2.3.0. These files must be copied into the directory: -- `~/.arduino15/packages/STM32/hardware/stm32/2.2.0/variants/STM32F7xx/F765Z(G-I)T_F767Z(G-I)T_F777ZIT/NUCLEO_F767ZI/variant.h` for Nucleo-144 NUCLEO_F767ZI. -- `~/.arduino15/packages/STM32/hardware/stm32/2.2.0/variants/STM32L0xx/L052R(6-8)T_L053R(6-8)T_L063R8T/NUCLEO_L053R8/variant.h` for Nucleo-64 NUCLEO_L053R8. +- `~/.arduino15/packages/STM32/hardware/stm32/2.3.0/variants/STM32F7xx/F765Z(G-I)T_F767Z(G-I)T_F777ZIT/NUCLEO_F767ZI/variant.h` for Nucleo-144 NUCLEO_F767ZI. +- `~/.arduino15/packages/STM32/hardware/stm32/2.3.0/variants/STM32L0xx/L052R(6-8)T_L053R(6-8)T_L063R8T/NUCLEO_L053R8/variant.h` for Nucleo-64 NUCLEO_L053R8. Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz, theses files must be copied into the corresponding directory: @@ -496,12 +496,12 @@ With core after v1.5.0, this step is not necessary anymore thanks to the PR [Add #### 9. For Portenta_H7 boards using Arduino IDE in Linux - **To be able to upload firmware to Portenta_H7 using Arduino IDE in Linux (Ubuntu, etc.)**, you have to copy the file [portenta_post_install.sh](Packages_Patches/arduino/hardware/mbed_portenta/3.0.0/portenta_post_install.sh) into mbed_portenta directory (~/.arduino15/packages/arduino/hardware/mbed_portenta/3.0.0/portenta_post_install.sh). + **To be able to upload firmware to Portenta_H7 using Arduino IDE in Linux (Ubuntu, etc.)**, you have to copy the file [portenta_post_install.sh](Packages_Patches/arduino/hardware/mbed_portenta/3.1.1/portenta_post_install.sh) into mbed_portenta directory (~/.arduino15/packages/arduino/hardware/mbed_portenta/3.1.1/portenta_post_install.sh). Then run the following command using `sudo` ``` -$ cd ~/.arduino15/packages/arduino/hardware/mbed_portenta/3.0.0 +$ cd ~/.arduino15/packages/arduino/hardware/mbed_portenta/3.1.1 $ chmod 755 portenta_post_install.sh $ sudo ./portenta_post_install.sh ``` @@ -514,9 +514,9 @@ This will create the file `/etc/udev/rules.d/49-portenta_h7.rules` as follows: SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="035b", GROUP="plugdev", MODE="0666" ``` -Supposing the ArduinoCore-mbed core version is 3.0.0. Now only one file must be copied into the directory: +Supposing the ArduinoCore-mbed core version is 3.1.1. Now only one file must be copied into the directory: -- `~/.arduino15/packages/arduino/hardware/mbed_portenta/3.0.0/portenta_post_install.sh` +- `~/.arduino15/packages/arduino/hardware/mbed_portenta/3.1.1/portenta_post_install.sh` Whenever a new version is installed, remember to copy this files into the new version directory. For example, new version is x.yy.zz @@ -527,11 +527,11 @@ This file must be copied into the directory: #### 10. For RTL8720DN boards using AmebaD core - To avoid compile error relating to PROGMEM, you have to copy the file [Realtek AmebaD core pgmspace.h](Packages_Patches/realtek/hardware/AmebaD/3.1.2/cores/arduino/avr/pgmspace.h) into Realtek AmebaD directory (~/.arduino15/packages/realtek/hardware/AmebaD/3.1.2/cores/arduino/avr/pgmspace.h). + To avoid compile error relating to PROGMEM, you have to copy the file [Realtek AmebaD core pgmspace.h](Packages_Patches/realtek/hardware/AmebaD/3.1.3/cores/arduino/avr/pgmspace.h) into Realtek AmebaD directory (~/.arduino15/packages/realtek/hardware/AmebaD/3.1.3/cores/arduino/avr/pgmspace.h). -Supposing the Realtek AmebaD core version is 3.1.2. This file must be copied into the directory: +Supposing the Realtek AmebaD core version is 3.1.3. This file must be copied into the directory: -- `~/.arduino15/packages/realtek/hardware/AmebaD/3.1.2/cores/arduino/avr/pgmspace.h` +- `~/.arduino15/packages/realtek/hardware/AmebaD/3.1.3/cores/arduino/avr/pgmspace.h` Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied into the directory: @@ -541,11 +541,11 @@ This file must be copied into the directory: #### 11. For SAMD21 and SAMD51 boards using ArduinoCore-fab-sam core - To avoid compile error relating to SAMD21/SAMD51, you have to copy the file [ArduinoCore-fab-sam core pgmspace.h](Packages_Patches/Fab_SAM_Arduino/hardware/samd/1.6.18-alpha2/boards.txt) into `ArduinoCore-fab-sam` samd directory (~/.arduino15/packages/Fab_SAM_Arduino/hardware/samd/1.6.18-alpha2/boards.txt). + To avoid compile error relating to SAMD21/SAMD51, you have to copy the file [ArduinoCore-fab-sam core pgmspace.h](Packages_Patches/Fab_SAM_Arduino/hardware/samd/1.7.0/boards.txt) into `ArduinoCore-fab-sam` samd directory (~/.arduino15/packages/Fab_SAM_Arduino/hardware/samd/1.7.0/boards.txt). -Supposing the `ArduinoCore-fab-sam` samd core version is 1.6.18-alpha2. This file must be copied into the directory: +Supposing the `ArduinoCore-fab-sam` samd core version is 1.7.0. This file must be copied into the directory: -- `~/.arduino15/packages/Fab_SAM_Arduino/hardware/samd/1.6.18-alpha2/boards.txt` +- `~/.arduino15/packages/Fab_SAM_Arduino/hardware/samd/1.7.0/boards.txt` Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied into the directory: @@ -819,7 +819,6 @@ then select **one and only one** Ethernet library to use as follows: #define USE_NATIVE_ETHERNET false #define USE_QN_ETHERNET false #define USE_ETHERNET_GENERIC false -#define USE_ETHERNET_ESP8266 false #define USE_ETHERNET_ENC false #define USE_CUSTOM_ETHERNET false ``` @@ -833,7 +832,6 @@ To use W5x00 Ethernet, for example using Ethernet_Generic library #define USE_NATIVE_ETHERNET false #define USE_QN_ETHERNET false #define USE_ETHERNET_GENERIC true -#define USE_ETHERNET_ESP8266 false #define USE_ETHERNET_ENC false #define USE_CUSTOM_ETHERNET false ``` @@ -847,7 +845,6 @@ To use W5x00 Ethernet, for example using Ethernet_Generic library #define USE_NATIVE_ETHERNET false #define USE_QN_ETHERNET false #define USE_ETHERNET_GENERIC false -#define USE_ETHERNET_ESP8266 false #define USE_ETHERNET_ENC true #define USE_CUSTOM_ETHERNET false ``` @@ -861,7 +858,6 @@ To use W5x00 Ethernet, for example using Ethernet_Generic library #define USE_NATIVE_ETHERNET false #define USE_QN_ETHERNET false #define USE_ETHERNET_GENERIC false -#define USE_ETHERNET_ESP8266 false #define USE_ETHERNET_ENC false #define USE_CUSTOM_ETHERNET false ``` @@ -877,7 +873,6 @@ For example, EthernetLarge library #define USE_NATIVE_ETHERNET false #define USE_QN_ETHERNET false #define USE_ETHERNET_GENERIC false -#define USE_ETHERNET_ESP8266 false #define USE_ETHERNET_ENC false #define USE_CUSTOM_ETHERNET true @@ -929,7 +924,6 @@ For example, EthernetLarge library // Only one if the following to be true #define USE_ETHERNET_GENERIC true -#define USE_ETHERNET_ESP8266 false #define USE_ETHERNET_ENC false #define USE_CUSTOM_ETHERNET false ``` @@ -954,7 +948,6 @@ For example, EthernetLarge library #define USE_UIP_ETHERNET false #define USE_ETHERNET_GENERIC false -#define USE_ETHERNET_ESP8266 false #define USE_ETHERNET_ENC false #define USE_CUSTOM_ETHERNET false @@ -1408,28 +1401,28 @@ void loop() #### 1. File [Ethernet_Generic.ino](examples/Ethernet_Generic/Ethernet_Generic.ino) -https://github.com/khoih-prog/Ethernet_Manager/blob/e47eb286be6e8ba2caa5e46a6f83735a2a99424c/examples/Ethernet_Generic/Ethernet_Generic.ino#L13-L347 +https://github.com/khoih-prog/Ethernet_Manager/blob/d04bc0fedc077f0d4f6e7758ca0b4f879cc26d45/examples/Ethernet_Generic/Ethernet_Generic.ino#L13-L369 --- #### 2. File [defines.h](examples/Ethernet_Generic/defines.h) -https://github.com/khoih-prog/Ethernet_Manager/blob/e47eb286be6e8ba2caa5e46a6f83735a2a99424c/examples/Ethernet_Generic/defines.h#L13-L513 +https://github.com/khoih-prog/Ethernet_Manager/blob/d04bc0fedc077f0d4f6e7758ca0b4f879cc26d45/examples/Ethernet_Generic/defines.h#L13-L523 --- #### 3. File [Credentials.h](examples/Ethernet_Generic/Credentials.h) -https://github.com/khoih-prog/Ethernet_Manager/blob/e47eb286be6e8ba2caa5e46a6f83735a2a99424c/examples/Ethernet_Generic/Credentials.h#L13-L67 +https://github.com/khoih-prog/Ethernet_Manager/blob/d04bc0fedc077f0d4f6e7758ca0b4f879cc26d45/examples/Ethernet_Generic/Credentials.h#L13-L67 --- #### 4. File [dynamicParams.h](examples/Ethernet_Generic/dynamicParams.h) -https://github.com/khoih-prog/Ethernet_Manager/blob/e47eb286be6e8ba2caa5e46a6f83735a2a99424c/examples/Ethernet_Generic/dynamicParams.h#L13-L76 +https://github.com/khoih-prog/Ethernet_Manager/blob/d04bc0fedc077f0d4f6e7758ca0b4f879cc26d45/examples/Ethernet_Generic/dynamicParams.h#L13-L76 @@ -1447,7 +1440,7 @@ This is the terminal output of an Adafruit NRF52840_FEATHER board with W5500 Eth ``` Start Ethernet_nRF52 on NRF52840_FEATHER Ethernet Shield type W5x00 using Ethernet_Generic Library -Ethernet_Manager v1.7.2 +Ethernet_Manager v1.8.0 DoubleResetDetector_Generic v1.8.1 [EWS] =========== USE_ETHERNET_GENERIC =========== [EWS] Default SPI pinout: @@ -1539,7 +1532,7 @@ Pubs Topics = old-mqtt-PubTopic ```cpp Start Ethernet_nRF52 on NRF52840_FEATHER Ethernet Shield type : W5x00 using Ethernet_Generic Library -Ethernet_Manager v1.7.2 +Ethernet_Manager v1.8.0 DoubleResetDetector_Generic v1.8.1 [EWS] =========== USE_ETHERNET_GENERIC =========== [EWS] Default SPI pinout: @@ -1722,7 +1715,7 @@ This is the terminal output of an SeeedStudio SAMD21 SEEED_XIAO_M0 board with W5 ``` Start Ethernet_SAMD on SEEED_XIAO_M0 Ethernet Shield type : W5x00 using Ethernet Library -Ethernet_Manager v1.7.2 +Ethernet_Manager v1.8.0 DoubleResetDetector_Generic v1.8.1 Flag read = 0xffffffff No doubleResetDetected @@ -1799,7 +1792,7 @@ This is the terminal output of an Arduino SAM DUE board with W5100 Ethernet shie ``` Start Ethernet_SAM_DUE on SAM DUE Ethernet Shield type : W5x00 using Ethernet_Generic Library -Ethernet_Manager v1.7.2 +Ethernet_Manager v1.8.0 DoubleResetDetector_Generic v1.8.1 Flag read = 0xd0d01234 doubleResetDetected @@ -1885,7 +1878,7 @@ If no valid config data are stored in EEPROM, it will switch to `Configuration M ``` Start MQTT_ThingStream_Ethernet_Generic using LittleFS on ESP8266_NODEMCU Ethernet Shield type : W5x00 using Ethernet_Generic Library -Ethernet_Manager v1.7.2 +Ethernet_Manager v1.8.0 ESP_DoubleResetDetector v1.3.1 ========================= Currently Used SPI pinout: @@ -1933,7 +1926,7 @@ Enter your credentials (Blynk Servers/Tokens and Port). If you prefer static IP, ``` Start MQTT_ThingStream_Ethernet_Generic using LittleFS on ESP8266_NODEMCU Ethernet Shield type : W5x00 using Ethernet_Generic Library -Ethernet_Manager v1.7.2 +Ethernet_Manager v1.8.0 ESP_DoubleResetDetector v1.3.1 ========================= Currently Used SPI pinout: @@ -1993,7 +1986,7 @@ This is the terminal output of NRF52840_FEATHER board with ENC28J60 using Ethern ``` Start MQTT_ThingStream_Ethernet_Generic on NRF52840_FEATHER Ethernet Shield type : ENC28J60 using EthernetENC Library -Ethernet_Manager v1.7.2 +Ethernet_Manager v1.8.0 DoubleResetDetector_Generic v1.8.1 LittleFS Flag read = 0xd0d01234 Flag read = 0xd0d01234 @@ -2031,7 +2024,7 @@ esp32-sniffer/12345678/ble ``` Start MQTT_ThingStream_Ethernet_Generic on NRF52840_FEATHER Ethernet Shield type : ENC28J60 using EthernetENC Library -Ethernet_Manager v1.7.2 +Ethernet_Manager v1.8.0 DoubleResetDetector_Generic v1.8.1 LittleFS Flag read = 0xd0d04321 Flag read = 0xd0d04321 @@ -2088,7 +2081,7 @@ This is the terminal output of RASPBERRY_PI_PICO board with W5x00 using Ethernet ``` Start MQTT_ThingStream_Ethernet_RP2040 on RASPBERRY_PI_PICO Ethernet Shield type : W5x00 using Ethernet_Generic Library -Ethernet_Manager v1.7.2 +Ethernet_Manager v1.8.0 DoubleResetDetector_Generic v1.8.1 [EWS] =========== USE_ETHERNET_GENERIC =========== [EWS] Default SPI pinout: @@ -2145,7 +2138,7 @@ esp32-sniffer/12345678/ble ``` Start MQTT_ThingStream_Ethernet_RP2040 on RASPBERRY_PI_PICO Ethernet Shield type : W5x00 using Ethernet_Generic Library -Ethernet_Manager v1.7.2 +Ethernet_Manager v1.8.0 DoubleResetDetector_Generic v1.8.1 [EWS] =========== USE_ETHERNET_GENERIC =========== [EWS] Default SPI pinout: @@ -2218,7 +2211,7 @@ This is the terminal output of an MBED RASPBERRY_PI_PICO board with W5500 Ethern ``` Start Ethernet_RP2040 on MBED RASPBERRY_PI_PICO Ethernet Shield type : W5x00 using Ethernet_Generic Library -Ethernet_Manager v1.7.2 +Ethernet_Manager v1.8.0 DoubleResetDetector_Generic v1.8.1 [[EWS] =========== USE_ETHERNET_GENERIC =========== [EWS] Default SPI pinout: @@ -2291,7 +2284,7 @@ HHHH[ETM] h:Updating LittleFS: /fs/etm_config.dat ``` Start Ethernet_RP2040 on MBED RASPBERRY_PI_PICO Ethernet Shield type : W5x00 using Ethernet_Generic Library -Ethernet_Manager v1.7.2 +Ethernet_Manager v1.8.0 DoubleResetDetector_Generic v1.8.1 [EWS] =========== USE_ETHERNET_GENERIC =========== [EWS] Default SPI pinout: @@ -2360,8 +2353,8 @@ This is the terminal output of WT32-ETH01 board with LAN8720 Ethernet, running c ``` Start MQTT_ThingStream_Ethernet_WT32_ETH01 on WT32-ETH01 Ethernet Shield type : ETH_PHY_LAN8720 -WebServer_WT32_ETH01 v1.4.1 -Ethernet_Manager v1.7.2 +WebServer_WT32_ETH01 v1.5.0 +Ethernet_Manager v1.8.0 ESP_DoubleResetDetector v1.3.1 [ETM] Set CustomsStyle to : [ETM] Set CustomsHeadElement to : @@ -2443,7 +2436,7 @@ This is the terminal output of Teensy 4.1 board with built-in Ethernet, using QN ``` Starting QNEthernet_Teensy on TEENSY 4.1 using QNEthernet -Ethernet_Manager v1.7.2 +Ethernet_Manager v1.8.0 DoubleResetDetector_Generic v1.8.1 [EWS] =========== USE_QN_ETHERNET =========== QNEthernet using static IP @@ -2514,6 +2507,7 @@ Sometimes, the library will only work if you update the board core to the latest Submit issues to: [Ethernet_Manager issues](https://github.com/khoih-prog/Ethernet_Manager/issues) +--- --- ### TO DO @@ -2562,18 +2556,22 @@ Default Credentials and dynamic parameters 34. Support **SPI2 for ESP32** 35. Add support to SPI1 for RP2040 using [arduino-pico core](https://github.com/earlephilhower/arduino-pico) 36. Drop `EthernetWrapper` - +37. Fix `macAddress` bug. Check [Unable so set MAC Address #2](https://github.com/khoih-prog/Ethernet_Manager/issues/2) +38. Permit setting `macAddress` for supporting Ethernet shields W5x00 and ENC28J60 +39. Add functions relating to `macAddress` --- --- ### Contributions and Thanks -1. Thanks to [Miguel Alexandre Wisintainer](https://github.com/tcpipchip) for initiating, inspriring, working with, developing, debugging and testing. +1. Thanks to [Miguel Alexandre Wisintainer](https://github.com/tcpipchip) for initiating, inspriring, working with, developing, debugging and testing +2. Thanks to [sahlex](https://github.com/sahlex) to report issue [Unable so set MAC Address #2](https://github.com/khoih-prog/Ethernet_Manager/issues/2) leading to version v1.8.0 +
tcpipchip
⭐️ Miguel Wisintainer

sahlex
sahlex

@@ -2599,3 +2597,5 @@ If you want to contribute to this project: ### Copyright Copyright 2020- Khoi Hoang + + diff --git a/changelog.md b/changelog.md index 127c660e..5685a999 100644 --- a/changelog.md +++ b/changelog.md @@ -13,6 +13,7 @@ * [Changelog](#changelog) + * [Releases v1.8.0](#releases-v180) * [Releases v1.7.2](#releases-v172) * [Releases v1.7.1](#releases-v171) * [Major Releases v1.7.0](#major-releases-v170) @@ -32,6 +33,15 @@ ## Changelog +### Releases v1.8.0 + +1. Fix `macAddress` bug. Check [Unable so set MAC Address #2](https://github.com/khoih-prog/Ethernet_Manager/issues/2) +2. Permit setting `macAddress` for supporting Ethernet shields W5x00 and ENC28J60 +3. Add functions relating to `macAddress` +4. Rewrite all the examples to support new features +5. Drop support to `Ethernet_ESP8266` +6. Update `Packages' Patches` + ### Releases v1.7.2 1. Use new [Ethernet_Generic library](https://github.com/khoih-prog/Ethernet_Generic) as default for W5x00. diff --git a/library.json b/library.json index 011fadab..e1e5c9e9 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Ethernet_Manager", - "version": "1.7.2", + "version": "1.8.0", "keywords": "communication, ethernet, esp8266, esp32, esp32-s2, esp32-c3, QNEthernet, rp2040, nano-rp2040-connect, W5x00, lan8720, SAM-DUE, SAMD, STM32, nRF52, Credentials, config-portal, WT32-ETH01, Double-Reset, MQTT, rpi-pico, ENC28J60, SAMD51, DynamicParameters, dynamic-params, customs-header, Manager", "description": "Simple Ethernet Manager for Teensy, SAM DUE, SAMD, nRF52, ESP32 (including ESP32-S2/C3), ESP8266, RP2040-based Nano_RP2040_Connect, RASPBERRY_PI_PICO, etc. boards. Config data saved in ESP LittleFS, SPIFFS or EEPROM, nRF52 LittleFS, EEPROM, DueFlashStorage or SAMD FlashStorage. For configuring/auto(re)connecting Ethernet W5x00, ENC28J60 and NativeEthernet/QNEthernet at runtime. Use much less memory compared to full-fledge WiFiManager. Config Portal (CP) will be auto-adjusted to match the number of dynamic custom parameters. Optional default Credentials to be autoloaded into CP to use or change instead of manually input. Credentials are saved in LittleFS, (emulated-)EEPROM, FlashStorage_SAMD or DueFlashStorage. New powerful-yet-simple-to-use feature to enable adding dynamic parameters from sketch and input using the same CP. DoubleDetectDetector as well as Virtual Switches feature permits entering CP as requested. Configurable HTML Headers, Customs Style, Head Elements, CORS Header", "authors": @@ -27,7 +27,7 @@ { "owner": "khoih-prog", "name": "EthernetWebServer", - "version": ">=2.1.2", + "version": ">=2.2.2", "platforms": ["*"] }, { @@ -57,7 +57,7 @@ { "owner": "khoih-prog", "name": "WebServer_WT32_ETH01", - "version": "^1.4.1", + "version": "^1.5.0", "platforms": ["espressif32"] }, { @@ -69,12 +69,12 @@ { "owner": "khoih-prog", "name": "Ethernet_Generic", - "version": "^2.0.1" + "version": "^2.5.2" }, { "owner": "ssilverman", "name": "QNEthernet", - "version": ">=0.14.0", + "version": ">=0.15.0", "platforms": ["teensy"] } ], diff --git a/library.properties b/library.properties index cc4f7780..e1fdb265 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Ethernet_Manager -version=1.7.2 +version=1.8.0 author=Khoi Hoang license=MIT maintainer=Khoi Hoang diff --git a/platformio/platformio.ini b/platformio/platformio.ini index 44931302..d185589f 100644 --- a/platformio/platformio.ini +++ b/platformio/platformio.ini @@ -45,23 +45,23 @@ lib_compat_mode = strict lib_deps = ; PlatformIO 4.x -; EthernetWebServer@>=2.1.2 -; Ethernet_Generic>=2.0.1 +; EthernetWebServer@>=2.2.2 +; Ethernet_Generic>=2.5.2 ; ESP_DoubleResetDetector@>=1.3.1 ; DoubleResetDetector_Generic@>=1.8.1 ; Functional-Vlpp@>=1.0.2 ; FlashStorage_SAMD@>=1.3.2 -; WebServer_WT32_ETH01@>=1.4.1 +; WebServer_WT32_ETH01@>=1.5.0 ; QNEthernet@>=0.14.0 ; PlatformIO 5.x - khoih-prog/EthernetWebServer@>=2.1.2 - khoih-prog/Ethernet_Generic@~2.0.1 + khoih-prog/EthernetWebServer@>=2.2.2 + khoih-prog/Ethernet_Generic@~2.5.2 khoih-prog/ESP_DoubleResetDetector@>=1.3.1 khoih-prog/DoubleResetDetector_Generic@>=1.8.1 khoih-prog/Functional-Vlpp@>=1.0.2 khoih-prog/FlashStorage_SAMD@>=1.3.2 - khoih-prog/WebServer_WT32_ETH01@>=1.4.1 - ssilverman/QNEthernet@>=0.14.0 + khoih-prog/WebServer_WT32_ETH01@>=1.5.0 + ssilverman/QNEthernet@>=0.15.0 build_flags = ; set your debug output (default=Serial) diff --git a/src/Adapters/Ethernet_DUE_Manager.h b/src/Adapters/Ethernet_DUE_Manager.h index 1afbee89..404b9316 100644 --- a/src/Adapters/Ethernet_DUE_Manager.h +++ b/src/Adapters/Ethernet_DUE_Manager.h @@ -9,7 +9,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.7.2 + Version: 1.8.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -26,6 +26,7 @@ 1.7.0 K Hoang 27/11/2021 Auto detect ESP32 core to use correct LittleFS. Fix QNEthernet-related linkStatus. 1.7.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. 1.7.2 K Hoang 10/04/2022 Use Ethernet_Generic library as default. Support SPI1/SPI2 for RP2040/ESP32 + 1.8.0 K Hoang 07/09/2022 Fix macAddress bug. Add functions relating to macAddress *****************************************************************************************************************************/ #pragma once @@ -106,7 +107,7 @@ typedef struct ///NEW extern uint16_t NUM_MENU_ITEMS; extern MenuItem myMenuItems []; - bool *menuItemUpdated = NULL; + bool *menuItemUpdated = nullptr; #else #warning Not using Dynamic Parameters #endif @@ -449,7 +450,7 @@ class Ethernet_Manager #if USING_CUSTOMS_HEAD_ELEMENT //sets a custom element to add to head, like a new style tag - void setCustomsHeadElement(const char* CustomsHeadElement = NULL) + void setCustomsHeadElement(const char* CustomsHeadElement = nullptr) { _CustomsHeadElement = CustomsHeadElement; ETM_LOGDEBUG1(F("Set CustomsHeadElement to : "), _CustomsHeadElement); @@ -463,7 +464,7 @@ class Ethernet_Manager #endif #if USING_CORS_FEATURE - void setCORSHeader(const char* CORSHeaders = NULL) + void setCORSHeader(const char* CORSHeaders = nullptr) { _CORS_Header = CORSHeaders; @@ -477,6 +478,46 @@ class Ethernet_Manager } #endif + ////////////////////////////////////////////// + + uint8_t* getMacAddress() + { + return macAddress; + } + + ////////////////////////////////////////////// + + uint8_t* setMacAddress(const uint8_t* mac) + { + if ( isMacAddressValid(mac) ) + memcpy(macAddress, mac, sizeof(macAddress)); + + printMacAddress(); + + return macAddress; + } + + ////////////////////////////////////////////// + + void printMacAddress() + { + char theLocalBuffer[24]; + + snprintf(theLocalBuffer, sizeof(theLocalBuffer), "MAC:%02X-%02X-%02X-%02X-%02X-%02X", + macAddress[0], macAddress[1], + macAddress[2], macAddress[3], + macAddress[4], macAddress[5]); + + ETM_LOGWARN(theLocalBuffer); + } + + ////////////////////////////////////////////// + + bool isMacAddressValid(const uint8_t* mac) + { + return ( (mac != nullptr) && ( (mac[0] != 0) || (mac[1] != 0) || (mac[2] != 0) || (mac[3] != 0) ) ); + } + ////////////////////////////////////// @@ -504,17 +545,19 @@ class Ethernet_Manager uint16_t totalDataSize = 0; uint8_t currentBlynkServerIndex = 255; + + uint8_t macAddress[6] = { 0, 0, 0, 0, 0, 0 }; ///////////////////////////////////// // Add customs headers from v1.1.0 #if USING_CUSTOMS_STYLE - const char* ETM_HTML_HEAD_CUSTOMS_STYLE = NULL; + const char* ETM_HTML_HEAD_CUSTOMS_STYLE = nullptr; #endif #if USING_CUSTOMS_HEAD_ELEMENT - const char* _CustomsHeadElement = NULL; + const char* _CustomsHeadElement = nullptr; #endif #if USING_CORS_FEATURE @@ -594,7 +637,7 @@ class Ethernet_Manager #define ETHERNET_BOARD_TYPE "SAMDUE" #define WM_NO_CONFIG "blank" -uint16_t EEPROM_SIZE = (IFLASH1_PAGE_SIZE / sizeof(byte)) * 4; +uint16_t EEPROM_SIZE = (IFLASH1_PAGE_SIZE / sizeof(uint8_t)) * 4; #ifndef EEPROM_START #define EEPROM_START 0 @@ -609,7 +652,7 @@ uint16_t EEPROM_SIZE = (IFLASH1_PAGE_SIZE / sizeof(byte)) * 4; int checkSum = 0; for (uint16_t index = 0; index < (sizeof(Ethernet_Manager_config) - sizeof(Ethernet_Manager_config.checkSum)); index++) { - checkSum += * ( ( (byte*) &Ethernet_Manager_config ) + index); + checkSum += * ( ( (uint8_t*) &Ethernet_Manager_config ) + index); } return checkSum; @@ -623,7 +666,7 @@ uint16_t EEPROM_SIZE = (IFLASH1_PAGE_SIZE / sizeof(byte)) * 4; uint16_t offset = CONFIG_EEPROM_START + CONFIG_DATA_SIZE; - dueFlashStorageData.write(offset, (byte *) &readForcedConfigPortalFlag, sizeof(readForcedConfigPortalFlag)); + dueFlashStorageData.write(offset, (uint8_t *) &readForcedConfigPortalFlag, sizeof(readForcedConfigPortalFlag)); } ////////////////////////////////////////////// @@ -658,7 +701,7 @@ uint16_t EEPROM_SIZE = (IFLASH1_PAGE_SIZE / sizeof(byte)) * 4; // => set flag noForcedConfigPortal = false uint16_t offset = CONFIG_EEPROM_START + CONFIG_DATA_SIZE; - byte* dataPointer = (byte* ) dueFlashStorageData.readAddress(offset); + uint8_t* dataPointer = (uint8_t* ) dueFlashStorageData.readAddress(offset); memcpy(&readForcedConfigPortalFlag, dataPointer, sizeof(readForcedConfigPortalFlag)); //EEPROM.get(CONFIG_EEPROM_START + CONFIG_DATA_SIZE, readForcedConfigPortalFlag); @@ -693,11 +736,11 @@ uint16_t EEPROM_SIZE = (IFLASH1_PAGE_SIZE / sizeof(byte)) * 4; uint16_t byteCount = 0; #define BIG_BUFFER_LEN 768 - byte bigBuffer[BIG_BUFFER_LEN + 1]; + uint8_t bigBuffer[BIG_BUFFER_LEN + 1]; uint16_t offset = CONFIG_EEPROM_START + sizeof(Ethernet_Manager_config) + FORCED_CONFIG_PORTAL_FLAG_DATA_SIZE; - // Make address 4-byte aligned + // Make address 4-uint8_t aligned if ( (offset % 4) != 0 ) { offset += 4 - (offset % 4); @@ -721,8 +764,8 @@ uint16_t EEPROM_SIZE = (IFLASH1_PAGE_SIZE / sizeof(byte)) * 4; } // Both Buffers big enough, read all dynamicData to BigBuffer once - // as address need to be 4-byte aligned - byte* dataPointer = (byte* ) dueFlashStorageData.readAddress(offset); + // as address need to be 4-uint8_t aligned + uint8_t* dataPointer = (uint8_t* ) dueFlashStorageData.readAddress(offset); // Prepare buffer, more than enough memset(bigBuffer, 0, sizeof(bigBuffer)); @@ -760,7 +803,7 @@ uint16_t EEPROM_SIZE = (IFLASH1_PAGE_SIZE / sizeof(byte)) * 4; { uint16_t offset = CONFIG_EEPROM_START + sizeof(Ethernet_Manager_config) + FORCED_CONFIG_PORTAL_FLAG_DATA_SIZE; - // Make address 4-byte aligned + // Make address 4-uint8_t aligned if ( (offset % 4) != 0 ) { offset += 4 - (offset % 4); @@ -772,9 +815,9 @@ uint16_t EEPROM_SIZE = (IFLASH1_PAGE_SIZE / sizeof(byte)) * 4; uint16_t byteCount = 0; #define BIG_BUFFER_LEN 768 - byte buffer[BIG_BUFFER_LEN + 1]; + uint8_t buffer[BIG_BUFFER_LEN + 1]; - byte* dataPointer = (byte* ) dueFlashStorageData.readAddress(offset); + uint8_t* dataPointer = (uint8_t* ) dueFlashStorageData.readAddress(offset); memcpy(buffer, dataPointer, sizeof(buffer)); @@ -817,7 +860,7 @@ uint16_t EEPROM_SIZE = (IFLASH1_PAGE_SIZE / sizeof(byte)) * 4; { uint16_t offset = CONFIG_EEPROM_START + sizeof(Ethernet_Manager_config) + FORCED_CONFIG_PORTAL_FLAG_DATA_SIZE; - // Make address 4-byte aligned + // Make address 4-uint8_t aligned if ( (offset % 4) != 0 ) { offset += 4 - (offset % 4); @@ -827,7 +870,7 @@ uint16_t EEPROM_SIZE = (IFLASH1_PAGE_SIZE / sizeof(byte)) * 4; uint16_t byteCount = 0; // Use 2K buffer, if need more memory, can reduce this - byte buffer[2048]; + uint8_t buffer[2048]; for (int i = 0; i < NUM_MENU_ITEMS; i++) { @@ -877,7 +920,7 @@ uint16_t EEPROM_SIZE = (IFLASH1_PAGE_SIZE / sizeof(byte)) * 4; { uint16_t offset = CONFIG_EEPROM_START; - byte* dataPointer = (byte* ) dueFlashStorageData.readAddress(offset); + uint8_t* dataPointer = (uint8_t* ) dueFlashStorageData.readAddress(offset); memcpy(&Ethernet_Manager_config, dataPointer, sizeof(Ethernet_Manager_config)); @@ -892,7 +935,7 @@ uint16_t EEPROM_SIZE = (IFLASH1_PAGE_SIZE / sizeof(byte)) * 4; { uint16_t offset = CONFIG_EEPROM_START; - dueFlashStorageData.write(offset, (byte *) &Ethernet_Manager_config, sizeof(Ethernet_Manager_config)); + dueFlashStorageData.write(offset, (uint8_t *) &Ethernet_Manager_config, sizeof(Ethernet_Manager_config)); } ////////////////////////////////////////////// @@ -935,7 +978,7 @@ uint16_t EEPROM_SIZE = (IFLASH1_PAGE_SIZE / sizeof(byte)) * 4; hadConfigData = false; - // For DUE, DATA_LENGTH = ((IFLASH1_PAGE_SIZE/sizeof(byte))*4) = 1KBytes + // For DUE, DATA_LENGTH = ((IFLASH1_PAGE_SIZE/sizeof(uint8_t))*4) = 1KBytes ETM_LOGERROR1(F("Simulate EEPROM, Sz:"), DATA_LENGTH); // Use new LOAD_DEFAULT_CONFIG_DATA logic @@ -1362,15 +1405,28 @@ uint16_t EEPROM_SIZE = (IFLASH1_PAGE_SIZE / sizeof(byte)) * 4; // Use static IP ETM_LOGWARN1(F("Start connectEthernet using Static IP ="), staticIP); - Ethernet.begin(SelectMacAddress(NULL), staticIP); + // If macAddress valid, use it + if (isMacAddressValid(macAddress)) + Ethernet.begin(SelectMacAddress(macAddress), staticIP); + else + Ethernet.begin(SelectMacAddress(NULL), staticIP); + ethernetConnected = true; } else { - // If static_IP ="nothing" or NULL, use DHCP dynamic IP + // If static_IP ="nothing" or NULL, use DHCP dynamic IP ETM_LOGWARN(F("Start connectEthernet using DHCP")); - ethernetConnected = ( Ethernet.begin(SelectMacAddress(NULL)) == 1); + // If macAddress valid, use it + if (isMacAddressValid(macAddress)) + { + ethernetConnected = ( Ethernet.begin(SelectMacAddress(macAddress)) == 1); + } + else + { + ethernetConnected = ( Ethernet.begin(SelectMacAddress(macAddress)) == 1); + } } // give the Ethernet shield a second to initialize: @@ -1388,47 +1444,53 @@ uint16_t EEPROM_SIZE = (IFLASH1_PAGE_SIZE / sizeof(byte)) * 4; return ethernetConnected; } - byte* SelectMacAddress(const byte mac[]) + /////////////////////////////////////////////////////////////////// + + uint8_t* SelectMacAddress(const uint8_t* mac) { - if (mac != NULL) + char localBuffer[24]; + + if (isMacAddressValid(mac)) { - return (byte*)mac; + return (uint8_t*)mac; } + // Initial mac to manipulate from macAddress[0] = 0xFE; - macAddress[1] = 0xAB; - macAddress[2] = 0xCD; - macAddress[3] = 0xEF; - macAddress[4] = 0xED; - macAddress[5] = 0xBA; + macAddress[1] = 0xED; + macAddress[2] = 0xDE; + macAddress[3] = 0xAD; + macAddress[4] = 0xBE; + macAddress[5] = 0xEF; - const char* token = String(millis()).c_str(); +#define TOKEN_LEN 8 - int len = strlen(token); + char token[TOKEN_LEN]; + uint32_t curTime = millis(); + snprintf(token, sizeof(token), "%ld", curTime * curTime); + int mac_index = 1; - - for (uint16_t i = 0; i < len; i++) + + ETM_LOGDEBUG3("token =", token, ", len =", TOKEN_LEN); + + for (uint16_t i = 0; i < TOKEN_LEN; i++) { macAddress[mac_index] ^= token[i]; - if (++mac_index > 5) { + if (++mac_index > 5) + { mac_index = 1; } } - - char localBuffer[24]; - + snprintf(localBuffer, sizeof(localBuffer), "MAC:%02X-%02X-%02X-%02X-%02X-%02X", macAddress[0], macAddress[1], macAddress[2], macAddress[3], macAddress[4], macAddress[5]); - ETM_LOGWARN(localBuffer); + ETM_LOGWARN1(F("Calculated =>"), localBuffer); return macAddress; } - - byte macAddress[6]; - }; #endif // Ethernet_DUE_Manager_h diff --git a/src/Adapters/Ethernet_ESP32_Manager.h b/src/Adapters/Ethernet_ESP32_Manager.h index ed41eb15..2aff8a2c 100644 --- a/src/Adapters/Ethernet_ESP32_Manager.h +++ b/src/Adapters/Ethernet_ESP32_Manager.h @@ -10,7 +10,7 @@ net_Manager Licensed under MIT license - Version: 1.7.2 + Version: 1.8.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -27,6 +27,7 @@ net_Manager 1.7.0 K Hoang 27/11/2021 Auto detect ESP32 core to use correct LittleFS. Fix QNEthernet-related linkStatus. 1.7.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. 1.7.2 K Hoang 10/04/2022 Use Ethernet_Generic library as default. Support SPI1/SPI2 for RP2040/ESP32 + 1.8.0 K Hoang 07/09/2022 Fix macAddress bug. Add functions relating to macAddress *****************************************************************************************************************************/ #pragma once @@ -155,7 +156,7 @@ typedef struct ///NEW extern uint16_t NUM_MENU_ITEMS; extern MenuItem myMenuItems []; - bool *menuItemUpdated = NULL; + bool *menuItemUpdated = nullptr; #else #warning Not using Dynamic Parameters #endif @@ -502,7 +503,7 @@ class Ethernet_Manager #if USING_CUSTOMS_HEAD_ELEMENT //sets a custom element to add to head, like a new style tag - void setCustomsHeadElement(const char* CustomsHeadElement = NULL) + void setCustomsHeadElement(const char* CustomsHeadElement = nullptr) { _CustomsHeadElement = CustomsHeadElement; ETM_LOGDEBUG1(F("Set CustomsHeadElement to : "), _CustomsHeadElement); @@ -516,7 +517,7 @@ class Ethernet_Manager #endif #if USING_CORS_FEATURE - void setCORSHeader(const char* CORSHeaders = NULL) + void setCORSHeader(const char* CORSHeaders = nullptr) { _CORS_Header = CORSHeaders; @@ -530,6 +531,69 @@ class Ethernet_Manager } #endif + ////////////////////////////////////////////// + + uint8_t* getMacAddress() + { + return macAddress; + } + + ////////////////////////////////////////////// + + uint8_t* setMacAddress(const uint8_t* mac) + { + if ( isMacAddressValid(mac) ) + memcpy(macAddress, mac, sizeof(macAddress)); + + printMacAddress(); + + return macAddress; + } + + ////////////////////////////////////////////// + + void printMacAddress() + { + char theLocalBuffer[24]; + + snprintf(theLocalBuffer, sizeof(theLocalBuffer), "MAC:%02X-%02X-%02X-%02X-%02X-%02X", + macAddress[0], macAddress[1], + macAddress[2], macAddress[3], + macAddress[4], macAddress[5]); + + ETM_LOGWARN(theLocalBuffer); + } + + ////////////////////////////////////////////// + + bool isMacAddressValid(const uint8_t* mac) + { + return ( (mac != nullptr) && ( (mac[0] != 0) || (mac[1] != 0) || (mac[2] != 0) || (mac[3] != 0) ) ); + } + + ////////////////////////////////////////////// + + bool isEthernetConnected() + { + return (ethernetConnected == true); + } + + ////////////////////////////////////////////// + + void setEthernetConnected() + { + ethernetConnected = true; + } + + ////////////////////////////////////////////// + + void setEthernetDisconnected() + { + ethernetConnected = false; + } + + //bool ethernetConnected = false; + ////////////////////////////////////// @@ -557,17 +621,19 @@ class Ethernet_Manager uint16_t totalDataSize = 0; uint8_t currentBlynkServerIndex = 255; + + uint8_t macAddress[6] = { 0, 0, 0, 0, 0, 0 }; ///////////////////////////////////// // Add customs headers from v1.1.0 #if USING_CUSTOMS_STYLE - const char* ETM_HTML_HEAD_CUSTOMS_STYLE = NULL; + const char* ETM_HTML_HEAD_CUSTOMS_STYLE = nullptr; #endif #if USING_CUSTOMS_HEAD_ELEMENT - const char* _CustomsHeadElement = NULL; + const char* _CustomsHeadElement = nullptr; #endif #if USING_CORS_FEATURE @@ -652,7 +718,7 @@ class Ethernet_Manager int checkSum = 0; for (uint16_t index = 0; index < (sizeof(Ethernet_Manager_config) - sizeof(Ethernet_Manager_config.checkSum)); index++) { - checkSum += * ( ( (byte*) &Ethernet_Manager_config ) + index); + checkSum += * ( ( (uint8_t*) &Ethernet_Manager_config ) + index); } return checkSum; @@ -820,7 +886,7 @@ class Ethernet_Manager readBuffer = new char[ maxBufferLength + 1 ]; // check to see NULL => stop and return false - if (readBuffer == NULL) + if (readBuffer == nullptr) { ETM_LOGERROR(F("ChkCrR: Error can't allocate buffer.")); return false; @@ -1943,15 +2009,24 @@ class Ethernet_Manager // Use static IP ETM_LOGWARN1(F("Start connectEthernet using Static IP ="), staticIP); - Ethernet.begin(SelectMacAddress(NULL), staticIP); + // If macAddress valid, use it + if (isMacAddressValid(macAddress)) + Ethernet.begin(SelectMacAddress(macAddress), staticIP); + else + Ethernet.begin(SelectMacAddress(nullptr), staticIP); + ethernetConnected = true; } else { - // If static_IP ="nothing" or NULL, use DHCP dynamic IP + // If static_IP ="nothing" or nullptr, use DHCP dynamic IP ETM_LOGWARN(F("Start connectEthernet using DHCP")); - ethernetConnected = ( Ethernet.begin(SelectMacAddress(NULL)) == 1); + // If macAddress valid, use it + if (isMacAddressValid(macAddress)) + ethernetConnected = ( Ethernet.begin(SelectMacAddress(macAddress)) == 1); + else + ethernetConnected = ( Ethernet.begin(SelectMacAddress(nullptr)) == 1); } // give the Ethernet shield a second to initialize: @@ -1969,48 +2044,70 @@ class Ethernet_Manager return ethernetConnected; } - byte* SelectMacAddress(const byte mac[]) + /////////////////////////////////////////////////////////////////// + + uint8_t* SelectMacAddress(const uint8_t* mac) { - if (mac != NULL) + char localBuffer[24]; + + if (isMacAddressValid(mac)) { - return (byte*)mac; + return (uint8_t*)mac; } +#if USE_ETHERNET_GENERIC + Ethernet.MACAddress(macAddress); +#endif + + printMacAddress(); + + if (isMacAddressValid(macAddress)) + { + return macAddress; + } + + // Initial mac to manipulate from macAddress[0] = 0xFE; - macAddress[1] = 0xAB; - macAddress[2] = 0xCD; - macAddress[3] = 0xEF; - macAddress[4] = 0xED; - macAddress[5] = 0xBA; + macAddress[1] = 0xED; + macAddress[2] = 0xDE; + macAddress[3] = 0xAD; + macAddress[4] = 0xBE; + macAddress[5] = 0xEF; - const char* token = String(millis()).c_str(); +#define TOKEN_LEN 8 - int len = strlen(token); + char token[TOKEN_LEN]; + uint32_t curTime = millis(); + snprintf(token, sizeof(token), "%ld", curTime * curTime); + int mac_index = 1; - - for (uint16_t i = 0; i < len; i++) + + ETM_LOGDEBUG3("token =", token, ", len =", TOKEN_LEN); + + for (uint16_t i = 0; i < TOKEN_LEN; i++) { macAddress[mac_index] ^= token[i]; - if (++mac_index > 5) { + if (++mac_index > 5) + { mac_index = 1; } } - - char localBuffer[24]; - + snprintf(localBuffer, sizeof(localBuffer), "MAC:%02X-%02X-%02X-%02X-%02X-%02X", macAddress[0], macAddress[1], macAddress[2], macAddress[3], macAddress[4], macAddress[5]); - ETM_LOGWARN(localBuffer); + ETM_LOGWARN1(F("Calculated =>"), localBuffer); + +#if USE_ETHERNET_GENERIC + // Set for later use + Ethernet.setMACAddress(macAddress); +#endif return macAddress; } - - byte macAddress[6]; - }; #endif // Ethernet_ESP32_Manager_h diff --git a/src/Adapters/Ethernet_ESP8266_Manager.h b/src/Adapters/Ethernet_ESP8266_Manager.h index 27551ed5..02ffb7ba 100644 --- a/src/Adapters/Ethernet_ESP8266_Manager.h +++ b/src/Adapters/Ethernet_ESP8266_Manager.h @@ -9,7 +9,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.7.2 + Version: 1.8.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -26,6 +26,7 @@ 1.7.0 K Hoang 27/11/2021 Auto detect ESP32 core to use correct LittleFS. Fix QNEthernet-related linkStatus. 1.7.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. 1.7.2 K Hoang 10/04/2022 Use Ethernet_Generic library as default. Support SPI1/SPI2 for RP2040/ESP32 + 1.8.0 K Hoang 07/09/2022 Fix macAddress bug. Add functions relating to macAddress *****************************************************************************************************************************/ #pragma once @@ -135,7 +136,7 @@ typedef struct ///NEW extern uint16_t NUM_MENU_ITEMS; extern MenuItem myMenuItems []; - bool *menuItemUpdated = NULL; + bool *menuItemUpdated = nullptr; #else #warning Not using Dynamic Parameters #endif @@ -377,7 +378,7 @@ class Ethernet_Manager if (!hadConfigData) getConfigData(); - // Check if NULL pointer + // Check if nullptr pointer if (configData) memcpy(configData, &Ethernet_Manager_config, sizeof(Ethernet_Manager_config)); @@ -469,45 +470,95 @@ class Ethernet_Manager void setCustomsStyle(const char* CustomsStyle = ETM_HTML_HEAD_STYLE) { ETM_HTML_HEAD_CUSTOMS_STYLE = CustomsStyle; - ETM_LOGDEBUG1(F("Set CustomsStyle to : "), ETM_HTML_HEAD_CUSTOMS_STYLE); + ETM_LOGDEBUG1(F("Set CustomsStyle to :"), ETM_HTML_HEAD_CUSTOMS_STYLE); } + ////////////////////////////////////////////// + const char* getCustomsStyle() { - ETM_LOGDEBUG1(F("Get CustomsStyle = "), ETM_HTML_HEAD_CUSTOMS_STYLE); + ETM_LOGDEBUG1(F("Get CustomsStyle ="), ETM_HTML_HEAD_CUSTOMS_STYLE); return ETM_HTML_HEAD_CUSTOMS_STYLE; } #endif + + ////////////////////////////////////////////// #if USING_CUSTOMS_HEAD_ELEMENT //sets a custom element to add to head, like a new style tag - void setCustomsHeadElement(const char* CustomsHeadElement = NULL) + void setCustomsHeadElement(const char* CustomsHeadElement = nullptr) { _CustomsHeadElement = CustomsHeadElement; - ETM_LOGDEBUG1(F("Set CustomsHeadElement to : "), _CustomsHeadElement); + ETM_LOGDEBUG1(F("Set CustomsHeadElement to :"), _CustomsHeadElement); } + ////////////////////////////////////////////// + const char* getCustomsHeadElement() { - ETM_LOGDEBUG1(F("Get CustomsHeadElement = "), _CustomsHeadElement); + ETM_LOGDEBUG1(F("Get CustomsHeadElement ="), _CustomsHeadElement); return _CustomsHeadElement; } #endif - + + ////////////////////////////////////////////// + #if USING_CORS_FEATURE - void setCORSHeader(const char* CORSHeaders = NULL) + void setCORSHeader(const char* CORSHeaders = nullptr) { _CORS_Header = CORSHeaders; - ETM_LOGDEBUG1(F("Set CORS Header to : "), _CORS_Header); + ETM_LOGDEBUG1(F("Set CORS Header to :"), _CORS_Header); } + ////////////////////////////////////////////// + const char* getCORSHeader() { - ETM_LOGDEBUG1(F("Get CORS Header = "), _CORS_Header); + ETM_LOGDEBUG1(F("Get CORS Header ="), _CORS_Header); return _CORS_Header; } #endif + + ////////////////////////////////////////////// + + uint8_t* getMacAddress() + { + return macAddress; + } + + ////////////////////////////////////////////// + + uint8_t* setMacAddress(const uint8_t* mac) + { + if ( isMacAddressValid(mac) ) + memcpy(macAddress, mac, sizeof(macAddress)); + + printMacAddress(); + + return macAddress; + } + + ////////////////////////////////////////////// + + void printMacAddress() + { + char theLocalBuffer[24]; + + snprintf(theLocalBuffer, sizeof(theLocalBuffer), "MAC:%02X-%02X-%02X-%02X-%02X-%02X", + macAddress[0], macAddress[1], + macAddress[2], macAddress[3], + macAddress[4], macAddress[5]); + + ETM_LOGWARN(theLocalBuffer); + } + + ////////////////////////////////////////////// + + bool isMacAddressValid(const uint8_t* mac) + { + return ( (mac != nullptr) && ( (mac[0] != 0) || (mac[1] != 0) || (mac[2] != 0) || (mac[3] != 0) ) ); + } ////////////////////////////////////// @@ -536,17 +587,19 @@ class Ethernet_Manager uint16_t totalDataSize = 0; uint8_t currentBlynkServerIndex = 255; + + uint8_t macAddress[6] = { 0, 0, 0, 0, 0, 0 }; ///////////////////////////////////// // Add customs headers from v1.1.0 #if USING_CUSTOMS_STYLE - const char* ETM_HTML_HEAD_CUSTOMS_STYLE = NULL; + const char* ETM_HTML_HEAD_CUSTOMS_STYLE = nullptr; #endif #if USING_CUSTOMS_HEAD_ELEMENT - const char* _CustomsHeadElement = NULL; + const char* _CustomsHeadElement = nullptr; #endif #if USING_CORS_FEATURE @@ -571,7 +624,7 @@ class Ethernet_Manager } else { - // Prepare and store the hostname only not NULL + // Prepare and store the hostname only not nullptr getRFC952_hostname(iHostname); } @@ -631,7 +684,7 @@ class Ethernet_Manager int checkSum = 0; for (uint16_t index = 0; index < (sizeof(Ethernet_Manager_config) - sizeof(Ethernet_Manager_config.checkSum)); index++) { - checkSum += * ( ( (byte*) &Ethernet_Manager_config ) + index); + checkSum += * ( ( (uint8_t*) &Ethernet_Manager_config ) + index); } return checkSum; @@ -654,7 +707,7 @@ class Ethernet_Manager { File file = FileFS.open(CONFIG_PORTAL_FILENAME, "w"); - ETM_LOGINFO(F("SaveCPFile ")); + ETM_LOGINFO(F("SaveCPFile")); if (file) { @@ -670,7 +723,7 @@ class Ethernet_Manager // Trying open redundant CP file file = FileFS.open(CONFIG_PORTAL_FILENAME_BACKUP, "w"); - ETM_LOGINFO(F("SaveBkUpCPFile ")); + ETM_LOGINFO(F("SaveBkUpCPFile")); if (file) { @@ -715,7 +768,7 @@ class Ethernet_Manager ETM_LOGDEBUG(F("Check if isForcedCP")); File file = FileFS.open(CONFIG_PORTAL_FILENAME, "r"); - ETM_LOGINFO(F("LoadCPFile ")); + ETM_LOGINFO(F("LoadCPFile")); if (!file) { @@ -723,7 +776,7 @@ class Ethernet_Manager // Trying open redundant config file file = FileFS.open(CONFIG_PORTAL_FILENAME_BACKUP, "r"); - ETM_LOGINFO(F("LoadBkUpCPFile ")); + ETM_LOGINFO(F("LoadBkUpCPFile")); if (!file) { @@ -766,7 +819,7 @@ class Ethernet_Manager char* readBuffer; File file = FileFS.open(CREDENTIALS_FILENAME, "r"); - ETM_LOGINFO(F("LoadCredFile ")); + ETM_LOGINFO(F("LoadCredFile")); if (!file) { @@ -774,7 +827,7 @@ class Ethernet_Manager // Trying open redundant config file file = FileFS.open(CREDENTIALS_FILENAME_BACKUP, "r"); - ETM_LOGINFO(F("LoadBkUpCredFile ")); + ETM_LOGINFO(F("LoadBkUpCredFile")); if (!file) { @@ -798,8 +851,8 @@ class Ethernet_Manager { readBuffer = new char[ maxBufferLength + 1 ]; - // check to see NULL => stop and return false - if (readBuffer == NULL) + // check to see nullptr => stop and return false + if (readBuffer == nullptr) { ETM_LOGERROR(F("ChkCrR: Error can't allocate buffer.")); return false; @@ -855,7 +908,7 @@ class Ethernet_Manager totalDataSize = sizeof(Ethernet_Manager_config) + sizeof(readCheckSum); File file = FileFS.open(CREDENTIALS_FILENAME, "r"); - ETM_LOGINFO(F("LoadCredFile ")); + ETM_LOGINFO(F("LoadCredFile")); if (!file) { @@ -863,7 +916,7 @@ class Ethernet_Manager // Trying open redundant config file file = FileFS.open(CREDENTIALS_FILENAME_BACKUP, "r"); - ETM_LOGINFO(F("LoadBkUpCredFile ")); + ETM_LOGINFO(F("LoadBkUpCredFile")); if (!file) { @@ -912,7 +965,7 @@ class Ethernet_Manager int checkSum = 0; File file = FileFS.open(CREDENTIALS_FILENAME, "w"); - ETM_LOGINFO(F("SaveCredFile ")); + ETM_LOGINFO(F("SaveCredFile")); for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) { @@ -950,7 +1003,7 @@ class Ethernet_Manager // Trying open redundant Auth file file = FileFS.open(CREDENTIALS_FILENAME_BACKUP, "w"); - ETM_LOGINFO(F("SaveBkUpCredFile ")); + ETM_LOGINFO(F("SaveBkUpCredFile")); for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) { @@ -1004,7 +1057,7 @@ class Ethernet_Manager bool loadConfigData() { - ETM_LOGINFO(F("LoadCfgFile ")); + ETM_LOGINFO(F("LoadCfgFile")); // file existed File file = FileFS.open(CONFIG_FILENAME, "r"); @@ -1016,7 +1069,7 @@ class Ethernet_Manager // Trying open redundant config file file = FileFS.open(CONFIG_FILENAME_BACKUP, "r"); - ETM_LOGINFO(F("LoadBkUpCfgFile ")); + ETM_LOGINFO(F("LoadBkUpCfgFile")); if (!file) { @@ -1039,7 +1092,7 @@ class Ethernet_Manager void saveConfigData() { - ETM_LOGINFO(F("SaveCfgFile ")); + ETM_LOGINFO(F("SaveCfgFile")); int calChecksum = calcChecksum(); Ethernet_Manager_config.checkSum = calChecksum; @@ -1060,7 +1113,7 @@ class Ethernet_Manager ETM_LOGINFO(F("failed")); } - ETM_LOGINFO(F("SaveBkUpCfgFile ")); + ETM_LOGINFO(F("SaveBkUpCfgFile")); // Trying open redundant Auth file file = FileFS.open(CONFIG_FILENAME_BACKUP, "w"); @@ -1901,7 +1954,7 @@ class Ethernet_Manager { configTimeout = millis() + CONFIG_TIMEOUT; - ETM_LOGDEBUG3(F("s:millis() = "), millis(), F(", configTimeout = "), configTimeout); + ETM_LOGDEBUG3(F("s:millis() ="), millis(), F(", configTimeout ="), configTimeout); } else { @@ -1924,15 +1977,24 @@ class Ethernet_Manager // Use static IP ETM_LOGWARN1(F("Start connectEthernet using Static IP ="), staticIP); - Ethernet.begin(SelectMacAddress(NULL), staticIP); + // If macAddress valid, use it + if (isMacAddressValid(macAddress)) + Ethernet.begin(SelectMacAddress(macAddress), staticIP); + else + Ethernet.begin(SelectMacAddress(nullptr), staticIP); + ethernetConnected = true; } else { - // If static_IP ="nothing" or NULL, use DHCP dynamic IP + // If static_IP ="nothing" or nullptr, use DHCP dynamic IP ETM_LOGWARN(F("Start connectEthernet using DHCP")); - ethernetConnected = ( Ethernet.begin(SelectMacAddress(NULL)) == 1); + // If macAddress valid, use it + if (isMacAddressValid(macAddress)) + ethernetConnected = ( Ethernet.begin(SelectMacAddress(macAddress)) == 1); + else + ethernetConnected = ( Ethernet.begin(SelectMacAddress(nullptr)) == 1); } // give the Ethernet shield a second to initialize: @@ -1949,49 +2011,71 @@ class Ethernet_Manager return ethernetConnected; } + + /////////////////////////////////////////////////////////////////// - byte* SelectMacAddress(const byte mac[]) + uint8_t* SelectMacAddress(const uint8_t* mac) { - if (mac != NULL) + char localBuffer[24]; + + if (isMacAddressValid(mac)) { - return (byte*)mac; + return (uint8_t*)mac; } +#if USE_ETHERNET_GENERIC + Ethernet.MACAddress(macAddress); +#endif + + printMacAddress(); + + if (isMacAddressValid(macAddress)) + { + return macAddress; + } + + // Initial mac to manipulate from macAddress[0] = 0xFE; - macAddress[1] = 0xAB; - macAddress[2] = 0xCD; - macAddress[3] = 0xEF; - macAddress[4] = 0xED; - macAddress[5] = 0xBA; + macAddress[1] = 0xED; + macAddress[2] = 0xDE; + macAddress[3] = 0xAD; + macAddress[4] = 0xBE; + macAddress[5] = 0xEF; - const char* token = String(millis()).c_str(); +#define TOKEN_LEN 8 - int len = strlen(token); + char token[TOKEN_LEN]; + uint32_t curTime = millis(); + snprintf(token, sizeof(token), "%d", curTime * curTime); + int mac_index = 1; - - for (uint16_t i = 0; i < len; i++) + + ETM_LOGDEBUG3("token =", token, ", len =", TOKEN_LEN); + + for (uint16_t i = 0; i < TOKEN_LEN; i++) { macAddress[mac_index] ^= token[i]; - if (++mac_index > 5) { + if (++mac_index > 5) + { mac_index = 1; } } - - char localBuffer[24]; - + snprintf(localBuffer, sizeof(localBuffer), "MAC:%02X-%02X-%02X-%02X-%02X-%02X", macAddress[0], macAddress[1], macAddress[2], macAddress[3], macAddress[4], macAddress[5]); - ETM_LOGWARN(localBuffer); + ETM_LOGWARN1(F("Calculated =>"), localBuffer); + +#if USE_ETHERNET_GENERIC + // Set for later use + Ethernet.setMACAddress(macAddress); +#endif return macAddress; } - - byte macAddress[6]; - }; #endif // Ethernet_ESP8266_Manager_h diff --git a/src/Adapters/Ethernet_MBED_RP2040_Manager.h b/src/Adapters/Ethernet_MBED_RP2040_Manager.h index f54dec45..c858ced4 100644 --- a/src/Adapters/Ethernet_MBED_RP2040_Manager.h +++ b/src/Adapters/Ethernet_MBED_RP2040_Manager.h @@ -9,7 +9,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.7.2 + Version: 1.8.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -26,6 +26,7 @@ 1.7.0 K Hoang 27/11/2021 Auto detect ESP32 core to use correct LittleFS. Fix QNEthernet-related linkStatus. 1.7.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. 1.7.2 K Hoang 10/04/2022 Use Ethernet_Generic library as default. Support SPI1/SPI2 for RP2040/ESP32 + 1.8.0 K Hoang 07/09/2022 Fix macAddress bug. Add functions relating to macAddress *****************************************************************************************************************************/ #pragma once @@ -106,7 +107,7 @@ typedef struct ///NEW extern uint16_t NUM_MENU_ITEMS; extern MenuItem myMenuItems []; - bool *menuItemUpdated = NULL; + bool *menuItemUpdated = nullptr; #else #warning Not using Dynamic Parameters #endif @@ -494,7 +495,7 @@ class Ethernet_Manager #if USING_CUSTOMS_HEAD_ELEMENT //sets a custom element to add to head, like a new style tag - void setCustomsHeadElement(const char* CustomsHeadElement = NULL) + void setCustomsHeadElement(const char* CustomsHeadElement = nullptr) { _CustomsHeadElement = CustomsHeadElement; ETM_LOGDEBUG1(F("Set CustomsHeadElement to : "), _CustomsHeadElement); @@ -508,7 +509,7 @@ class Ethernet_Manager #endif #if USING_CORS_FEATURE - void setCORSHeader(const char* CORSHeaders = NULL) + void setCORSHeader(const char* CORSHeaders = nullptr) { _CORS_Header = CORSHeaders; @@ -522,6 +523,46 @@ class Ethernet_Manager } #endif + ////////////////////////////////////////////// + + uint8_t* getMacAddress() + { + return macAddress; + } + + ////////////////////////////////////////////// + + uint8_t* setMacAddress(const uint8_t* mac) + { + if ( isMacAddressValid(mac) ) + memcpy(macAddress, mac, sizeof(macAddress)); + + printMacAddress(); + + return macAddress; + } + + ////////////////////////////////////////////// + + void printMacAddress() + { + char theLocalBuffer[24]; + + snprintf(theLocalBuffer, sizeof(theLocalBuffer), "MAC:%02X-%02X-%02X-%02X-%02X-%02X", + macAddress[0], macAddress[1], + macAddress[2], macAddress[3], + macAddress[4], macAddress[5]); + + ETM_LOGWARN(theLocalBuffer); + } + + ////////////////////////////////////////////// + + bool isMacAddressValid(const uint8_t* mac) + { + return ( (mac != nullptr) && ( (mac[0] != 0) || (mac[1] != 0) || (mac[2] != 0) || (mac[3] != 0) ) ); + } + ////////////////////////////////////// @@ -549,17 +590,19 @@ class Ethernet_Manager uint16_t totalDataSize = 0; uint8_t currentBlynkServerIndex = 255; + + uint8_t macAddress[6] = { 0, 0, 0, 0, 0, 0 }; ///////////////////////////////////// // Add customs headers from v1.1.0 #if USING_CUSTOMS_STYLE - const char* ETM_HTML_HEAD_CUSTOMS_STYLE = NULL; + const char* ETM_HTML_HEAD_CUSTOMS_STYLE = nullptr; #endif #if USING_CUSTOMS_HEAD_ELEMENT - const char* _CustomsHeadElement = NULL; + const char* _CustomsHeadElement = nullptr; #endif #if USING_CORS_FEATURE @@ -643,7 +686,7 @@ class Ethernet_Manager int checkSum = 0; for (uint16_t index = 0; index < (sizeof(Ethernet_Manager_config) - sizeof(Ethernet_Manager_config.checkSum)); index++) { - checkSum += * ( ( (byte*) &Ethernet_Manager_config ) + index); + checkSum += * ( ( (uint8_t*) &Ethernet_Manager_config ) + index); } return checkSum; @@ -837,7 +880,7 @@ class Ethernet_Manager readBuffer = new char[ maxBufferLength + 1 ]; // check to see NULL => stop and return false - if (readBuffer == NULL) + if (readBuffer == nullptr) { ETM_LOGERROR(F("ChkCrR: Error can't allocate buffer.")); return false; @@ -1656,15 +1699,24 @@ class Ethernet_Manager // Use static IP ETM_LOGWARN1(F("Start connectEthernet using Static IP ="), staticIP); - Ethernet.begin(SelectMacAddress(NULL), staticIP); + // If macAddress valid, use it + if (isMacAddressValid(macAddress)) + Ethernet.begin(SelectMacAddress(macAddress), staticIP); + else + Ethernet.begin(SelectMacAddress(nullptr), staticIP); + ethernetConnected = true; } else { - // If static_IP ="nothing" or NULL, use DHCP dynamic IP + // If static_IP ="nothing" or nullptr, use DHCP dynamic IP ETM_LOGWARN(F("Start connectEthernet using DHCP")); - ethernetConnected = ( Ethernet.begin(SelectMacAddress(NULL)) == 1); + // If macAddress valid, use it + if (isMacAddressValid(macAddress)) + ethernetConnected = ( Ethernet.begin(SelectMacAddress(macAddress)) == 1); + else + ethernetConnected = ( Ethernet.begin(SelectMacAddress(nullptr)) == 1); } // give the Ethernet shield a second to initialize: @@ -1682,48 +1734,70 @@ class Ethernet_Manager return ethernetConnected; } - byte* SelectMacAddress(const byte mac[]) + /////////////////////////////////////////////////////////////////// + + uint8_t* SelectMacAddress(const uint8_t* mac) { - if (mac != NULL) + char localBuffer[24]; + + if (isMacAddressValid(mac)) { - return (byte*)mac; + return (uint8_t*)mac; } +#if USE_ETHERNET_GENERIC + Ethernet.MACAddress(macAddress); +#endif + + printMacAddress(); + + if (isMacAddressValid(macAddress)) + { + return macAddress; + } + + // Initial mac to manipulate from macAddress[0] = 0xFE; - macAddress[1] = 0xAB; - macAddress[2] = 0xCD; - macAddress[3] = 0xEF; - macAddress[4] = 0xED; - macAddress[5] = 0xBA; + macAddress[1] = 0xED; + macAddress[2] = 0xDE; + macAddress[3] = 0xAD; + macAddress[4] = 0xBE; + macAddress[5] = 0xEF; - const char* token = String(millis()).c_str(); +#define TOKEN_LEN 8 - int len = strlen(token); + char token[TOKEN_LEN]; + uint32_t curTime = millis(); + snprintf(token, sizeof(token), "%ld", curTime * curTime); + int mac_index = 1; - - for (uint16_t i = 0; i < len; i++) + + ETM_LOGDEBUG3("token =", token, ", len =", TOKEN_LEN); + + for (uint16_t i = 0; i < TOKEN_LEN; i++) { macAddress[mac_index] ^= token[i]; - if (++mac_index > 5) { + if (++mac_index > 5) + { mac_index = 1; } } - - char localBuffer[24]; - + snprintf(localBuffer, sizeof(localBuffer), "MAC:%02X-%02X-%02X-%02X-%02X-%02X", macAddress[0], macAddress[1], macAddress[2], macAddress[3], macAddress[4], macAddress[5]); - ETM_LOGWARN(localBuffer); + ETM_LOGWARN1(F("Calculated =>"), localBuffer); + +#if USE_ETHERNET_GENERIC + // Set for later use + Ethernet.setMACAddress(macAddress); +#endif return macAddress; } - - byte macAddress[6]; - }; #endif // Ethernet_RP2040_Manager_h diff --git a/src/Adapters/Ethernet_NRF52_Manager.h b/src/Adapters/Ethernet_NRF52_Manager.h index 0b1e3132..ba92ea76 100644 --- a/src/Adapters/Ethernet_NRF52_Manager.h +++ b/src/Adapters/Ethernet_NRF52_Manager.h @@ -9,7 +9,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.7.2 + Version: 1.8.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -26,6 +26,7 @@ 1.7.0 K Hoang 27/11/2021 Auto detect ESP32 core to use correct LittleFS. Fix QNEthernet-related linkStatus. 1.7.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. 1.7.2 K Hoang 10/04/2022 Use Ethernet_Generic library as default. Support SPI1/SPI2 for RP2040/ESP32 + 1.8.0 K Hoang 07/09/2022 Fix macAddress bug. Add functions relating to macAddress *****************************************************************************************************************************/ #pragma once @@ -110,7 +111,7 @@ typedef struct ///NEW extern uint16_t NUM_MENU_ITEMS; extern MenuItem myMenuItems []; - bool *menuItemUpdated = NULL; + bool *menuItemUpdated = nullptr; #else #warning Not using Dynamic Parameters #endif @@ -457,7 +458,7 @@ class Ethernet_Manager #if USING_CUSTOMS_HEAD_ELEMENT //sets a custom element to add to head, like a new style tag - void setCustomsHeadElement(const char* CustomsHeadElement = NULL) + void setCustomsHeadElement(const char* CustomsHeadElement = nullptr) { _CustomsHeadElement = CustomsHeadElement; ETM_LOGDEBUG1(F("Set CustomsHeadElement to : "), _CustomsHeadElement); @@ -471,7 +472,7 @@ class Ethernet_Manager #endif #if USING_CORS_FEATURE - void setCORSHeader(const char* CORSHeaders = NULL) + void setCORSHeader(const char* CORSHeaders = nullptr) { _CORS_Header = CORSHeaders; @@ -485,6 +486,46 @@ class Ethernet_Manager } #endif + ////////////////////////////////////////////// + + uint8_t* getMacAddress() + { + return macAddress; + } + + ////////////////////////////////////////////// + + uint8_t* setMacAddress(const uint8_t* mac) + { + if ( isMacAddressValid(mac) ) + memcpy(macAddress, mac, sizeof(macAddress)); + + printMacAddress(); + + return macAddress; + } + + ////////////////////////////////////////////// + + void printMacAddress() + { + char theLocalBuffer[24]; + + snprintf(theLocalBuffer, sizeof(theLocalBuffer), "MAC:%02X-%02X-%02X-%02X-%02X-%02X", + macAddress[0], macAddress[1], + macAddress[2], macAddress[3], + macAddress[4], macAddress[5]); + + ETM_LOGWARN(theLocalBuffer); + } + + ////////////////////////////////////////////// + + bool isMacAddressValid(const uint8_t* mac) + { + return ( (mac != nullptr) && ( (mac[0] != 0) || (mac[1] != 0) || (mac[2] != 0) || (mac[3] != 0) ) ); + } + ////////////////////////////////////// @@ -512,17 +553,19 @@ class Ethernet_Manager uint16_t totalDataSize = 0; uint8_t currentBlynkServerIndex = 255; + + uint8_t macAddress[6] = { 0, 0, 0, 0, 0, 0 }; ///////////////////////////////////// // Add customs headers from v1.1.0 #if USING_CUSTOMS_STYLE - const char* ETM_HTML_HEAD_CUSTOMS_STYLE = NULL; + const char* ETM_HTML_HEAD_CUSTOMS_STYLE = nullptr; #endif #if USING_CUSTOMS_HEAD_ELEMENT - const char* _CustomsHeadElement = NULL; + const char* _CustomsHeadElement = nullptr; #endif #if USING_CORS_FEATURE @@ -606,7 +649,7 @@ class Ethernet_Manager int checkSum = 0; for (uint16_t index = 0; index < (sizeof(Ethernet_Manager_config) - sizeof(Ethernet_Manager_config.checkSum)); index++) { - checkSum += * ( ( (byte*) &Ethernet_Manager_config ) + index); + checkSum += * ( ( (uint8_t*) &Ethernet_Manager_config ) + index); } return checkSum; @@ -786,7 +829,7 @@ class Ethernet_Manager readBuffer = new char[ maxBufferLength + 1 ]; // check to see NULL => stop and return false - if (readBuffer == NULL) + if (readBuffer == nullptr) { ETM_LOGERROR(F("ChkCrR: Error can't allocate buffer.")); return false; @@ -1555,15 +1598,24 @@ class Ethernet_Manager // Use static IP ETM_LOGWARN1(F("Start connectEthernet using Static IP ="), staticIP); - Ethernet.begin(SelectMacAddress(NULL), staticIP); + // If macAddress valid, use it + if (isMacAddressValid(macAddress)) + Ethernet.begin(SelectMacAddress(macAddress), staticIP); + else + Ethernet.begin(SelectMacAddress(nullptr), staticIP); + ethernetConnected = true; } else { - // If static_IP ="nothing" or NULL, use DHCP dynamic IP + // If static_IP ="nothing" or nullptr, use DHCP dynamic IP ETM_LOGWARN(F("Start connectEthernet using DHCP")); - ethernetConnected = ( Ethernet.begin(SelectMacAddress(NULL)) == 1); + // If macAddress valid, use it + if (isMacAddressValid(macAddress)) + ethernetConnected = ( Ethernet.begin(SelectMacAddress(macAddress)) == 1); + else + ethernetConnected = ( Ethernet.begin(SelectMacAddress(nullptr)) == 1); } // give the Ethernet shield a second to initialize: @@ -1581,48 +1633,70 @@ class Ethernet_Manager return ethernetConnected; } - byte* SelectMacAddress(const byte mac[]) + /////////////////////////////////////////////////////////////////// + + uint8_t* SelectMacAddress(const uint8_t* mac) { - if (mac != NULL) + char localBuffer[24]; + + if (isMacAddressValid(mac)) { - return (byte*)mac; + return (uint8_t*)mac; } +#if USE_ETHERNET_GENERIC + Ethernet.MACAddress(macAddress); +#endif + + printMacAddress(); + + if (isMacAddressValid(macAddress)) + { + return macAddress; + } + + // Initial mac to manipulate from macAddress[0] = 0xFE; - macAddress[1] = 0xAB; - macAddress[2] = 0xCD; - macAddress[3] = 0xEF; - macAddress[4] = 0xED; - macAddress[5] = 0xBA; + macAddress[1] = 0xED; + macAddress[2] = 0xDE; + macAddress[3] = 0xAD; + macAddress[4] = 0xBE; + macAddress[5] = 0xEF; - const char* token = String(millis()).c_str(); +#define TOKEN_LEN 8 - int len = strlen(token); + char token[TOKEN_LEN]; + uint32_t curTime = millis(); + snprintf(token, sizeof(token), "%ld", curTime * curTime); + int mac_index = 1; - - for (uint16_t i = 0; i < len; i++) + + ETM_LOGDEBUG3("token =", token, ", len =", TOKEN_LEN); + + for (uint16_t i = 0; i < TOKEN_LEN; i++) { macAddress[mac_index] ^= token[i]; - if (++mac_index > 5) { + if (++mac_index > 5) + { mac_index = 1; } } - - char localBuffer[24]; - + snprintf(localBuffer, sizeof(localBuffer), "MAC:%02X-%02X-%02X-%02X-%02X-%02X", macAddress[0], macAddress[1], macAddress[2], macAddress[3], macAddress[4], macAddress[5]); - ETM_LOGWARN(localBuffer); + ETM_LOGWARN1(F("Calculated =>"), localBuffer); + +#if USE_ETHERNET_GENERIC + // Set for later use + Ethernet.setMACAddress(macAddress); +#endif return macAddress; } - - byte macAddress[6]; - }; #endif // Ethernet_NRF52_Manager_h diff --git a/src/Adapters/Ethernet_RP2040_Manager.h b/src/Adapters/Ethernet_RP2040_Manager.h index ae807af1..eb340890 100644 --- a/src/Adapters/Ethernet_RP2040_Manager.h +++ b/src/Adapters/Ethernet_RP2040_Manager.h @@ -9,7 +9,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.7.2 + Version: 1.8.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -26,6 +26,7 @@ 1.7.0 K Hoang 27/11/2021 Auto detect ESP32 core to use correct LittleFS. Fix QNEthernet-related linkStatus. 1.7.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. 1.7.2 K Hoang 10/04/2022 Use Ethernet_Generic library as default. Support SPI1/SPI2 for RP2040/ESP32 + 1.8.0 K Hoang 07/09/2022 Fix macAddress bug. Add functions relating to macAddress *****************************************************************************************************************************/ #pragma once @@ -117,7 +118,7 @@ typedef struct ///NEW extern uint16_t NUM_MENU_ITEMS; extern MenuItem myMenuItems []; - bool *menuItemUpdated = NULL; + bool *menuItemUpdated = nullptr; #else #warning Not using Dynamic Parameters #endif @@ -505,7 +506,7 @@ class Ethernet_Manager #if USING_CUSTOMS_HEAD_ELEMENT //sets a custom element to add to head, like a new style tag - void setCustomsHeadElement(const char* CustomsHeadElement = NULL) + void setCustomsHeadElement(const char* CustomsHeadElement = nullptr) { _CustomsHeadElement = CustomsHeadElement; ETM_LOGDEBUG1(F("Set CustomsHeadElement to : "), _CustomsHeadElement); @@ -519,7 +520,7 @@ class Ethernet_Manager #endif #if USING_CORS_FEATURE - void setCORSHeader(const char* CORSHeaders = NULL) + void setCORSHeader(const char* CORSHeaders = nullptr) { _CORS_Header = CORSHeaders; @@ -533,6 +534,46 @@ class Ethernet_Manager } #endif + ////////////////////////////////////////////// + + uint8_t* getMacAddress() + { + return macAddress; + } + + ////////////////////////////////////////////// + + uint8_t* setMacAddress(const uint8_t* mac) + { + if ( isMacAddressValid(mac) ) + memcpy(macAddress, mac, sizeof(macAddress)); + + printMacAddress(); + + return macAddress; + } + + ////////////////////////////////////////////// + + void printMacAddress() + { + char theLocalBuffer[24]; + + snprintf(theLocalBuffer, sizeof(theLocalBuffer), "MAC:%02X-%02X-%02X-%02X-%02X-%02X", + macAddress[0], macAddress[1], + macAddress[2], macAddress[3], + macAddress[4], macAddress[5]); + + ETM_LOGWARN(theLocalBuffer); + } + + ////////////////////////////////////////////// + + bool isMacAddressValid(const uint8_t* mac) + { + return ( (mac != nullptr) && ( (mac[0] != 0) || (mac[1] != 0) || (mac[2] != 0) || (mac[3] != 0) ) ); + } + ////////////////////////////////////// @@ -560,17 +601,19 @@ class Ethernet_Manager uint16_t totalDataSize = 0; uint8_t currentBlynkServerIndex = 255; + + uint8_t macAddress[6] = { 0, 0, 0, 0, 0, 0 }; ///////////////////////////////////// // Add customs headers from v1.1.0 #if USING_CUSTOMS_STYLE - const char* ETM_HTML_HEAD_CUSTOMS_STYLE = NULL; + const char* ETM_HTML_HEAD_CUSTOMS_STYLE = nullptr; #endif #if USING_CUSTOMS_HEAD_ELEMENT - const char* _CustomsHeadElement = NULL; + const char* _CustomsHeadElement = nullptr; #endif #if USING_CORS_FEATURE @@ -654,7 +697,7 @@ class Ethernet_Manager int checkSum = 0; for (uint16_t index = 0; index < (sizeof(Ethernet_Manager_config) - sizeof(Ethernet_Manager_config.checkSum)); index++) { - checkSum += * ( ( (byte*) &Ethernet_Manager_config ) + index); + checkSum += * ( ( (uint8_t*) &Ethernet_Manager_config ) + index); } return checkSum; @@ -791,7 +834,7 @@ class Ethernet_Manager { int checkSum = 0; int readCheckSum; - char* readBuffer = NULL; + char* readBuffer = nullptr; File file = FileFS.open(CREDENTIALS_FILENAME, "r"); @@ -830,7 +873,7 @@ class Ethernet_Manager readBuffer = new char[ maxBufferLength + 1 ]; // check to see NULL => stop and return false - if (readBuffer == NULL) + if (readBuffer == nullptr) { ETM_LOGERROR(F("ChkCrR: Error can't allocate buffer.")); return false; @@ -1603,15 +1646,24 @@ class Ethernet_Manager // Use static IP ETM_LOGWARN1(F("Start connectEthernet using Static IP ="), staticIP); - Ethernet.begin(SelectMacAddress(NULL), staticIP); + // If macAddress valid, use it + if (isMacAddressValid(macAddress)) + Ethernet.begin(SelectMacAddress(macAddress), staticIP); + else + Ethernet.begin(SelectMacAddress(nullptr), staticIP); + ethernetConnected = true; } else { - // If static_IP ="nothing" or NULL, use DHCP dynamic IP + // If static_IP ="nothing" or nullptr, use DHCP dynamic IP ETM_LOGWARN(F("Start connectEthernet using DHCP")); - ethernetConnected = ( Ethernet.begin(SelectMacAddress(NULL)) == 1); + // If macAddress valid, use it + if (isMacAddressValid(macAddress)) + ethernetConnected = ( Ethernet.begin(SelectMacAddress(macAddress)) == 1); + else + ethernetConnected = ( Ethernet.begin(SelectMacAddress(nullptr)) == 1); } // give the Ethernet shield a second to initialize: @@ -1629,48 +1681,70 @@ class Ethernet_Manager return ethernetConnected; } - byte* SelectMacAddress(const byte mac[]) + /////////////////////////////////////////////////////////////////// + + uint8_t* SelectMacAddress(const uint8_t* mac) { - if (mac != NULL) + char localBuffer[24]; + + if (isMacAddressValid(mac)) { - return (byte*)mac; + return (uint8_t*)mac; } +#if USE_ETHERNET_GENERIC + Ethernet.MACAddress(macAddress); +#endif + + printMacAddress(); + + if (isMacAddressValid(macAddress)) + { + return macAddress; + } + + // Initial mac to manipulate from macAddress[0] = 0xFE; - macAddress[1] = 0xAB; - macAddress[2] = 0xCD; - macAddress[3] = 0xEF; - macAddress[4] = 0xED; - macAddress[5] = 0xBA; + macAddress[1] = 0xED; + macAddress[2] = 0xDE; + macAddress[3] = 0xAD; + macAddress[4] = 0xBE; + macAddress[5] = 0xEF; - const char* token = String(millis()).c_str(); +#define TOKEN_LEN 8 - int len = strlen(token); + char token[TOKEN_LEN]; + uint32_t curTime = millis(); + snprintf(token, sizeof(token), "%ld", curTime * curTime); + int mac_index = 1; - - for (uint16_t i = 0; i < len; i++) + + ETM_LOGDEBUG3("token =", token, ", len =", TOKEN_LEN); + + for (uint16_t i = 0; i < TOKEN_LEN; i++) { macAddress[mac_index] ^= token[i]; - if (++mac_index > 5) { + if (++mac_index > 5) + { mac_index = 1; } } - - char localBuffer[24]; - + snprintf(localBuffer, sizeof(localBuffer), "MAC:%02X-%02X-%02X-%02X-%02X-%02X", macAddress[0], macAddress[1], macAddress[2], macAddress[3], macAddress[4], macAddress[5]); - ETM_LOGWARN(localBuffer); + ETM_LOGWARN1(F("Calculated =>"), localBuffer); + +#if USE_ETHERNET_GENERIC + // Set for later use + Ethernet.setMACAddress(macAddress); +#endif return macAddress; } - - byte macAddress[6]; - }; #endif // Ethernet_RP2040_Manager_h diff --git a/src/Adapters/Ethernet_SAMD_Manager.h b/src/Adapters/Ethernet_SAMD_Manager.h index ef2a298d..8506fcca 100644 --- a/src/Adapters/Ethernet_SAMD_Manager.h +++ b/src/Adapters/Ethernet_SAMD_Manager.h @@ -9,7 +9,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.7.2 + Version: 1.8.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -26,6 +26,7 @@ 1.7.0 K Hoang 27/11/2021 Auto detect ESP32 core to use correct LittleFS. Fix QNEthernet-related linkStatus. 1.7.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. 1.7.2 K Hoang 10/04/2022 Use Ethernet_Generic library as default. Support SPI1/SPI2 for RP2040/ESP32 + 1.8.0 K Hoang 07/09/2022 Fix macAddress bug. Add functions relating to macAddress *****************************************************************************************************************************/ #pragma once @@ -111,7 +112,7 @@ typedef struct ///NEW extern uint16_t NUM_MENU_ITEMS; extern MenuItem myMenuItems []; - bool *menuItemUpdated = NULL; + bool *menuItemUpdated = nullptr; #else #warning Not using Dynamic Parameters #endif @@ -479,7 +480,7 @@ class Ethernet_Manager #if USING_CUSTOMS_HEAD_ELEMENT //sets a custom element to add to head, like a new style tag - void setCustomsHeadElement(const char* CustomsHeadElement = NULL) + void setCustomsHeadElement(const char* CustomsHeadElement = nullptr) { _CustomsHeadElement = CustomsHeadElement; ETM_LOGDEBUG1(F("Set CustomsHeadElement to : "), _CustomsHeadElement); @@ -493,7 +494,7 @@ class Ethernet_Manager #endif #if USING_CORS_FEATURE - void setCORSHeader(const char* CORSHeaders = NULL) + void setCORSHeader(const char* CORSHeaders = nullptr) { _CORS_Header = CORSHeaders; @@ -507,6 +508,46 @@ class Ethernet_Manager } #endif + ////////////////////////////////////////////// + + uint8_t* getMacAddress() + { + return macAddress; + } + + ////////////////////////////////////////////// + + uint8_t* setMacAddress(const uint8_t* mac) + { + if ( isMacAddressValid(mac) ) + memcpy(macAddress, mac, sizeof(macAddress)); + + printMacAddress(); + + return macAddress; + } + + ////////////////////////////////////////////// + + void printMacAddress() + { + char theLocalBuffer[24]; + + snprintf(theLocalBuffer, sizeof(theLocalBuffer), "MAC:%02X-%02X-%02X-%02X-%02X-%02X", + macAddress[0], macAddress[1], + macAddress[2], macAddress[3], + macAddress[4], macAddress[5]); + + ETM_LOGWARN(theLocalBuffer); + } + + ////////////////////////////////////////////// + + bool isMacAddressValid(const uint8_t* mac) + { + return ( (mac != nullptr) && ( (mac[0] != 0) || (mac[1] != 0) || (mac[2] != 0) || (mac[3] != 0) ) ); + } + ////////////////////////////////////// @@ -534,17 +575,19 @@ class Ethernet_Manager uint16_t totalDataSize = 0; uint8_t currentBlynkServerIndex = 255; + + uint8_t macAddress[6] = { 0, 0, 0, 0, 0, 0 }; ///////////////////////////////////// // Add customs headers from v1.1.0 #if USING_CUSTOMS_STYLE - const char* ETM_HTML_HEAD_CUSTOMS_STYLE = NULL; + const char* ETM_HTML_HEAD_CUSTOMS_STYLE = nullptr; #endif #if USING_CUSTOMS_HEAD_ELEMENT - const char* _CustomsHeadElement = NULL; + const char* _CustomsHeadElement = nullptr; #endif #if USING_CORS_FEATURE @@ -646,7 +689,7 @@ class Ethernet_Manager int checkSum = 0; for (uint16_t index = 0; index < (sizeof(Ethernet_Manager_config) - sizeof(Ethernet_Manager_config.checkSum)); index++) { - checkSum += * ( ( (byte*) &Ethernet_Manager_config ) + index); + checkSum += * ( ( (uint8_t*) &Ethernet_Manager_config ) + index); } return checkSum; @@ -707,7 +750,7 @@ class Ethernet_Manager bool checkDynamicData() { // It's too bad that emulate EEPROM.read()/write() can only deal with bytes. - // Have to read/write each byte. To rewrite the library + // Have to read/write each uint8_t. To rewrite the library int checkSum = 0; int readCheckSum; @@ -812,7 +855,7 @@ class Ethernet_Manager void EEPROM_putDynamicData() { // It's too bad that emulate EEPROM.read()/writ() can only deal with bytes. - // Have to read/write each byte. To rewrite the library + // Have to read/write each uint8_t. To rewrite the library int checkSum = 0; // Using FORCED_CONFIG_PORTAL_FLAG_DATA @@ -1341,15 +1384,24 @@ class Ethernet_Manager // Use static IP ETM_LOGWARN1(F("Start connectEthernet using Static IP ="), staticIP); - Ethernet.begin(SelectMacAddress(NULL), staticIP); + // If macAddress valid, use it + if (isMacAddressValid(macAddress)) + Ethernet.begin(SelectMacAddress(macAddress), staticIP); + else + Ethernet.begin(SelectMacAddress(nullptr), staticIP); + ethernetConnected = true; } else { - // If static_IP ="nothing" or NULL, use DHCP dynamic IP + // If static_IP ="nothing" or nullptr, use DHCP dynamic IP ETM_LOGWARN(F("Start connectEthernet using DHCP")); - ethernetConnected = ( Ethernet.begin(SelectMacAddress(NULL)) == 1); + // If macAddress valid, use it + if (isMacAddressValid(macAddress)) + ethernetConnected = ( Ethernet.begin(SelectMacAddress(macAddress)) == 1); + else + ethernetConnected = ( Ethernet.begin(SelectMacAddress(nullptr)) == 1); } // give the Ethernet shield a second to initialize: @@ -1367,48 +1419,70 @@ class Ethernet_Manager return ethernetConnected; } - byte* SelectMacAddress(const byte mac[]) + /////////////////////////////////////////////////////////////////// + + uint8_t* SelectMacAddress(const uint8_t* mac) { - if (mac != NULL) + char localBuffer[24]; + + if (isMacAddressValid(mac)) { - return (byte*)mac; + return (uint8_t*)mac; } +#if USE_ETHERNET_GENERIC + Ethernet.MACAddress(macAddress); +#endif + + printMacAddress(); + + if (isMacAddressValid(macAddress)) + { + return macAddress; + } + + // Initial mac to manipulate from macAddress[0] = 0xFE; - macAddress[1] = 0xAB; - macAddress[2] = 0xCD; - macAddress[3] = 0xEF; - macAddress[4] = 0xED; - macAddress[5] = 0xBA; + macAddress[1] = 0xED; + macAddress[2] = 0xDE; + macAddress[3] = 0xAD; + macAddress[4] = 0xBE; + macAddress[5] = 0xEF; - const char* token = String(millis()).c_str(); +#define TOKEN_LEN 8 - int len = strlen(token); + char token[TOKEN_LEN]; + uint32_t curTime = millis(); + snprintf(token, sizeof(token), "%ld", curTime * curTime); + int mac_index = 1; - - for (uint16_t i = 0; i < len; i++) + + ETM_LOGDEBUG3("token =", token, ", len =", TOKEN_LEN); + + for (uint16_t i = 0; i < TOKEN_LEN; i++) { macAddress[mac_index] ^= token[i]; - if (++mac_index > 5) { + if (++mac_index > 5) + { mac_index = 1; } } - - char localBuffer[24]; - + snprintf(localBuffer, sizeof(localBuffer), "MAC:%02X-%02X-%02X-%02X-%02X-%02X", macAddress[0], macAddress[1], macAddress[2], macAddress[3], macAddress[4], macAddress[5]); - ETM_LOGWARN(localBuffer); + ETM_LOGWARN1(F("Calculated =>"), localBuffer); + +#if USE_ETHERNET_GENERIC + // Set for later use + Ethernet.setMACAddress(macAddress); +#endif return macAddress; } - - byte macAddress[6]; - }; #endif // Ethernet_SAMD_Manager_h diff --git a/src/Adapters/Ethernet_Teensy_Manager.h b/src/Adapters/Ethernet_Teensy_Manager.h index a6fb7833..74c7a2b7 100644 --- a/src/Adapters/Ethernet_Teensy_Manager.h +++ b/src/Adapters/Ethernet_Teensy_Manager.h @@ -9,7 +9,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.7.2 + Version: 1.8.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -26,6 +26,7 @@ 1.7.0 K Hoang 27/11/2021 Auto detect ESP32 core to use correct LittleFS. Fix QNEthernet-related linkStatus. 1.7.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. 1.7.2 K Hoang 10/04/2022 Use Ethernet_Generic library as default. Support SPI1/SPI2 for RP2040/ESP32 + 1.8.0 K Hoang 07/09/2022 Fix macAddress bug. Add functions relating to macAddress *****************************************************************************************************************************/ #pragma once @@ -105,7 +106,7 @@ typedef struct ///NEW extern uint16_t NUM_MENU_ITEMS; extern MenuItem myMenuItems []; - bool *menuItemUpdated = NULL; + bool *menuItemUpdated = nullptr; #else #warning Not using Dynamic Parameters #endif @@ -456,7 +457,7 @@ class Ethernet_Manager #if USING_CUSTOMS_HEAD_ELEMENT //sets a custom element to add to head, like a new style tag - void setCustomsHeadElement(const char* CustomsHeadElement = NULL) + void setCustomsHeadElement(const char* CustomsHeadElement = nullptr) { _CustomsHeadElement = CustomsHeadElement; ETM_LOGDEBUG1(F("Set CustomsHeadElement to : "), _CustomsHeadElement); @@ -470,7 +471,7 @@ class Ethernet_Manager #endif #if USING_CORS_FEATURE - void setCORSHeader(const char* CORSHeaders = NULL) + void setCORSHeader(const char* CORSHeaders = nullptr) { _CORS_Header = CORSHeaders; @@ -484,6 +485,46 @@ class Ethernet_Manager } #endif + ////////////////////////////////////////////// + + uint8_t* getMacAddress() + { + return macAddress; + } + + ////////////////////////////////////////////// + + uint8_t* setMacAddress(const uint8_t* mac) + { + if ( isMacAddressValid(mac) ) + memcpy(macAddress, mac, sizeof(macAddress)); + + printMacAddress(); + + return macAddress; + } + + ////////////////////////////////////////////// + + void printMacAddress() + { + char theLocalBuffer[24]; + + snprintf(theLocalBuffer, sizeof(theLocalBuffer), "MAC:%02X-%02X-%02X-%02X-%02X-%02X", + macAddress[0], macAddress[1], + macAddress[2], macAddress[3], + macAddress[4], macAddress[5]); + + ETM_LOGWARN(theLocalBuffer); + } + + ////////////////////////////////////////////// + + bool isMacAddressValid(const uint8_t* mac) + { + return ( (mac != nullptr) && ( (mac[0] != 0) || (mac[1] != 0) || (mac[2] != 0) || (mac[3] != 0) ) ); + } + ////////////////////////////////////// @@ -511,17 +552,19 @@ class Ethernet_Manager uint16_t totalDataSize = 0; uint8_t currentBlynkServerIndex = 255; + + uint8_t macAddress[6] = { 0, 0, 0, 0, 0, 0 }; ///////////////////////////////////// // Add customs headers from v1.1.0 #if USING_CUSTOMS_STYLE - const char* ETM_HTML_HEAD_CUSTOMS_STYLE = NULL; + const char* ETM_HTML_HEAD_CUSTOMS_STYLE = nullptr; #endif #if USING_CUSTOMS_HEAD_ELEMENT - const char* _CustomsHeadElement = NULL; + const char* _CustomsHeadElement = nullptr; #endif #if USING_CORS_FEATURE @@ -669,7 +712,7 @@ class Ethernet_Manager int checkSum = 0; for (uint16_t index = 0; index < (sizeof(Ethernet_Manager_config) - sizeof(Ethernet_Manager_config.checkSum)); index++) { - checkSum += * ( ( (byte*) &Ethernet_Manager_config ) + index); + checkSum += * ( ( (uint8_t*) &Ethernet_Manager_config ) + index); } return checkSum; @@ -1363,15 +1406,24 @@ class Ethernet_Manager // Use static IP ETM_LOGWARN1(F("Start connectEthernet using Static IP ="), staticIP); - Ethernet.begin(SelectMacAddress(NULL), staticIP); + // If macAddress valid, use it + if (isMacAddressValid(macAddress)) + Ethernet.begin(SelectMacAddress(macAddress), staticIP); + else + Ethernet.begin(SelectMacAddress(nullptr), staticIP); + ethernetConnected = true; } else { - // If static_IP ="nothing" or NULL, use DHCP dynamic IP + // If static_IP ="nothing" or nullptr, use DHCP dynamic IP ETM_LOGWARN(F("Start connectEthernet using DHCP")); - ethernetConnected = ( Ethernet.begin(SelectMacAddress(NULL)) == 1); + // If macAddress valid, use it + if (isMacAddressValid(macAddress)) + ethernetConnected = ( Ethernet.begin(SelectMacAddress(macAddress)) == 1); + else + ethernetConnected = ( Ethernet.begin(SelectMacAddress(nullptr)) == 1); } // give the Ethernet shield a second to initialize: @@ -1389,48 +1441,70 @@ class Ethernet_Manager return ethernetConnected; } - byte* SelectMacAddress(const byte mac[]) + /////////////////////////////////////////////////////////////////// + + uint8_t* SelectMacAddress(const uint8_t* mac) { - if (mac != NULL) + char localBuffer[24]; + + if (isMacAddressValid(mac)) { - return (byte*)mac; + return (uint8_t*)mac; } +#if USE_ETHERNET_GENERIC + Ethernet.MACAddress(macAddress); +#endif + + printMacAddress(); + + if (isMacAddressValid(macAddress)) + { + return macAddress; + } + + // Initial mac to manipulate from macAddress[0] = 0xFE; - macAddress[1] = 0xAB; - macAddress[2] = 0xCD; - macAddress[3] = 0xEF; - macAddress[4] = 0xED; - macAddress[5] = 0xBA; + macAddress[1] = 0xED; + macAddress[2] = 0xDE; + macAddress[3] = 0xAD; + macAddress[4] = 0xBE; + macAddress[5] = 0xEF; - const char* token = String(millis()).c_str(); +#define TOKEN_LEN 8 - int len = strlen(token); + char token[TOKEN_LEN]; + uint32_t curTime = millis(); + snprintf(token, sizeof(token), "%ld", curTime * curTime); + int mac_index = 1; - - for (uint16_t i = 0; i < len; i++) + + ETM_LOGDEBUG3("token =", token, ", len =", TOKEN_LEN); + + for (uint16_t i = 0; i < TOKEN_LEN; i++) { macAddress[mac_index] ^= token[i]; - if (++mac_index > 5) { + if (++mac_index > 5) + { mac_index = 1; } } - - char localBuffer[24]; - + snprintf(localBuffer, sizeof(localBuffer), "MAC:%02X-%02X-%02X-%02X-%02X-%02X", macAddress[0], macAddress[1], macAddress[2], macAddress[3], macAddress[4], macAddress[5]); - ETM_LOGWARN(localBuffer); + ETM_LOGWARN1(F("Calculated =>"), localBuffer); + +#if USE_ETHERNET_GENERIC + // Set for later use + Ethernet.setMACAddress(macAddress); +#endif return macAddress; } - - byte macAddress[6]; - }; #endif // Ethernet_Teensy_Manager_h diff --git a/src/Adapters/Ethernet_WT32_ETH01_Manager.h b/src/Adapters/Ethernet_WT32_ETH01_Manager.h index 12eb75ce..898770df 100644 --- a/src/Adapters/Ethernet_WT32_ETH01_Manager.h +++ b/src/Adapters/Ethernet_WT32_ETH01_Manager.h @@ -9,7 +9,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.7.2 + Version: 1.8.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -26,6 +26,7 @@ 1.7.0 K Hoang 27/11/2021 Auto detect ESP32 core to use correct LittleFS. Fix QNEthernet-related linkStatus. 1.7.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. 1.7.2 K Hoang 10/04/2022 Use Ethernet_Generic library as default. Support SPI1/SPI2 for RP2040/ESP32 + 1.8.0 K Hoang 07/09/2022 Fix macAddress bug. Add functions relating to macAddress *****************************************************************************************************************************/ #pragma once @@ -156,7 +157,7 @@ typedef struct ///NEW extern uint16_t NUM_MENU_ITEMS; extern MenuItem myMenuItems []; - bool *menuItemUpdated = NULL; + bool *menuItemUpdated = nullptr; #else #warning Not using Dynamic Parameters #endif @@ -479,7 +480,7 @@ class Ethernet_Manager #if USING_CUSTOMS_HEAD_ELEMENT //sets a custom element to add to head, like a new style tag - void setCustomsHeadElement(const char* CustomsHeadElement = NULL) + void setCustomsHeadElement(const char* CustomsHeadElement = nullptr) { _CustomsHeadElement = CustomsHeadElement; ETM_LOGDEBUG1(F("Set CustomsHeadElement to : "), _CustomsHeadElement); @@ -493,7 +494,7 @@ class Ethernet_Manager #endif #if USING_CORS_FEATURE - void setCORSHeader(const char* CORSHeaders = NULL) + void setCORSHeader(const char* CORSHeaders = nullptr) { _CORS_Header = CORSHeaders; @@ -511,8 +512,60 @@ class Ethernet_Manager public: - bool ethernetConnected = false; + //bool ethernetConnected = false; + + ////////////////////////////////////////////// + + uint8_t* getMacAddress() + { + return macAddress; + } + + ////////////////////////////////////////////// + + void printMacAddress() + { + char theLocalBuffer[24]; + + snprintf(theLocalBuffer, sizeof(theLocalBuffer), "MAC:%02X-%02X-%02X-%02X-%02X-%02X", + macAddress[0], macAddress[1], + macAddress[2], macAddress[3], + macAddress[4], macAddress[5]); + + ETM_LOGWARN(theLocalBuffer); + } + + ////////////////////////////////////////////// + + bool isMacAddressValid(const uint8_t* mac) + { + return ( (mac != nullptr) && ( (mac[0] != 0) || (mac[1] != 0) || (mac[2] != 0) || (mac[3] != 0) ) ); + } + + ////////////////////////////////////////////// + + bool isEthernetConnected() + { + return (ethernetConnected == true); + } + ////////////////////////////////////////////// + + void setEthernetConnected() + { + ethernetConnected = true; + } + + ////////////////////////////////////////////// + + void setEthernetDisconnected() + { + ethernetConnected = false; + } + + ////////////////////////////////////// + + private: // Initialize the Ethernet server library @@ -521,7 +574,7 @@ class Ethernet_Manager //EthernetWebServer *server; WebServer *server; - //bool ethernetConnected = false; + bool ethernetConnected = false; //static bool ethernetConnected = false; //static bool ethernetConnected; @@ -540,17 +593,19 @@ class Ethernet_Manager uint16_t totalDataSize = 0; uint8_t currentBlynkServerIndex = 255; + + uint8_t macAddress[6] = { 0, 0, 0, 0, 0, 0 }; ///////////////////////////////////// // Add customs headers from v1.1.0 #if USING_CUSTOMS_STYLE - const char* ETM_HTML_HEAD_CUSTOMS_STYLE = NULL; + const char* ETM_HTML_HEAD_CUSTOMS_STYLE = nullptr; #endif #if USING_CUSTOMS_HEAD_ELEMENT - const char* _CustomsHeadElement = NULL; + const char* _CustomsHeadElement = nullptr; #endif #if USING_CORS_FEATURE @@ -635,7 +690,7 @@ class Ethernet_Manager int checkSum = 0; for (uint16_t index = 0; index < (sizeof(Ethernet_Manager_config) - sizeof(Ethernet_Manager_config.checkSum)); index++) { - checkSum += * ( ( (byte*) &Ethernet_Manager_config ) + index); + checkSum += * ( ( (uint8_t*) &Ethernet_Manager_config ) + index); } return checkSum; @@ -803,7 +858,7 @@ class Ethernet_Manager readBuffer = new char[ maxBufferLength + 1 ]; // check to see NULL => stop and return false - if (readBuffer == NULL) + if (readBuffer == nullptr) { ETM_LOGERROR(F("ChkCrR: Error can't allocate buffer.")); return false; @@ -1951,7 +2006,7 @@ class Ethernet_Manager } else { - // If static_IP ="nothing" or NULL, use DHCP dynamic IP + // If static_IP ="nothing" or nullptr, use DHCP dynamic IP ETM_LOGWARN(F("Start connectEthernet using DHCP")); //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, @@ -1970,6 +2025,9 @@ class Ethernet_Manager { ETM_LOGWARN1(F("IP:"), ETH.localIP()); } + + // KH new. Get mac and store + ETH.macAddress(macAddress); return ethernetConnected; } diff --git a/src/Adapters/QNEthernet_Teensy_Manager.h b/src/Adapters/QNEthernet_Teensy_Manager.h index a1f93622..b9288abc 100644 --- a/src/Adapters/QNEthernet_Teensy_Manager.h +++ b/src/Adapters/QNEthernet_Teensy_Manager.h @@ -9,7 +9,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.7.2 + Version: 1.8.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -26,6 +26,7 @@ 1.7.0 K Hoang 27/11/2021 Auto detect ESP32 core to use correct LittleFS. Fix QNEthernet-related linkStatus. 1.7.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. 1.7.2 K Hoang 10/04/2022 Use Ethernet_Generic library as default. Support SPI1/SPI2 for RP2040/ESP32 + 1.8.0 K Hoang 07/09/2022 Fix macAddress bug. Add functions relating to macAddress *****************************************************************************************************************************/ #pragma once @@ -104,7 +105,7 @@ typedef struct ///NEW extern uint16_t NUM_MENU_ITEMS; extern MenuItem myMenuItems []; - bool *menuItemUpdated = NULL; + bool *menuItemUpdated = nullptr; #else #warning Not using Dynamic Parameters #endif @@ -456,7 +457,7 @@ class Ethernet_Manager #if USING_CUSTOMS_HEAD_ELEMENT //sets a custom element to add to head, like a new style tag - void setCustomsHeadElement(const char* CustomsHeadElement = NULL) + void setCustomsHeadElement(const char* CustomsHeadElement = nullptr) { _CustomsHeadElement = CustomsHeadElement; ETM_LOGDEBUG1(F("Set CustomsHeadElement to : "), _CustomsHeadElement); @@ -470,7 +471,7 @@ class Ethernet_Manager #endif #if USING_CORS_FEATURE - void setCORSHeader(const char* CORSHeaders = NULL) + void setCORSHeader(const char* CORSHeaders = nullptr) { _CORS_Header = CORSHeaders; @@ -489,6 +490,46 @@ class Ethernet_Manager return (Ethernet.linkStatus() == EthernetLinkStatus::LinkON); } + ////////////////////////////////////////////// + + uint8_t* getMacAddress() + { + return macAddress; + } + + ////////////////////////////////////////////// + + uint8_t* setMacAddress(const uint8_t* mac) + { + if ( isMacAddressValid(mac) ) + memcpy(macAddress, mac, sizeof(macAddress)); + + printMacAddress(); + + return macAddress; + } + + ////////////////////////////////////////////// + + void printMacAddress() + { + char theLocalBuffer[24]; + + snprintf(theLocalBuffer, sizeof(theLocalBuffer), "MAC:%02X-%02X-%02X-%02X-%02X-%02X", + macAddress[0], macAddress[1], + macAddress[2], macAddress[3], + macAddress[4], macAddress[5]); + + ETM_LOGWARN(theLocalBuffer); + } + + ////////////////////////////////////////////// + + bool isMacAddressValid(const uint8_t* mac) + { + return ( (mac != nullptr) && ( (mac[0] != 0) || (mac[1] != 0) || (mac[2] != 0) || (mac[3] != 0) ) ); + } + ////////////////////////////////////// @@ -516,17 +557,19 @@ class Ethernet_Manager uint16_t totalDataSize = 0; uint8_t currentBlynkServerIndex = 255; + + uint8_t macAddress[6] = { 0, 0, 0, 0, 0, 0 }; ///////////////////////////////////// // Add customs headers from v1.1.0 #if USING_CUSTOMS_STYLE - const char* ETM_HTML_HEAD_CUSTOMS_STYLE = NULL; + const char* ETM_HTML_HEAD_CUSTOMS_STYLE = nullptr; #endif #if USING_CUSTOMS_HEAD_ELEMENT - const char* _CustomsHeadElement = NULL; + const char* _CustomsHeadElement = nullptr; #endif #if USING_CORS_FEATURE @@ -674,7 +717,7 @@ class Ethernet_Manager int checkSum = 0; for (uint16_t index = 0; index < (sizeof(Ethernet_Manager_config) - sizeof(Ethernet_Manager_config.checkSum)); index++) { - checkSum += * ( ( (byte*) &Ethernet_Manager_config ) + index); + checkSum += * ( ( (uint8_t*) &Ethernet_Manager_config ) + index); } return checkSum; @@ -1391,6 +1434,9 @@ class Ethernet_Manager { ETM_LOGWARN(F("DHCPFailed")); } + + // KH new. Get mac and store + Ethernet.macAddress(macAddress); return ethernetConnected; } diff --git a/src/Ethernet_Manager.h b/src/Ethernet_Manager.h index 47568f99..a28323ef 100644 --- a/src/Ethernet_Manager.h +++ b/src/Ethernet_Manager.h @@ -9,7 +9,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.7.2 + Version: 1.8.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -26,6 +26,7 @@ 1.7.0 K Hoang 27/11/2021 Auto detect ESP32 core to use correct LittleFS. Fix QNEthernet-related linkStatus. 1.7.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. 1.7.2 K Hoang 10/04/2022 Use Ethernet_Generic library as default. Support SPI1/SPI2 for RP2040/ESP32 + 1.8.0 K Hoang 07/09/2022 Fix macAddress bug. Add functions relating to macAddress *****************************************************************************************************************************/ #pragma once @@ -36,19 +37,19 @@ /////////////////////////////////////////////////////////////// #ifndef ETHERNET_MANAGER_VERSION - #define ETHERNET_MANAGER_VERSION "Ethernet_Manager v1.7.2" + #define ETHERNET_MANAGER_VERSION "Ethernet_Manager v1.8.0" #define ETHERNET_MANAGER_VERSION_MAJOR 1 - #define ETHERNET_MANAGER_VERSION_MINOR 7 - #define ETHERNET_MANAGER_VERSION_PATCH 2 + #define ETHERNET_MANAGER_VERSION_MINOR 8 + #define ETHERNET_MANAGER_VERSION_PATCH 0 - #define ETHERNET_MANAGER_VERSION_INT 1007002 + #define ETHERNET_MANAGER_VERSION_INT 1008000 #endif /////////////////////////////////////////////////////////////// -#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET #endif diff --git a/src/Ethernet_Manager_Debug.h b/src/Ethernet_Manager_Debug.h index a93a6c1c..2a4224fe 100644 --- a/src/Ethernet_Manager_Debug.h +++ b/src/Ethernet_Manager_Debug.h @@ -9,7 +9,7 @@ Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.7.2 + Version: 1.8.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -26,6 +26,7 @@ 1.7.0 K Hoang 27/11/2021 Auto detect ESP32 core to use correct LittleFS. Fix QNEthernet-related linkStatus. 1.7.1 K Hoang 26/01/2022 Update to be compatible with new FlashStorage libraries. 1.7.2 K Hoang 10/04/2022 Use Ethernet_Generic library as default. Support SPI1/SPI2 for RP2040/ESP32 + 1.8.0 K Hoang 07/09/2022 Fix macAddress bug. Add functions relating to macAddress *****************************************************************************************************************************/ #pragma once