From a3300e94a7c08b8b7a991e4ba74780d72f4d90ce Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Tue, 3 Oct 2023 15:28:27 +0200 Subject: [PATCH] compiles for 2.0.13/idf4.4.6 and 3.0.0/idf5.1 (see pio_local.example) --- lib/AsyncTCP/src/AsyncTCP.cpp | 2 +- lib/ESPAsyncWebServer/AsyncEventSource.cpp | 2 +- lib/ESPAsyncWebServer/WebAuthentication.cpp | 4 ++-- lib/framework/UploadFileService.cpp | 1 + pio_local.ini_example | 3 +++ src/analogsensor.cpp | 16 ++++++++++++++-- src/system.cpp | 2 +- src/web/WebDataService.cpp | 4 ++-- 8 files changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/AsyncTCP/src/AsyncTCP.cpp b/lib/AsyncTCP/src/AsyncTCP.cpp index 5695918e9..4b5c25acb 100644 --- a/lib/AsyncTCP/src/AsyncTCP.cpp +++ b/lib/AsyncTCP/src/AsyncTCP.cpp @@ -84,7 +84,7 @@ typedef struct { }; } lwip_event_packet_t; -static xQueueHandle _async_queue; +static QueueHandle_t _async_queue; static TaskHandle_t _async_service_task_handle = NULL; diff --git a/lib/ESPAsyncWebServer/AsyncEventSource.cpp b/lib/ESPAsyncWebServer/AsyncEventSource.cpp index 8230f0ebc..e6ae38d69 100644 --- a/lib/ESPAsyncWebServer/AsyncEventSource.cpp +++ b/lib/ESPAsyncWebServer/AsyncEventSource.cpp @@ -185,7 +185,7 @@ void AsyncEventSourceClient::_queueMessage(AsyncEventSourceMessage *dataMessage) return; } if(_messageQueue.length() >= SSE_MAX_QUEUED_MESSAGES){ - ets_printf(String(F("ERROR: Too many messages queued\n")).c_str()); + // ets_printf(String(F("ERROR: Too many messages queued\n")).c_str()); delete dataMessage; } else { _messageQueue.add(dataMessage); diff --git a/lib/ESPAsyncWebServer/WebAuthentication.cpp b/lib/ESPAsyncWebServer/WebAuthentication.cpp index 288e15508..340d4471e 100644 --- a/lib/ESPAsyncWebServer/WebAuthentication.cpp +++ b/lib/ESPAsyncWebServer/WebAuthentication.cpp @@ -71,8 +71,8 @@ static bool getMD5(uint8_t * data, uint16_t len, char * output){//33 bytes or mo memset(_buf, 0x00, 16); #ifdef ESP32 mbedtls_md5_init(&_ctx); - mbedtls_md5_update_ret (&_ctx,data,len); - mbedtls_md5_finish_ret(&_ctx,data); + mbedtls_md5_update (&_ctx,data,len); + mbedtls_md5_finish(&_ctx,data); mbedtls_internal_md5_process( &_ctx ,data); #else MD5Init(&_ctx); diff --git a/lib/framework/UploadFileService.cpp b/lib/framework/UploadFileService.cpp index 91428b8eb..0d7b652d5 100644 --- a/lib/framework/UploadFileService.cpp +++ b/lib/framework/UploadFileService.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "../../src/emsesp_stub.hpp" diff --git a/pio_local.ini_example b/pio_local.ini_example index 5180d1c53..99fa32ed0 100644 --- a/pio_local.ini_example +++ b/pio_local.ini_example @@ -21,6 +21,9 @@ default_envs = esp32_4M ; default_envs = debug [env:esp32_4M] +; update to arduino 3, IDF 5 +platform = https://github.com/Jason2866/platform-espressif32.git#Arduino/IDF5 +; ; if using OTA enter your details below ; upload_protocol = espota ; upload_flags = diff --git a/src/analogsensor.cpp b/src/analogsensor.cpp index a819b17cd..8c42be43c 100644 --- a/src/analogsensor.cpp +++ b/src/analogsensor.cpp @@ -213,15 +213,23 @@ void AnalogSensor::reload() { publish_sensor(sensor); } else if (sensor.type() >= AnalogType::PWM_0) { LOG_DEBUG("Adding PWM output sensor on GPIO %02d", sensor.gpio()); - uint channel = sensor.type() - AnalogType::PWM_0; +#if ESP_IDF_VERSION_MAJOR >= 5 + ledcAttach(sensor.gpio(), sensor.factor(), 13); +#else + uint8_t channel = sensor.type() - AnalogType::PWM_0; ledcSetup(channel, sensor.factor(), 13); ledcAttachPin(sensor.gpio(), channel); +#endif if (sensor.offset() > 100) { sensor.set_offset(100); } else if (sensor.offset() < 0) { sensor.set_offset(0); } +#if ESP_IDF_VERSION_MAJOR >= 5 + ledcWrite(sensor.gpio(), (uint32_t)(sensor.offset() * 8191 / 100)); +#else ledcWrite(channel, (uint32_t)(sensor.offset() * 8191 / 100)); +#endif sensor.set_value(sensor.offset()); sensor.set_uom(DeviceValueUOM::PERCENT); publish_sensor(sensor); @@ -798,7 +806,6 @@ bool AnalogSensor::command_setvalue(const char * value, const int8_t gpio) { return true; } } else if (sensor.type() >= AnalogType::PWM_0) { - uint8_t channel = sensor.type() - AnalogType::PWM_0; if (val > 100) { val = 100; } else if (val < 0) { @@ -806,7 +813,12 @@ bool AnalogSensor::command_setvalue(const char * value, const int8_t gpio) { } sensor.set_offset(val); sensor.set_value(val); +#if ESP_IDF_VERSION_MAJOR >= 5 + ledcWrite(sensor.gpio(), (uint32_t)(sensor.offset() * 8191 / 100)); +#else + uint8_t channel = sensor.type() - AnalogType::PWM_0; ledcWrite(channel, (uint32_t)(val * 8191 / 100)); +#endif publish_sensor(sensor); return true; } diff --git a/src/system.cpp b/src/system.cpp index 4d511366d..ade342558 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -696,7 +696,7 @@ void System::network_init(bool refresh) { // ETH_CLOCK_GPIO17_OUT = 3 RMII clock output from GPIO17, for 50hz inverted clock auto clock_mode = (eth_clock_mode_t)eth_clock_mode_; - eth_present_ = ETH.begin(phy_addr, power, mdc, mdio, type, clock_mode); + eth_present_ = ETH.begin((eth_phy_type_t)phy_addr, power, mdc, mdio, type, clock_mode); #endif } diff --git a/src/web/WebDataService.cpp b/src/web/WebDataService.cpp index b8488ca23..92ab854d1 100644 --- a/src/web/WebDataService.cpp +++ b/src/web/WebDataService.cpp @@ -251,7 +251,7 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar return_code = Command::call(device_type, cmd, data.as(), true, id, output); } else if (data.is()) { char s[10]; - return_code = Command::call(device_type, cmd, Helpers::render_value(s, data.as(), 0), true, id, output); + return_code = Command::call(device_type, cmd, Helpers::render_value(s, data.as(), 0), true, id, output); } else if (data.is()) { char s[10]; return_code = Command::call(device_type, cmd, Helpers::render_value(s, data.as(), 1), true, id, output); @@ -288,7 +288,7 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar return_code = Command::call(device_type, cmd, data.as(), true, id, output); } else if (data.is()) { char s[10]; - return_code = Command::call(device_type, cmd, Helpers::render_value(s, data.as(), 0), true, id, output); + return_code = Command::call(device_type, cmd, Helpers::render_value(s, data.as(), 0), true, id, output); } else if (data.is()) { char s[10]; return_code = Command::call(device_type, cmd, Helpers::render_value(s, data.as(), 1), true, id, output);