From 06af62ca23a21de24e270a398b8211588b5af43b Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Tue, 25 Jun 2024 12:28:27 +0200 Subject: [PATCH] Tasmota changes * revert WiFiClient - rename flush() to clear() https://github.com/espressif/arduino-esp32/pull/9453/files since it uneeded brakes many libs and code * optional Ethernet support (JL1101 driver added) * esp-modem only esp32, esp32s2 and esp32s3 * remove `OpenThread` * remove all BT BLE libraries * remove SPIFFS * remove Client Secure * remove Provisioning * remove TfLite, Insights and Rainmaker --- CMakeLists.txt | 100 +--------- Kconfig.projbuild | 31 --- README.md | 74 +------ cores/esp32/main.cpp | 6 + docs/en/migration_guides/2.x_to_3.0.rst | 1 - idf_component.yml | 43 +--- libraries/Ethernet/src/ETH.cpp | 5 + libraries/Ethernet/src/ETH.h | 3 + libraries/HTTPClient/src/HTTPClient.cpp | 2 + libraries/HTTPClient/src/HTTPClient.h | 4 + libraries/Network/src/NetworkClient.cpp | 10 +- libraries/Network/src/NetworkClient.h | 3 +- libraries/Network/src/NetworkEvents.h | 8 + libraries/Network/src/NetworkUdp.cpp | 4 +- libraries/Network/src/NetworkUdp.h | 3 +- libraries/Update/src/Update.h | 54 +---- libraries/Update/src/Updater.cpp | 185 +----------------- libraries/WiFi/examples/WiFiIPv6/WiFiIPv6.ino | 2 +- libraries/WiFi/src/STA.cpp | 99 ---------- libraries/WiFi/src/WiFiGeneric.cpp | 9 +- libraries/WiFi/src/WiFiGeneric.h | 4 + libraries/WiFi/src/WiFiSTA.cpp | 4 +- libraries/WiFi/src/WiFiSTA.h | 10 +- tools/platformio-build.py | 21 +- 24 files changed, 96 insertions(+), 589 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2086932a2d5..2a1652c004c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,6 @@ endif() set(CORE_SRCS cores/esp32/base64.cpp cores/esp32/cbuf.cpp - cores/esp32/chip-debug-report.cpp cores/esp32/esp32-hal-adc.c cores/esp32/esp32-hal-bt.c cores/esp32/esp32-hal-cpu.c @@ -78,39 +77,27 @@ set(CORE_SRCS set(ARDUINO_ALL_LIBRARIES ArduinoOTA AsyncUDP - BLE - BluetoothSerial DNSServer EEPROM - ESP_I2S - ESP_NOW - ESP_SR ESPmDNS Ethernet FFat FS HTTPClient HTTPUpdate - Insights LittleFS NetBIOS Network - OpenThread PPP Preferences - RainMaker SD_MMC SD - SimpleBLE - SPIFFS SPI Ticker Update USB WebServer - NetworkClientSecure WiFi - WiFiProv Wire ) @@ -119,26 +106,10 @@ set(ARDUINO_LIBRARY_ArduinoOTA_REQUIRES esp_https_ota) set(ARDUINO_LIBRARY_AsyncUDP_SRCS libraries/AsyncUDP/src/AsyncUDP.cpp) -set(ARDUINO_LIBRARY_BluetoothSerial_SRCS - libraries/BluetoothSerial/src/BluetoothSerial.cpp - libraries/BluetoothSerial/src/BTAddress.cpp - libraries/BluetoothSerial/src/BTAdvertisedDeviceSet.cpp - libraries/BluetoothSerial/src/BTScanResultsSet.cpp) - set(ARDUINO_LIBRARY_DNSServer_SRCS libraries/DNSServer/src/DNSServer.cpp) set(ARDUINO_LIBRARY_EEPROM_SRCS libraries/EEPROM/src/EEPROM.cpp) -set(ARDUINO_LIBRARY_ESP_I2S_SRCS libraries/ESP_I2S/src/ESP_I2S.cpp) - -set(ARDUINO_LIBRARY_ESP_NOW_SRCS - libraries/ESP_NOW/src/ESP32_NOW.cpp - libraries/ESP_NOW/src/ESP32_NOW_Serial.cpp) - -set(ARDUINO_LIBRARY_ESP_SR_SRCS - libraries/ESP_SR/src/ESP_SR.cpp - libraries/ESP_SR/src/esp32-hal-sr.c) - set(ARDUINO_LIBRARY_ESPmDNS_SRCS libraries/ESPmDNS/src/ESPmDNS.cpp) set(ARDUINO_LIBRARY_Ethernet_SRCS libraries/Ethernet/src/ETH.cpp) @@ -153,32 +124,16 @@ set(ARDUINO_LIBRARY_HTTPClient_SRCS libraries/HTTPClient/src/HTTPClient.cpp) set(ARDUINO_LIBRARY_HTTPUpdate_SRCS libraries/HTTPUpdate/src/HTTPUpdate.cpp) -set(ARDUINO_LIBRARY_Insights_SRCS libraries/Insights/src/Insights.cpp) - set(ARDUINO_LIBRARY_LittleFS_SRCS libraries/LittleFS/src/LittleFS.cpp) set(ARDUINO_LIBRARY_NetBIOS_SRCS libraries/NetBIOS/src/NetBIOS.cpp) -set(ARDUINO_LIBRARY_OpenThread_SRCS - libraries/OpenThread/src/OThreadCLI.cpp - libraries/OpenThread/src/OThreadCLI_Util.cpp) - set(ARDUINO_LIBRARY_PPP_SRCS libraries/PPP/src/PPP.cpp libraries/PPP/src/ppp.c) set(ARDUINO_LIBRARY_Preferences_SRCS libraries/Preferences/src/Preferences.cpp) -set(ARDUINO_LIBRARY_RainMaker_SRCS - libraries/RainMaker/src/RMaker.cpp - libraries/RainMaker/src/RMakerNode.cpp - libraries/RainMaker/src/RMakerParam.cpp - libraries/RainMaker/src/RMakerDevice.cpp - libraries/RainMaker/src/RMakerType.cpp - libraries/RainMaker/src/RMakerQR.cpp - libraries/RainMaker/src/RMakerUtils.cpp - libraries/RainMaker/src/AppInsights.cpp) - set(ARDUINO_LIBRARY_SD_MMC_SRCS libraries/SD_MMC/src/SD_MMC.cpp) set(ARDUINO_LIBRARY_SD_SRCS @@ -186,10 +141,6 @@ set(ARDUINO_LIBRARY_SD_SRCS libraries/SD/src/sd_diskio.cpp libraries/SD/src/sd_diskio_crc.c) -set(ARDUINO_LIBRARY_SimpleBLE_SRCS libraries/SimpleBLE/src/SimpleBLE.cpp) - -set(ARDUINO_LIBRARY_SPIFFS_SRCS libraries/SPIFFS/src/SPIFFS.cpp) - set(ARDUINO_LIBRARY_SPI_SRCS libraries/SPI/src/SPI.cpp) set(ARDUINO_LIBRARY_Ticker_SRCS libraries/Ticker/src/Ticker.cpp) @@ -214,10 +165,6 @@ set(ARDUINO_LIBRARY_WebServer_SRCS libraries/WebServer/src/Parsing.cpp libraries/WebServer/src/detail/mimetable.cpp) -set(ARDUINO_LIBRARY_NetworkClientSecure_SRCS - libraries/NetworkClientSecure/src/ssl_client.cpp - libraries/NetworkClientSecure/src/NetworkClientSecure.cpp) - set(ARDUINO_LIBRARY_Network_SRCS libraries/Network/src/NetworkInterface.cpp libraries/Network/src/NetworkEvents.cpp @@ -236,43 +183,8 @@ set(ARDUINO_LIBRARY_WiFi_SRCS libraries/WiFi/src/STA.cpp libraries/WiFi/src/AP.cpp) -set(ARDUINO_LIBRARY_WiFiProv_SRCS libraries/WiFiProv/src/WiFiProv.cpp) - set(ARDUINO_LIBRARY_Wire_SRCS libraries/Wire/src/Wire.cpp) -set(ARDUINO_LIBRARY_BLE_SRCS - libraries/BLE/src/BLE2901.cpp - libraries/BLE/src/BLE2902.cpp - libraries/BLE/src/BLE2904.cpp - libraries/BLE/src/BLEAddress.cpp - libraries/BLE/src/BLEAdvertisedDevice.cpp - libraries/BLE/src/BLEAdvertising.cpp - libraries/BLE/src/BLEBeacon.cpp - libraries/BLE/src/BLECharacteristic.cpp - libraries/BLE/src/BLECharacteristicMap.cpp - libraries/BLE/src/BLEClient.cpp - libraries/BLE/src/BLEDescriptor.cpp - libraries/BLE/src/BLEDescriptorMap.cpp - libraries/BLE/src/BLEDevice.cpp - libraries/BLE/src/BLEEddystoneTLM.cpp - libraries/BLE/src/BLEEddystoneURL.cpp - libraries/BLE/src/BLEExceptions.cpp - libraries/BLE/src/BLEHIDDevice.cpp - libraries/BLE/src/BLERemoteCharacteristic.cpp - libraries/BLE/src/BLERemoteDescriptor.cpp - libraries/BLE/src/BLERemoteService.cpp - libraries/BLE/src/BLEScan.cpp - libraries/BLE/src/BLESecurity.cpp - libraries/BLE/src/BLEServer.cpp - libraries/BLE/src/BLEService.cpp - libraries/BLE/src/BLEServiceMap.cpp - libraries/BLE/src/BLEUtils.cpp - libraries/BLE/src/BLEUUID.cpp - libraries/BLE/src/BLEValue.cpp - libraries/BLE/src/FreeRTOS.cpp - libraries/BLE/src/GeneralUtils.cpp - ) - set(ARDUINO_LIBRARIES_SRCS) set(ARDUINO_LIBRARIES_REQUIRES) set(ARDUINO_LIBRARIES_INCLUDEDIRS) @@ -293,16 +205,8 @@ endforeach() set(includedirs variants/${CONFIG_ARDUINO_VARIANT}/ cores/esp32/ ${ARDUINO_LIBRARIES_INCLUDEDIRS}) set(srcs ${CORE_SRCS} ${ARDUINO_LIBRARIES_SRCS}) set(priv_includes cores/esp32/libb64) -set(requires spi_flash esp_partition mbedtls wifi_provisioning wpa_supplicant esp_adc esp_eth http_parser) -set(priv_requires fatfs nvs_flash app_update spiffs bootloader_support bt esp_hid usb esp_psram ${ARDUINO_LIBRARIES_REQUIRES}) - -if(NOT CONFIG_ARDUINO_SELECTIVE_COMPILATION OR CONFIG_ARDUINO_SELECTIVE_OpenThread) - #if(CONFIG_SOC_IEEE802154_SUPPORTED) # Does not work! - #if(CONFIG_OPENTHREAD_ENABLED) # Does not work! - if(IDF_TARGET STREQUAL "esp32c6" OR IDF_TARGET STREQUAL "esp32h2") # Sadly only this works - list(APPEND requires openthread) - endif() -endif() +set(requires spi_flash esp_partition mbedtls wpa_supplicant esp_adc esp_eth http_parser) +set(priv_requires fatfs nvs_flash app_update bootloader_support bt esp_hid usb esp_psram ${ARDUINO_LIBRARIES_REQUIRES}) idf_component_register(INCLUDE_DIRS ${includedirs} PRIV_INCLUDE_DIRS ${priv_includes} SRCS ${srcs} REQUIRES ${requires} PRIV_REQUIRES ${priv_requires}) diff --git a/Kconfig.projbuild b/Kconfig.projbuild index 2085a11ea7d..9b53fb77e81 100644 --- a/Kconfig.projbuild +++ b/Kconfig.projbuild @@ -301,11 +301,6 @@ config ARDUINO_SELECTIVE_SD_MMC depends on ARDUINO_SELECTIVE_COMPILATION && ARDUINO_SELECTIVE_FS default y -config ARDUINO_SELECTIVE_SPIFFS - bool "Enable SPIFFS" - depends on ARDUINO_SELECTIVE_COMPILATION && ARDUINO_SELECTIVE_FS - default y - config ARDUINO_SELECTIVE_FFat bool "Enable FFat" depends on ARDUINO_SELECTIVE_COMPILATION && ARDUINO_SELECTIVE_FS @@ -355,7 +350,6 @@ config ARDUINO_SELECTIVE_ESPmDNS config ARDUINO_SELECTIVE_HTTPClient bool "Enable HTTPClient" depends on ARDUINO_SELECTIVE_COMPILATION && ARDUINO_SELECTIVE_Network - select ARDUINO_SELECTIVE_NetworkClientSecure default y config ARDUINO_SELECTIVE_NetBIOS @@ -374,29 +368,4 @@ config ARDUINO_SELECTIVE_WiFi depends on ARDUINO_SELECTIVE_COMPILATION && ARDUINO_SELECTIVE_Network default y -config ARDUINO_SELECTIVE_NetworkClientSecure - bool "Enable NetworkClientSecure" - depends on ARDUINO_SELECTIVE_COMPILATION && ARDUINO_SELECTIVE_Network - default y - -config ARDUINO_SELECTIVE_WiFiProv - bool "Enable WiFiProv" - depends on ARDUINO_SELECTIVE_COMPILATION && ARDUINO_SELECTIVE_Network && ARDUINO_SELECTIVE_WiFi - default y - -config ARDUINO_SELECTIVE_BLE - bool "Enable BLE" - depends on ARDUINO_SELECTIVE_COMPILATION - default y - -config ARDUINO_SELECTIVE_BluetoothSerial - bool "Enable BluetoothSerial" - depends on ARDUINO_SELECTIVE_COMPILATION - default y - -config ARDUINO_SELECTIVE_SimpleBLE - bool "Enable SimpleBLE" - depends on ARDUINO_SELECTIVE_COMPILATION - default y - endmenu diff --git a/README.md b/README.md index 52d13707db6..9c06a3378ac 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,6 @@ -# Arduino core for the ESP32, ESP32-S2, ESP32-S3, ESP32-C3, ESP32-C6 and ESP32-H2 +# Tasmota Platformio Arduino for ESP32, ESP32-S2, ESP32-S3, ESP32-C2, ESP32-C3, ESP32-C6 and ESP32-H2 -![Build Status](https://github.com/espressif/arduino-esp32/workflows/ESP32%20Arduino%20CI/badge.svg) [![External Libraries Test](https://github.com/espressif/arduino-esp32/actions/workflows/lib.yml/badge.svg?branch=master&event=schedule)](https://github.com/espressif/arduino-esp32/blob/gh-pages/LIBRARIES_TEST.md) [![Hardware Tests](https://github.com/espressif/arduino-esp32/actions/workflows/tests.yml/badge.svg?branch=master&event=schedule)](https://github.com/espressif/arduino-esp32/actions/workflows/tests.yml?query=event%3Aschedule) - -### Need help or have a question? Join the chat at [Gitter](https://gitter.im/espressif/arduino-esp32) or [open a new Discussion](https://github.com/espressif/arduino-esp32/discussions) - -## Contents - - - [Development Status](#development-status) - - [Development Planning](#development-planning) - - [Documentation](#documentation) - - [Supported Chips](#supported-chips) - - [Decoding exceptions](#decoding-exceptions) - - [Issue/Bug report template](#issuebug-report-template) - - [Contributing](#contributing) - -### Development Status - -Latest Stable Release [![Release Version](https://img.shields.io/github/release/espressif/arduino-esp32.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/latest/) [![Release Date](https://img.shields.io/github/release-date/espressif/arduino-esp32.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/latest/) [![Downloads](https://img.shields.io/github/downloads/espressif/arduino-esp32/latest/total.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/latest/) - -Latest Development Release [![Release Version](https://img.shields.io/github/release/espressif/arduino-esp32/all.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/) [![Release Date](https://img.shields.io/github/release-date-pre/espressif/arduino-esp32.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/) [![Downloads](https://img.shields.io/github/downloads-pre/espressif/arduino-esp32/latest/total.svg?style=plastic)](https://github.com/espressif/arduino-esp32/releases/) - -### Development Planning - -Our Development is fully tracked on this public **[Roadmap 🎉](https://github.com/orgs/espressif/projects/3)** - -For even more information you can join our **[Monthly Community Meetings 🔔](https://github.com/espressif/arduino-esp32/discussions/categories/monthly-community-meetings).** +### [![GitHub Releases](https://img.shields.io/github/downloads/tasmota/arduino-esp32/total?label=downloads)](https://github.com/tasmota/arduino-esp32/releases/latest) ### Documentation @@ -33,58 +9,24 @@ You can use the [Arduino-ESP32 Online Documentation](https://docs.espressif.com/ --- **Migration guide from version 2.x to 3.x is available [here](https://docs.espressif.com/projects/arduino-esp32/en/latest/migration_guides/2.x_to_3.0.html).** +The mentioned change from `flush` to `clear` is NOT done! --- -**APIs compatibility with ESP8266 and Arduino-CORE (Arduino.cc) is explained [here](https://docs.espressif.com/projects/arduino-esp32/en/latest/libraries.html#apis).** - ---- - -* [Getting Started](https://docs.espressif.com/projects/arduino-esp32/en/latest/getting_started.html) -* [Installing (Windows, Linux and macOS)](https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html) -* [Libraries](https://docs.espressif.com/projects/arduino-esp32/en/latest/libraries.html) -* [Arduino as an ESP-IDF component](https://docs.espressif.com/projects/arduino-esp32/en/latest/esp-idf_component.html) -* [FAQ](https://docs.espressif.com/projects/arduino-esp32/en/latest/faq.html) -* [Troubleshooting](https://docs.espressif.com/projects/arduino-esp32/en/latest/troubleshooting.html) - ### Supported Chips -Here are the ESP32 series supported by the Arduino-ESP32 project: +Here are the ESP32 series supported by the Tasmota Arduino-ESP32 project: | **SoC** | **Stable** | **Development** | **Datasheet** | |----------|:----------:|:---------------:|:-------------------------------------------------------------------------------------------------:| -| ESP32 | Yes | Yes | [ESP32](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf) | +| ESP32 | Yes | Yes | [ESP32](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf) | +| ESP32solo1| Yes | Yes | [ESP32solo1](https://www.espressif.com/sites/default/files/documentation/esp32-solo-1_datasheet_en.pdf) | | ESP32-S2 | Yes | Yes | [ESP32-S2](https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf) | -| ESP32-C3 | Yes | Yes | [ESP32-C3](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf) | | ESP32-S3 | Yes | Yes | [ESP32-S3](https://www.espressif.com/sites/default/files/documentation/esp32-s3_datasheet_en.pdf) | +| ESP32-C2 | Yes | Yes | [ESP32-C2](https://www.espressif.com/sites/default/files/documentation/esp8684_datasheet_en.pdf) | +| ESP32-C3 | Yes | Yes | [ESP32-C3](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf) | | ESP32-C6 | Yes | Yes | [ESP32-C6](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf) | | ESP32-H2 | Yes | Yes | [ESP32-H2](https://www.espressif.com/sites/default/files/documentation/esp32-h2_datasheet_en.pdf) | -> [!NOTE] -> ESP32-C2 is also supported by Arduino-ESP32 but requires rebuilding the static libraries. This is not trivial and requires a good understanding of the ESP-IDF -> build system. For more information, see the [Lib Builder documentation](https://docs.espressif.com/projects/arduino-esp32/en/latest/lib_builder.html). For more details visit the [supported chips](https://docs.espressif.com/projects/arduino-esp32/en/latest/getting_started.html#supported-soc-s) documentation page. - -### Decoding exceptions - -You can use [EspExceptionDecoder](https://github.com/me-no-dev/EspExceptionDecoder) to get meaningful call trace. - -### Issue/Bug report template - -Before reporting an issue, make sure you've searched for similar one that was already created. Also make sure to go through all the issues labeled as [Type: For reference](https://github.com/espressif/arduino-esp32/issues?q=is%3Aissue+label%3A%22Type%3A+For+reference%22+). - -Finally, if you are sure no one else had the issue, follow the **Issue template** or **Feature request template** while reporting any [new Issue](https://github.com/espressif/arduino-esp32/issues/new/choose). - -### External libraries compilation test - -We have set-up CI testing for external libraries for ESP32 Arduino core. You can check test results in the file [LIBRARIES_TEST](https://github.com/espressif/arduino-esp32/blob/gh-pages/LIBRARIES_TEST.md). -For more information and how to add your library to the test see [external library testing](https://docs.espressif.com/projects/arduino-esp32/en/latest/external_libraries_test.html) in the documentation. - -### Contributing - -We welcome contributions to the Arduino ESP32 project! - -See [contributing](https://docs.espressif.com/projects/arduino-esp32/en/latest/contributing.html) in the documentation for more information on how to contribute to the project. - -> We would like to have this repository in a polite and friendly atmosphere, so please be kind and respectful to others. For more details, look at [Code of Conduct](https://github.com/espressif/arduino-esp32/blob/master/CODE_OF_CONDUCT.md). diff --git a/cores/esp32/main.cpp b/cores/esp32/main.cpp index 6c4d50a9a84..746d18dc075 100644 --- a/cores/esp32/main.cpp +++ b/cores/esp32/main.cpp @@ -10,7 +10,9 @@ #endif #endif +#if defined __has_include && __has_include("chip-debug-report.h") #include "chip-debug-report.h" +#endif #ifndef ARDUINO_LOOP_STACK_SIZE #ifndef CONFIG_ARDUINO_LOOP_STACK_SIZE @@ -49,20 +51,24 @@ void loopTask(void *pvParameters) { // sets UART0 (default console) RX/TX pins as already configured in boot or as defined in variants/pins_arduino.h Serial0.setPins(gpioNumberToDigitalPin(SOC_RX0), gpioNumberToDigitalPin(SOC_TX0)); #endif +#if defined __has_include && __has_include("chip-debug-report.h") #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG printBeforeSetupInfo(); #else if (shouldPrintChipDebugReport()) { printBeforeSetupInfo(); } +#endif #endif setup(); +#if defined __has_include && __has_include("chip-debug-report.h") #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG printAfterSetupInfo(); #else if (shouldPrintChipDebugReport()) { printAfterSetupInfo(); } +#endif #endif for (;;) { #if CONFIG_FREERTOS_UNICORE diff --git a/docs/en/migration_guides/2.x_to_3.0.rst b/docs/en/migration_guides/2.x_to_3.0.rst index bb6cab294cc..9db94937e9a 100644 --- a/docs/en/migration_guides/2.x_to_3.0.rst +++ b/docs/en/migration_guides/2.x_to_3.0.rst @@ -223,6 +223,5 @@ WiFi Functional changes ^^^^^^^^^^^^^^^^^^ -* In Arduino (and other frameworks) the method named ``flush()`` is intended to send out the transmit buffer content. ``WiFiClient`` and ``WiFiUDP`` method ``flush()`` won't clear the receive buffer anymore. A new method called ``clear()`` is now used for that. Currently ``flush()`` does nothing in ``WiFiClient``, ``WiFiClientSecure`` and ``WiFiUDP``. * ``WiFiServer`` has functions ``accept()`` and ``available()`` with the same functionality. In Arduino, ``available()`` should work differently so it is now deprecated. * ``WiFiServer`` had unimplemented write functions inherited from ``Print`` class. These are now removed. Also unimplemented method ``stopAll()`` is removed. The methods were unimplemented because ``WiFiServer`` doesn't manage connected ``WiFiClient`` objects for print-to-all-clients functionality. diff --git a/idf_component.yml b/idf_component.yml index 81d79180dbb..77b87bd6d25 100644 --- a/idf_component.yml +++ b/idf_component.yml @@ -49,48 +49,19 @@ dependencies: require: public espressif/esp_modem: version: "^1.1.0" + rules: + - if: "target in [esp32, esp32s2, esp32s3, esp32h2]" espressif/esp-zboss-lib: version: "^1.0.1" rules: - - if: "target != esp32c2" + - if: "target in [esp32h2]" espressif/esp-zigbee-lib: version: "^1.0.1" rules: - - if: "target != esp32c2" + - if: "target in [esp32h2]" espressif/esp-dsp: - version: "^1.3.4" - rules: - - if: "target != esp32c2" - espressif/esp_rainmaker: - version: "^1.0.0" - rules: - - if: "target != esp32c2" - espressif/rmaker_common: - version: "^1.4.3" - rules: - - if: "target != esp32c2" - espressif/esp_insights: - version: "^1.0.1" + version: "^1.4.12" rules: - - if: "target != esp32c2" - espressif/qrcode: - version: "^0.1.0~1" - rules: - - if: "target != esp32c2" - espressif/esp-sr: - version: "^1.4.2" - rules: - - if: "target in [esp32s3]" - espressif/libsodium: - version: "^1.0.20~1" - require: public - espressif/esp-modbus: - version: "^1.0.15" - require: public + - if: "target in [esp32s3, esp32]" joltwallet/littlefs: - version: "^1.10.2" - chmorgan/esp-libhelix-mp3: - version: "1.0.3" - require: public -examples: - - path: ./idf_component_examples/hello_world + version: "^1.14.1" diff --git a/libraries/Ethernet/src/ETH.cpp b/libraries/Ethernet/src/ETH.cpp index 2480dd982ec..f833967154c 100644 --- a/libraries/Ethernet/src/ETH.cpp +++ b/libraries/Ethernet/src/ETH.cpp @@ -19,6 +19,8 @@ */ // Disable the automatic pin remapping of the API calls in this file +#if defined __has_include && __has_include("esp_eth_driver.h") + #define ARDUINO_CORE_BUILD #include "ETH.h" @@ -231,6 +233,7 @@ bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, i case ETH_PHY_TLK110: phy = esp_eth_phy_new_ip101(&phy_config); break; case ETH_PHY_RTL8201: phy = esp_eth_phy_new_rtl8201(&phy_config); break; case ETH_PHY_DP83848: phy = esp_eth_phy_new_dp83848(&phy_config); break; + case ETH_PHY_JL1101: phy = esp_eth_phy_new_jl1101(&phy_config); break; case ETH_PHY_KSZ8041: phy = esp_eth_phy_new_ksz80xx(&phy_config); break; case ETH_PHY_KSZ8081: phy = esp_eth_phy_new_ksz80xx(&phy_config); break; default: log_e("Unsupported PHY %d", type); break; @@ -998,3 +1001,5 @@ size_t ETHClass::printDriverInfo(Print &out) const { } ETHClass ETH; + +#endif /* defined __has_include && __has_include("esp_eth_driver.h") */ diff --git a/libraries/Ethernet/src/ETH.h b/libraries/Ethernet/src/ETH.h index b481b9e36c3..551243074fa 100644 --- a/libraries/Ethernet/src/ETH.h +++ b/libraries/Ethernet/src/ETH.h @@ -17,6 +17,7 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#if defined __has_include && __has_include("esp_eth_driver.h") #ifndef _ETH_H_ #define _ETH_H_ @@ -101,6 +102,7 @@ typedef enum { ETH_PHY_LAN8720, ETH_PHY_TLK110, ETH_PHY_RTL8201, + ETH_PHY_JL1101, ETH_PHY_DP83848, ETH_PHY_KSZ8041, ETH_PHY_KSZ8081, @@ -219,3 +221,4 @@ class ETHClass : public NetworkInterface { extern ETHClass ETH; #endif /* _ETH_H_ */ +#endif /* defined __has_include && __has_include("esp_eth_driver.h") */ diff --git a/libraries/HTTPClient/src/HTTPClient.cpp b/libraries/HTTPClient/src/HTTPClient.cpp index 3dc3b7156ca..30589cd1600 100644 --- a/libraries/HTTPClient/src/HTTPClient.cpp +++ b/libraries/HTTPClient/src/HTTPClient.cpp @@ -35,6 +35,8 @@ /// Cookie jar support #include +#define HTTPCLIENT_NOSECURE + #ifdef HTTPCLIENT_1_1_COMPATIBLE class TransportTraits { public: diff --git a/libraries/HTTPClient/src/HTTPClient.h b/libraries/HTTPClient/src/HTTPClient.h index 80f6da28599..20d07c723ed 100644 --- a/libraries/HTTPClient/src/HTTPClient.h +++ b/libraries/HTTPClient/src/HTTPClient.h @@ -31,6 +31,10 @@ #define HTTPCLIENT_1_1_COMPATIBLE #endif +#ifndef HTTPCLIENT_NOSECURE +#define HTTPCLIENT_NOSECURE +#endif + #include #include #include diff --git a/libraries/Network/src/NetworkClient.cpp b/libraries/Network/src/NetworkClient.cpp index 9f4806df18a..820a97d2a43 100644 --- a/libraries/Network/src/NetworkClient.cpp +++ b/libraries/Network/src/NetworkClient.cpp @@ -146,7 +146,7 @@ class NetworkClientRxBuffer { return _fill - _pos + r_available(); } - void clear() { + void flush() { if (r_available()) { fillBuffer(); } @@ -369,8 +369,6 @@ int NetworkClient::read() { return data; } -void NetworkClient::flush() {} - size_t NetworkClient::write(const uint8_t *buf, size_t size) { int res = 0; int retry = WIFI_CLIENT_MAX_WRITE_RETRY; @@ -531,9 +529,11 @@ int NetworkClient::available() { return res; } -void NetworkClient::clear() { +// Though flushing means to send all pending data, +// seems that in Arduino it also means to clear RX +void NetworkClient::flush() { if (_rxBuffer != nullptr) { - _rxBuffer->clear(); + _rxBuffer->flush(); } } diff --git a/libraries/Network/src/NetworkClient.h b/libraries/Network/src/NetworkClient.h index 572292a7a99..d4e013c80e0 100644 --- a/libraries/Network/src/NetworkClient.h +++ b/libraries/Network/src/NetworkClient.h @@ -56,7 +56,6 @@ class NetworkClient : public ESPLwIPClient { size_t write(const uint8_t *buf, size_t size); size_t write_P(PGM_P buf, size_t size); size_t write(Stream &stream); - void flush(); // Print::flush tx int available(); int read(); int read(uint8_t *buf, size_t size); @@ -65,7 +64,7 @@ class NetworkClient : public ESPLwIPClient { return readBytes((char *)buffer, length); } int peek(); - void clear(); // clear rx + void flush(); void stop(); uint8_t connected(); void setSSE(bool sse); diff --git a/libraries/Network/src/NetworkEvents.h b/libraries/Network/src/NetworkEvents.h index 6c0e82f4d81..82912ace52c 100644 --- a/libraries/Network/src/NetworkEvents.h +++ b/libraries/Network/src/NetworkEvents.h @@ -9,7 +9,9 @@ #include "esp_err.h" #include "esp_event.h" #include "esp_netif_types.h" +#if defined __has_include && __has_include("esp_eth_driver.h") #include "esp_eth_driver.h" +#endif #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -20,8 +22,10 @@ #if SOC_WIFI_SUPPORTED #include "esp_wifi_types.h" #include "esp_smartconfig.h" +#if defined __has_include && __has_include("wifi_provisioning/wifi_config.h") #include "wifi_provisioning/wifi_config.h" #endif +#endif #if SOC_WIFI_SUPPORTED static const int WIFI_SCANNING_BIT = BIT0; @@ -92,7 +96,9 @@ typedef union { ip_event_ap_staipassigned_t wifi_ap_staipassigned; ip_event_got_ip_t got_ip; ip_event_got_ip6_t got_ip6; +#if defined __has_include && __has_include("esp_eth_driver.h") esp_eth_handle_t eth_connected; +#endif #if SOC_WIFI_SUPPORTED wifi_event_sta_scan_done_t wifi_scan_done; wifi_event_sta_authmode_change_t wifi_sta_authmode_change; @@ -105,7 +111,9 @@ typedef union { wifi_event_ap_stadisconnected_t wifi_ap_stadisconnected; wifi_event_ftm_report_t wifi_ftm_report; wifi_sta_config_t prov_cred_recv; +#if defined __has_include && __has_include("wifi_provisioning/wifi_config.h") wifi_prov_sta_fail_reason_t prov_fail_reason; +#endif smartconfig_event_got_ssid_pswd_t sc_got_ssid_pswd; #endif } arduino_event_info_t; diff --git a/libraries/Network/src/NetworkUdp.cpp b/libraries/Network/src/NetworkUdp.cpp index 6134ba49967..57f3b28ca3f 100644 --- a/libraries/Network/src/NetworkUdp.cpp +++ b/libraries/Network/src/NetworkUdp.cpp @@ -288,8 +288,6 @@ size_t NetworkUDP::write(const uint8_t *buffer, size_t size) { return i; } -void NetworkUDP::flush() {} - int NetworkUDP::parsePacket() { if (rx_buffer) { return 0; @@ -385,7 +383,7 @@ int NetworkUDP::peek() { return rx_buffer->peek(); } -void NetworkUDP::clear() { +void NetworkUDP::flush() { if (!rx_buffer) { return; } diff --git a/libraries/Network/src/NetworkUdp.h b/libraries/Network/src/NetworkUdp.h index ec05991b7e3..62aa4f9cb20 100644 --- a/libraries/Network/src/NetworkUdp.h +++ b/libraries/Network/src/NetworkUdp.h @@ -64,14 +64,13 @@ class NetworkUDP : public UDP { int endPacket(); size_t write(uint8_t); size_t write(const uint8_t *buffer, size_t size); - void flush(); // Print::flush tx int parsePacket(); int available(); int read(); int read(unsigned char *buffer, size_t len); int read(char *buffer, size_t len); int peek(); - void clear(); // clear rx + void flush(); IPAddress remoteIP(); uint16_t remotePort(); }; diff --git a/libraries/Update/src/Update.h b/libraries/Update/src/Update.h index 7ae5e980751..ece90a2af1a 100644 --- a/libraries/Update/src/Update.h +++ b/libraries/Update/src/Update.h @@ -25,7 +25,6 @@ #define UPDATE_ERROR_NO_PARTITION (10) #define UPDATE_ERROR_BAD_ARGUMENT (11) #define UPDATE_ERROR_ABORT (12) -#define UPDATE_ERROR_DECRYPT (13) #define UPDATE_SIZE_UNKNOWN 0xFFFFFFFF @@ -33,15 +32,7 @@ #define U_SPIFFS 100 #define U_AUTH 200 -#define ENCRYPTED_BLOCK_SIZE 16 -#define ENCRYPTED_TWEAK_BLOCK_SIZE 32 -#define ENCRYPTED_KEY_SIZE 32 - -#define U_AES_DECRYPT_NONE 0 -#define U_AES_DECRYPT_AUTO 1 -#define U_AES_DECRYPT_ON 2 -#define U_AES_DECRYPT_MODE_MASK 3 -#define U_AES_IMAGE_DECRYPTING_BIT 4 +#define ENCRYPTED_BLOCK_SIZE 16 #define SPI_SECTORS_PER_BLOCK 16 // usually large erase block is 32k/64k #define SPI_FLASH_BLOCK_SIZE (SPI_SECTORS_PER_BLOCK * SPI_FLASH_SEC_SIZE) @@ -63,15 +54,6 @@ class UpdateClass { */ bool begin(size_t size = UPDATE_SIZE_UNKNOWN, int command = U_FLASH, int ledPin = -1, uint8_t ledOn = LOW, const char *label = NULL); - /* - Setup decryption configuration - Crypt Key is 32bytes(256bits) block of data, use the same key as used to encrypt image file - Crypt Address, use the same value as used to encrypt image file - Crypt Config, use the same value as used to encrypt image file - Crypt Mode, used to select if image files should be decrypted or not - */ - bool setupCrypt(const uint8_t *cryptKey = 0, size_t cryptAddress = 0, uint8_t cryptConfig = 0xf, int cryptMode = U_AES_DECRYPT_AUTO); - /* Writes a buffer to the flash and increments the address Returns the amount written @@ -95,34 +77,10 @@ class UpdateClass { or there is an error this will clear everything and return false the last error is available through getError() - evenIfRemaining is helpful when you update without knowing the final size first + evenIfRemaining is helpfull when you update without knowing the final size first */ bool end(bool evenIfRemaining = false); - /* - sets AES256 key(32 bytes) used for decrypting image file - */ - bool setCryptKey(const uint8_t *cryptKey); - - /* - sets crypt mode used on image files - */ - bool setCryptMode(const int cryptMode); - - /* - sets address used for decrypting image file - */ - void setCryptAddress(const size_t cryptAddress) { - _cryptAddress = cryptAddress & 0x00fffff0; - } - - /* - sets crypt config used for decrypting image file - */ - void setCryptConfig(const uint8_t cryptConfig) { - _cryptCfg = cryptConfig & 0x0f; - } - /* Aborts the running update */ @@ -235,8 +193,6 @@ class UpdateClass { private: void _reset(); void _abort(uint8_t err); - void _cryptKeyTweak(size_t cryptAddress, uint8_t *tweaked_key); - bool _decryptBuffer(); bool _writeBuffer(); bool _verifyHeader(uint8_t data); bool _verifyEnd(); @@ -244,8 +200,6 @@ class UpdateClass { bool _chkDataInBlock(const uint8_t *data, size_t len) const; // check if block contains any data or is empty uint8_t _error; - uint8_t *_cryptKey; - uint8_t *_cryptBuffer; uint8_t *_buffer; uint8_t *_skipBuffer; size_t _bufferLen; @@ -261,10 +215,6 @@ class UpdateClass { int _ledPin; uint8_t _ledOn; - - uint8_t _cryptMode; - size_t _cryptAddress; - uint8_t _cryptCfg; }; #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_UPDATE) diff --git a/libraries/Update/src/Updater.cpp b/libraries/Update/src/Updater.cpp index 4be13b9d1ed..e5717c5beea 100644 --- a/libraries/Update/src/Updater.cpp +++ b/libraries/Update/src/Updater.cpp @@ -9,7 +9,6 @@ #include "spi_flash_mmap.h" #include "esp_ota_ops.h" #include "esp_image_format.h" -#include "mbedtls/aes.h" static const char *_err2str(uint8_t _error) { if (_error == UPDATE_ERROR_OK) { @@ -38,8 +37,6 @@ static const char *_err2str(uint8_t _error) { return ("Bad Argument"); } else if (_error == UPDATE_ERROR_ABORT) { return ("Aborted"); - } else if (_error == UPDATE_ERROR_DECRYPT) { - return ("Decryption error"); } return ("UNKNOWN"); } @@ -67,8 +64,7 @@ bool UpdateClass::_enablePartition(const esp_partition_t *partition) { } UpdateClass::UpdateClass() - : _error(0), _cryptKey(0), _cryptBuffer(0), _buffer(0), _skipBuffer(0), _bufferLen(0), _size(0), _progress_callback(NULL), _progress(0), _paroffset(0), - _command(U_FLASH), _partition(NULL), _cryptMode(U_AES_DECRYPT_AUTO), _cryptAddress(0), _cryptCfg(0xf) {} + : _error(0), _buffer(0), _bufferLen(0), _size(0), _progress_callback(NULL), _progress(0), _paroffset(0), _command(U_FLASH), _partition(NULL) {} UpdateClass &UpdateClass::onProgress(THandlerFunction_Progress fn) { _progress_callback = fn; @@ -83,7 +79,6 @@ void UpdateClass::_reset() { delete[] _skipBuffer; } - _cryptBuffer = nullptr; _buffer = nullptr; _skipBuffer = nullptr; _bufferLen = 0; @@ -175,48 +170,6 @@ bool UpdateClass::begin(size_t size, int command, int ledPin, uint8_t ledOn, con return true; } -bool UpdateClass::setupCrypt(const uint8_t *cryptKey, size_t cryptAddress, uint8_t cryptConfig, int cryptMode) { - if (setCryptKey(cryptKey)) { - if (setCryptMode(cryptMode)) { - setCryptAddress(cryptAddress); - setCryptConfig(cryptConfig); - return true; - } - } - return false; -} - -bool UpdateClass::setCryptKey(const uint8_t *cryptKey) { - if (!cryptKey) { - if (_cryptKey) { - delete[] _cryptKey; - _cryptKey = 0; - log_d("AES key unset"); - } - return false; //key cleared, no key to decrypt with - } - //initialize - if (!_cryptKey) { - _cryptKey = new (std::nothrow) uint8_t[ENCRYPTED_KEY_SIZE]; - } - if (!_cryptKey) { - log_e("new failed"); - return false; - } - memcpy(_cryptKey, cryptKey, ENCRYPTED_KEY_SIZE); - return true; -} - -bool UpdateClass::setCryptMode(const int cryptMode) { - if (cryptMode >= U_AES_DECRYPT_NONE && cryptMode <= U_AES_DECRYPT_ON) { - _cryptMode = cryptMode; - } else { - log_e("bad crypt mode argument %i", cryptMode); - return false; - } - return true; -} - void UpdateClass::_abort(uint8_t err) { _reset(); _error = err; @@ -226,135 +179,7 @@ void UpdateClass::abort() { _abort(UPDATE_ERROR_ABORT); } -void UpdateClass::_cryptKeyTweak(size_t cryptAddress, uint8_t *tweaked_key) { - memcpy(tweaked_key, _cryptKey, ENCRYPTED_KEY_SIZE); - if (_cryptCfg == 0) { - return; //no tweaking needed, use crypt key as-is - } - - const uint8_t pattern[] = {23, 23, 23, 14, 23, 23, 23, 12, 23, 23, 23, 10, 23, 23, 23, 8}; - int pattern_idx = 0; - int key_idx = 0; - int bit_len = 0; - uint32_t tweak = 0; - cryptAddress &= 0x00ffffe0; //bit 23-5 - cryptAddress <<= 8; //bit23 shifted to bit31(MSB) - while (pattern_idx < sizeof(pattern)) { - tweak = cryptAddress << (23 - pattern[pattern_idx]); //bit shift for small patterns - // alternative to: tweak = rotl32(tweak,8 - bit_len); - tweak = (tweak << (8 - bit_len)) | (tweak >> (24 + bit_len)); //rotate to line up with end of previous tweak bits - bit_len += pattern[pattern_idx++] - 4; //add number of bits in next pattern(23-4 = 19bits = 23bit to 5bit) - while (bit_len > 7) { - tweaked_key[key_idx++] ^= tweak; //XOR byte - // alternative to: tweak = rotl32(tweak, 8); - tweak = (tweak << 8) | (tweak >> 24); //compiler should optimize to use rotate(fast) - bit_len -= 8; - } - tweaked_key[key_idx] ^= tweak; //XOR remaining bits, will XOR zeros if no remaining bits - } - if (_cryptCfg == 0xf) { - return; //return with fully tweaked key - } - - //some of tweaked key bits need to be restore back to crypt key bits - const uint8_t cfg_bits[] = {67, 65, 63, 61}; - key_idx = 0; - pattern_idx = 0; - while (key_idx < ENCRYPTED_KEY_SIZE) { - bit_len += cfg_bits[pattern_idx]; - if ((_cryptCfg & (1 << pattern_idx)) == 0) { //restore crypt key bits - while (bit_len > 0) { - if (bit_len > 7 || ((_cryptCfg & (2 << pattern_idx)) == 0)) { //restore a crypt key byte - tweaked_key[key_idx] = _cryptKey[key_idx]; - } else { //MSBits restore crypt key bits, LSBits keep as tweaked bits - tweaked_key[key_idx] &= (0xff >> bit_len); - tweaked_key[key_idx] |= (_cryptKey[key_idx] & (~(0xff >> bit_len))); - } - key_idx++; - bit_len -= 8; - } - } else { //keep tweaked key bits - while (bit_len > 0) { - if (bit_len < 8 && ((_cryptCfg & (2 << pattern_idx)) == 0)) { //MSBits keep as tweaked bits, LSBits restore crypt key bits - tweaked_key[key_idx] &= (~(0xff >> bit_len)); - tweaked_key[key_idx] |= (_cryptKey[key_idx] & (0xff >> bit_len)); - } - key_idx++; - bit_len -= 8; - } - } - pattern_idx++; - } -} - -bool UpdateClass::_decryptBuffer() { - if (!_cryptKey) { - log_w("AES key not set"); - return false; - } - if (_bufferLen % ENCRYPTED_BLOCK_SIZE != 0) { - log_e("buffer size error"); - return false; - } - if (!_cryptBuffer) { - _cryptBuffer = new (std::nothrow) uint8_t[ENCRYPTED_BLOCK_SIZE]; - } - if (!_cryptBuffer) { - log_e("new failed"); - return false; - } - uint8_t tweaked_key[ENCRYPTED_KEY_SIZE]; //tweaked crypt key - int done = 0; - - /* - Mbedtls functions will be replaced with esp_aes functions when hardware acceleration is available - - To Do: - Replace mbedtls for the cases where there's no hardware acceleration - */ - - mbedtls_aes_context ctx; //initialize AES - mbedtls_aes_init(&ctx); - while ((_bufferLen - done) >= ENCRYPTED_BLOCK_SIZE) { - for (int i = 0; i < ENCRYPTED_BLOCK_SIZE; i++) { - _cryptBuffer[(ENCRYPTED_BLOCK_SIZE - 1) - i] = _buffer[i + done]; //reverse order 16 bytes to decrypt - } - if (((_cryptAddress + _progress + done) % ENCRYPTED_TWEAK_BLOCK_SIZE) == 0 || done == 0) { - _cryptKeyTweak(_cryptAddress + _progress + done, tweaked_key); //update tweaked crypt key - if (mbedtls_aes_setkey_enc(&ctx, tweaked_key, 256)) { - return false; - } - if (mbedtls_aes_setkey_dec(&ctx, tweaked_key, 256)) { - return false; - } - } - if (mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT, _cryptBuffer, _cryptBuffer)) { //use MBEDTLS_AES_ENCRYPT to decrypt flash code - return false; - } - for (int i = 0; i < ENCRYPTED_BLOCK_SIZE; i++) { - _buffer[i + done] = _cryptBuffer[(ENCRYPTED_BLOCK_SIZE - 1) - i]; //reverse order 16 bytes from decrypt - } - done += ENCRYPTED_BLOCK_SIZE; - } - return true; -} - bool UpdateClass::_writeBuffer() { - //first bytes of loading image, check to see if loading image needs decrypting - if (!_progress) { - _cryptMode &= U_AES_DECRYPT_MODE_MASK; - if ((_cryptMode == U_AES_DECRYPT_ON) || ((_command == U_FLASH) && (_cryptMode & U_AES_DECRYPT_AUTO) && (_buffer[0] != ESP_IMAGE_HEADER_MAGIC))) { - _cryptMode |= U_AES_IMAGE_DECRYPTING_BIT; //set to decrypt the loading image - log_d("Decrypting OTA Image"); - } - } - //check if data in buffer needs decrypting - if (_cryptMode & U_AES_IMAGE_DECRYPTING_BIT) { - if (!_decryptBuffer()) { - _abort(UPDATE_ERROR_DECRYPT); - return false; - } - } //first bytes of new firmware uint8_t skip = 0; if (!_progress && _command == U_FLASH) { @@ -524,11 +349,9 @@ size_t UpdateClass::writeStream(Stream &data) { return 0; } - if (_command == U_FLASH && !_cryptMode) { - if (!_verifyHeader(data.peek())) { - _reset(); - return 0; - } + if (!_verifyHeader(data.peek())) { + _reset(); + return 0; } if (_ledPin != -1) { diff --git a/libraries/WiFi/examples/WiFiIPv6/WiFiIPv6.ino b/libraries/WiFi/examples/WiFiIPv6/WiFiIPv6.ino index d7241a2f1a4..05cbc4a1841 100644 --- a/libraries/WiFi/examples/WiFiIPv6/WiFiIPv6.ino +++ b/libraries/WiFi/examples/WiFiIPv6/WiFiIPv6.ino @@ -50,7 +50,7 @@ void wifiConnectedLoop() { if (packetLength >= NTP_PACKET_SIZE) { ntpClient.read(ntpPacketBuffer, NTP_PACKET_SIZE); } - ntpClient.clear(); + ntpClient.flush(); uint32_t secsSince1900 = (uint32_t)ntpPacketBuffer[40] << 24 | (uint32_t)ntpPacketBuffer[41] << 16 | (uint32_t)ntpPacketBuffer[42] << 8 | ntpPacketBuffer[43]; //Serial.printf("Seconds since Jan 1 1900: %u\n", secsSince1900); diff --git a/libraries/WiFi/src/STA.cpp b/libraries/WiFi/src/STA.cpp index 443d2621957..bede1680ec4 100644 --- a/libraries/WiFi/src/STA.cpp +++ b/libraries/WiFi/src/STA.cpp @@ -419,105 +419,6 @@ bool STAClass::connect(const char *ssid, const char *passphrase, int32_t channel return true; } -/** - * Start Wifi connection with a WPA2 Enterprise AP - * if passphrase is set the most secure supported mode will be automatically selected - * @param ssid const char* Pointer to the SSID string. - * @param method wpa2_method_t The authentication method of WPA2 (WPA2_AUTH_TLS, WPA2_AUTH_PEAP, WPA2_AUTH_TTLS) - * @param wpa2_identity const char* Pointer to the entity - * @param wpa2_username const char* Pointer to the username - * @param password const char * Pointer to the password. - * @param ca_pem const char* Pointer to a string with the contents of a .pem file with CA cert - * @param client_crt const char* Pointer to a string with the contents of a .crt file with client cert - * @param client_key const char* Pointer to a string with the contents of a .key file with client key - * @param bssid uint8_t[6] Optional. BSSID / MAC of AP - * @param channel Optional. Channel of AP - * @param connect Optional. call connect - * @return - */ -bool STAClass::connect( - const char *wpa2_ssid, wpa2_auth_method_t method, const char *wpa2_identity, const char *wpa2_username, const char *wpa2_password, const char *ca_pem, - const char *client_crt, const char *client_key, int ttls_phase2_type, int32_t channel, const uint8_t *bssid, bool tryConnect -) { - if (_esp_netif == NULL) { - log_e("STA not started! You must call begin() first."); - return false; - } - - if (connected()) { - log_w("STA currently connected. Disconnecting..."); - if (!disconnect(true, 1000)) { - return false; - } - } - - if (!wpa2_ssid || *wpa2_ssid == 0x00 || strlen(wpa2_ssid) > 32) { - log_e("SSID too long or missing!"); - return false; - } - - if (wpa2_identity && strlen(wpa2_identity) > 64) { - log_e("identity too long!"); - return false; - } - - if (wpa2_username && strlen(wpa2_username) > 64) { - log_e("username too long!"); - return false; - } - - if (wpa2_password && strlen(wpa2_password) > 64) { - log_e("password too long!"); - return false; - } - - if (ttls_phase2_type >= 0) { -#if __has_include("esp_eap_client.h") - esp_eap_client_set_ttls_phase2_method((esp_eap_ttls_phase2_types)ttls_phase2_type); -#else - esp_wifi_sta_wpa2_ent_set_ttls_phase2_method((esp_eap_ttls_phase2_types)ttls_phase2_type); -#endif - } - - if (ca_pem) { -#if __has_include("esp_eap_client.h") - esp_eap_client_set_ca_cert((uint8_t *)ca_pem, strlen(ca_pem)); -#else - esp_wifi_sta_wpa2_ent_set_ca_cert((uint8_t *)ca_pem, strlen(ca_pem)); -#endif - } - - if (client_crt) { -#if __has_include("esp_eap_client.h") - esp_eap_client_set_certificate_and_key((uint8_t *)client_crt, strlen(client_crt), (uint8_t *)client_key, strlen(client_key), NULL, 0); -#else - esp_wifi_sta_wpa2_ent_set_cert_key((uint8_t *)client_crt, strlen(client_crt), (uint8_t *)client_key, strlen(client_key), NULL, 0); -#endif - } - -#if __has_include("esp_eap_client.h") - esp_eap_client_set_identity((uint8_t *)wpa2_identity, strlen(wpa2_identity)); -#else - esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)wpa2_identity, strlen(wpa2_identity)); -#endif - if (method == WPA2_AUTH_PEAP || method == WPA2_AUTH_TTLS) { -#if __has_include("esp_eap_client.h") - esp_eap_client_set_username((uint8_t *)wpa2_username, strlen(wpa2_username)); - esp_eap_client_set_password((uint8_t *)wpa2_password, strlen(wpa2_password)); -#else - esp_wifi_sta_wpa2_ent_set_username((uint8_t *)wpa2_username, strlen(wpa2_username)); - esp_wifi_sta_wpa2_ent_set_password((uint8_t *)wpa2_password, strlen(wpa2_password)); -#endif - } -#if __has_include("esp_eap_client.h") - esp_wifi_sta_enterprise_enable(); //set config settings to enable function -#else - esp_wifi_sta_wpa2_ent_enable(); //set config settings to enable function -#endif - - return connect(wpa2_ssid, NULL, channel, bssid, tryConnect); //connect to wifi -} - bool STAClass::disconnect(bool eraseap, unsigned long timeout) { if (eraseap) { if (!started()) { diff --git a/libraries/WiFi/src/WiFiGeneric.cpp b/libraries/WiFi/src/WiFiGeneric.cpp index 75a01d1362f..0f5ec0ee279 100644 --- a/libraries/WiFi/src/WiFiGeneric.cpp +++ b/libraries/WiFi/src/WiFiGeneric.cpp @@ -126,7 +126,9 @@ static void _arduino_event_cb(void *arg, esp_event_base_t event_base, int32_t ev /* * Provisioning * */ - } else if (event_base == WIFI_PROV_EVENT && event_id == WIFI_PROV_INIT) { + } +#if defined __has_include && __has_include("wifi_provisioning/wifi_config.h") + else if (event_base == WIFI_PROV_EVENT && event_id == WIFI_PROV_INIT) { log_v("Provisioning Initialized!"); arduino_event.event_id = ARDUINO_EVENT_PROV_INIT; } else if (event_base == WIFI_PROV_EVENT && event_id == WIFI_PROV_DEINIT) { @@ -157,6 +159,7 @@ static void _arduino_event_cb(void *arg, esp_event_base_t event_base, int32_t ev log_v("Provisioning Success!"); arduino_event.event_id = ARDUINO_EVENT_PROV_CRED_SUCCESS; } +#endif // __has_include ("wifi_provisioning/wifi_config.h") if (arduino_event.event_id < ARDUINO_EVENT_MAX) { Network.postEvent(&arduino_event); @@ -174,10 +177,12 @@ static bool initWiFiEvents() { return false; } +#if defined __has_include && __has_include("wifi_provisioning/wifi_config.h") if (esp_event_handler_instance_register(WIFI_PROV_EVENT, ESP_EVENT_ANY_ID, &_arduino_event_cb, NULL, NULL)) { log_e("event_handler_instance_register for WIFI_PROV_EVENT Failed!"); return false; } +#endif // __has_include ("wifi_provisioning/wifi_config.h") return true; } @@ -193,10 +198,12 @@ static bool deinitWiFiEvents() { return false; } +#if defined __has_include && __has_include("wifi_provisioning/wifi_config.h") if (esp_event_handler_unregister(WIFI_PROV_EVENT, ESP_EVENT_ANY_ID, &_arduino_event_cb)) { log_e("esp_event_handler_unregister for WIFI_PROV_EVENT Failed!"); return false; } +#endif // __has_include ("wifi_provisioning/wifi_config.h") return true; } diff --git a/libraries/WiFi/src/WiFiGeneric.h b/libraries/WiFi/src/WiFiGeneric.h index 3cb1515b324..df46639fb03 100644 --- a/libraries/WiFi/src/WiFiGeneric.h +++ b/libraries/WiFi/src/WiFiGeneric.h @@ -32,8 +32,12 @@ #include "IPAddress.h" #include "esp_smartconfig.h" #include "esp_netif_types.h" +#if defined __has_include && __has_include("esp_eth_driver.h") #include "esp_eth_driver.h" +#endif +#if defined __has_include && __has_include("wifi_provisioning/manager.h") #include "wifi_provisioning/manager.h" +#endif #include "lwip/ip_addr.h" #include "Network.h" diff --git a/libraries/WiFi/src/WiFiSTA.cpp b/libraries/WiFi/src/WiFiSTA.cpp index 1c1ce42c12f..470db1a5675 100644 --- a/libraries/WiFi/src/WiFiSTA.cpp +++ b/libraries/WiFi/src/WiFiSTA.cpp @@ -65,13 +65,13 @@ wl_status_t WiFiSTAClass::status() { wl_status_t WiFiSTAClass::begin( const char *wpa2_ssid, wpa2_auth_method_t method, const char *wpa2_identity, const char *wpa2_username, const char *wpa2_password, const char *ca_pem, - const char *client_crt, const char *client_key, int ttls_phase2_type, int32_t channel, const uint8_t *bssid, bool connect + const char *client_crt, const char *client_key, int32_t channel, const uint8_t *bssid, bool connect ) { if (!STA.begin()) { return WL_CONNECT_FAILED; } - if (!STA.connect(wpa2_ssid, method, wpa2_identity, wpa2_username, wpa2_password, ca_pem, client_crt, client_key, ttls_phase2_type, channel, bssid, connect)) { + if (!STA.connect(wpa2_ssid, method, wpa2_identity, wpa2_username, wpa2_password, ca_pem, client_crt, client_key, channel, bssid, connect)) { return WL_CONNECT_FAILED; } diff --git a/libraries/WiFi/src/WiFiSTA.h b/libraries/WiFi/src/WiFiSTA.h index 2c046c4c4b9..d5c5d377d3b 100644 --- a/libraries/WiFi/src/WiFiSTA.h +++ b/libraries/WiFi/src/WiFiSTA.h @@ -55,8 +55,7 @@ class STAClass : public NetworkInterface { bool connect(const char *ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t *bssid = NULL, bool connect = true); bool connect( const char *wpa2_ssid, wpa2_auth_method_t method, const char *wpa2_identity = NULL, const char *wpa2_username = NULL, const char *wpa2_password = NULL, - const char *ca_pem = NULL, const char *client_crt = NULL, const char *client_key = NULL, int ttls_phase2_type = -1, int32_t channel = 0, - const uint8_t *bssid = 0, bool connect = true + const char *ca_pem = NULL, const char *client_crt = NULL, const char *client_key = NULL, int32_t channel = 0, const uint8_t *bssid = 0, bool connect = true ); bool disconnect(bool eraseap = false, unsigned long timeout = 0); bool reconnect(); @@ -110,17 +109,16 @@ class WiFiSTAClass { wl_status_t begin( const char *wpa2_ssid, wpa2_auth_method_t method, const char *wpa2_identity = NULL, const char *wpa2_username = NULL, const char *wpa2_password = NULL, - const char *ca_pem = NULL, const char *client_crt = NULL, const char *client_key = NULL, int ttls_phase2_type = -1, int32_t channel = 0, - const uint8_t *bssid = 0, bool connect = true + const char *ca_pem = NULL, const char *client_crt = NULL, const char *client_key = NULL, int32_t channel = 0, const uint8_t *bssid = 0, bool connect = true ); wl_status_t begin( const String &wpa2_ssid, wpa2_auth_method_t method, const String &wpa2_identity = (const char *)NULL, const String &wpa2_username = (const char *)NULL, const String &wpa2_password = (const char *)NULL, const String &ca_pem = (const char *)NULL, const String &client_crt = (const char *)NULL, - const String &client_key = (const char *)NULL, int ttls_phase2_type = -1, int32_t channel = 0, const uint8_t *bssid = 0, bool connect = true + const String &client_key = (const char *)NULL, int32_t channel = 0, const uint8_t *bssid = 0, bool connect = true ) { return begin( wpa2_ssid.c_str(), method, wpa2_identity.c_str(), wpa2_username.c_str(), wpa2_password.c_str(), ca_pem.c_str(), client_crt.c_str(), client_key.c_str(), - ttls_phase2_type, channel, bssid, connect + channel, bssid, connect ); } wl_status_t begin(const char *ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t *bssid = NULL, bool connect = true); diff --git a/tools/platformio-build.py b/tools/platformio-build.py index 06b5dac2e1b..8f90e29004f 100644 --- a/tools/platformio-build.py +++ b/tools/platformio-build.py @@ -35,7 +35,7 @@ partitions_name = board_config.get("build.partitions", board_config.get("build.arduino.partitions", "")) FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32") -FRAMEWORK_LIBS_DIR = platform.get_package_dir("framework-arduinoespressif32-libs") +FRAMEWORK_LIBS_DIR = join(FRAMEWORK_DIR, "tools", "esp32-arduino-libs") assert isdir(FRAMEWORK_DIR) @@ -175,9 +175,15 @@ def add_tinyuf2_extra_image(): libs = [] variants_dir = join(FRAMEWORK_DIR, "variants") +try: + build_variants_dir = join(board_config.get("build.variants_dir")) +except Exception: + build_variants_dir = "" if "build.variants_dir" in board_config: - variants_dir = join("$PROJECT_DIR", board_config.get("build.variants_dir")) + if len(build_variants_dir) > 1: + variants_dir = join("$PROJECT_DIR", board_config.get("build.variants_dir")) + if "build.variant" in board_config: env.Append(CPPPATH=[join(variants_dir, board_config.get("build.variant"))]) @@ -200,6 +206,15 @@ def add_tinyuf2_extra_image(): # Process framework extra images # +# Tasmota places extra images "safeboot" in custom variants folder in project directory +build_name = join(board_config.get("name")) +if len(build_variants_dir) > 1: + EXTRA_IMG_DIR = join(variants_dir) +else: + EXTRA_IMG_DIR = FRAMEWORK_DIR + if "tasmota" in build_name.lower(): + EXTRA_IMG_DIR = join(EXTRA_IMG_DIR, "variants", "tasmota") + env.Append( LIBSOURCE_DIRS=[join(FRAMEWORK_DIR, "libraries")], FLASH_EXTRA_IMAGES=[ @@ -210,7 +225,7 @@ def add_tinyuf2_extra_image(): ("0x8000", join(env.subst("$BUILD_DIR"), "partitions.bin")), ("0xe000", join(FRAMEWORK_DIR, "tools", "partitions", "boot_app0.bin")), ] - + [(offset, join(FRAMEWORK_DIR, img)) for offset, img in board_config.get("upload.arduino.flash_extra_images", [])], + + [(offset, join(EXTRA_IMG_DIR, img)) for offset, img in board_config.get("upload.arduino.flash_extra_images", [])], ) # Add an extra UF2 image if the 'TinyUF2' partition is selected