From 3afc16515718cd291471c7609601452d7c3afc1c Mon Sep 17 00:00:00 2001 From: lumapu Date: Mon, 7 Oct 2024 22:42:47 +0200 Subject: [PATCH] 0.8.152 * patching MqTT library to prevent raise conditions while using semaphores * update ESP32 espressif platform to `0.6.9` * update ESPAsyncWebServer to `3.3.12` --- patches/espMqttClientSemaphore.patch | 88 ++++++++++++++++++++++++++++ scripts/applyPatches.py | 2 + src/CHANGES.md | 5 ++ src/defines.h | 2 +- src/platformio.ini | 30 +++++----- 5 files changed, 111 insertions(+), 16 deletions(-) create mode 100644 patches/espMqttClientSemaphore.patch diff --git a/patches/espMqttClientSemaphore.patch b/patches/espMqttClientSemaphore.patch new file mode 100644 index 00000000..99ad9249 --- /dev/null +++ b/patches/espMqttClientSemaphore.patch @@ -0,0 +1,88 @@ +diff --git a/src/MqttClient.cpp b/src/MqttClient.cpp +index dc21f74..d4b35c4 100644 +--- a/src/MqttClient.cpp ++++ b/src/MqttClient.cpp +@@ -1,7 +1,7 @@ + /* + Copyright (c) 2022 Bert Melis. All rights reserved. + +-This work is licensed under the terms of the MIT license. ++This work is licensed under the terms of the MIT license. + For a copy, see or + the LICENSE file. + */ +@@ -148,16 +148,19 @@ uint16_t MqttClient::publish(const char* topic, uint8_t qos, bool retain, const + #endif + return 0; + } +- EMC_SEMAPHORE_TAKE(); +- uint16_t packetId = (qos > 0) ? _getNextPacketId() : 1; +- if (!_addPacket(packetId, topic, payload, length, qos, retain)) { +- emc_log_e("Could not create PUBLISH packet"); ++ uint16_t packetId = 0; ++ if(pdTRUE == EMC_SEMAPHORE_TAKE()) { ++ packetId = (qos > 0) ? _getNextPacketId() : 1; ++ if (!_addPacket(packetId, topic, payload, length, qos, retain)) { ++ emc_log_e("Could not create PUBLISH packet"); ++ EMC_SEMAPHORE_GIVE(); ++ _onError(packetId, Error::OUT_OF_MEMORY); ++ if(pdTRUE == EMC_SEMAPHORE_TAKE()) ++ packetId = 0; ++ } + EMC_SEMAPHORE_GIVE(); +- _onError(packetId, Error::OUT_OF_MEMORY); +- EMC_SEMAPHORE_TAKE(); +- packetId = 0; ++ yield(); + } +- EMC_SEMAPHORE_GIVE(); + return packetId; + } + +@@ -174,16 +177,19 @@ uint16_t MqttClient::publish(const char* topic, uint8_t qos, bool retain, espMqt + #endif + return 0; + } +- EMC_SEMAPHORE_TAKE(); +- uint16_t packetId = (qos > 0) ? _getNextPacketId() : 1; +- if (!_addPacket(packetId, topic, callback, length, qos, retain)) { +- emc_log_e("Could not create PUBLISH packet"); ++ uint16_t packetId = 0; ++ if(pdTRUE == EMC_SEMAPHORE_TAKE()) { ++ packetId = (qos > 0) ? _getNextPacketId() : 1; ++ if (!_addPacket(packetId, topic, callback, length, qos, retain)) { ++ emc_log_e("Could not create PUBLISH packet"); ++ EMC_SEMAPHORE_GIVE(); ++ _onError(packetId, Error::OUT_OF_MEMORY); ++ if(pdTRUE == EMC_SEMAPHORE_TAKE()) ++ packetId = 0; ++ } + EMC_SEMAPHORE_GIVE(); +- _onError(packetId, Error::OUT_OF_MEMORY); +- EMC_SEMAPHORE_TAKE(); +- packetId = 0; ++ yield(); + } +- EMC_SEMAPHORE_GIVE(); + return packetId; + } + +@@ -237,11 +243,13 @@ void MqttClient::loop() { + case State::connectingMqtt: + #if EMC_WAIT_FOR_CONNACK + if (_transport->connected()) { +- EMC_SEMAPHORE_TAKE(); +- _sendPacket(); +- _checkIncoming(); +- _checkPing(); +- EMC_SEMAPHORE_GIVE(); ++ if(pdTRUE == EMC_SEMAPHORE_TAKE()) { ++ _sendPacket(); ++ _checkIncoming(); ++ _checkPing(); ++ EMC_SEMAPHORE_GIVE(); ++ yield(); ++ } + } else { + _setState(State::disconnectingTcp1); + _disconnectReason = DisconnectReason::TCP_DISCONNECTED; diff --git a/scripts/applyPatches.py b/scripts/applyPatches.py index 1ef36963..dcd3098f 100644 --- a/scripts/applyPatches.py +++ b/scripts/applyPatches.py @@ -25,6 +25,8 @@ def applyPatch(libName, patchFile): os.chdir(start) +applyPatch("espMqttClient", "../patches/espMqttClientSemaphore.patch") + # list of patches to apply (relative to /src) if (env['PIOENV'][:5] == "esp32") or (env['PIOENV'][:13] == "opendtufusion"): applyPatch("GxEPD2", "../patches/GxEPD2_HAL.patch") diff --git a/src/CHANGES.md b/src/CHANGES.md index 050cbbf3..d14bca3d 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -1,5 +1,10 @@ # Development Changes +## 0.8.152 - 2024-10-07 +* patching MqTT library to prevent raise conditions while using semaphores +* update ESP32 espressif platform to `0.6.9` +* update ESPAsyncWebServer to `3.3.12` + ## 0.8.151 - 2024-10-03 * don't interrupt current command by setting a new limit #1757 * add button for CMT inverters to catch them independend on which frequency they were before #1749 diff --git a/src/defines.h b/src/defines.h index 4b2828c8..1f3d013c 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 8 -#define VERSION_PATCH 151 +#define VERSION_PATCH 152 //------------------------------------- typedef struct { uint8_t ch; diff --git a/src/platformio.ini b/src/platformio.ini index 8553d824..f5c75a10 100644 --- a/src/platformio.ini +++ b/src/platformio.ini @@ -152,18 +152,18 @@ monitor_filters = esp8266_exception_decoder [env:esp32-wroom32-minimal] -platform = espressif32@6.7.0 +platform = espressif32@6.9.0 board = lolin_d32 lib_deps = ${env.lib_deps} - https://github.com/mathieucarbou/ESPAsyncWebServer#v3.3.7 + https://github.com/mathieucarbou/ESPAsyncWebServer#v3.3.12 build_flags = ${env.build_flags} -DSPI_HAL monitor_filters = esp32_exception_decoder [env:esp32-wroom32] -platform = espressif32@6.7.0 +platform = espressif32@6.9.0 board = lolin_d32 lib_deps = ${env:esp32-wroom32-minimal.lib_deps} build_flags = ${env:esp32-wroom32-minimal.build_flags} @@ -193,7 +193,7 @@ monitor_filters = esp32_exception_decoder [env:esp32-wroom32-de] -platform = espressif32@6.7.0 +platform = espressif32@6.9.0 board = lolin_d32 lib_deps = ${env:esp32-wroom32-minimal.lib_deps} build_flags = ${env:esp32-wroom32.build_flags} @@ -202,7 +202,7 @@ monitor_filters = esp32_exception_decoder [env:esp32-wroom32-prometheus] -platform = espressif32@6.7.0 +platform = espressif32@6.9.0 board = lolin_d32 lib_deps = ${env:esp32-wroom32-minimal.lib_deps} build_flags = ${env:esp32-wroom32.build_flags} @@ -211,7 +211,7 @@ monitor_filters = esp32_exception_decoder [env:esp32-wroom32-prometheus-de] -platform = espressif32@6.7.0 +platform = espressif32@6.9.0 board = lolin_d32 lib_deps = ${env:esp32-wroom32-minimal.lib_deps} build_flags = ${env:esp32-wroom32-prometheus.build_flags} @@ -220,7 +220,7 @@ monitor_filters = esp32_exception_decoder [env:esp32-s2-mini] -platform = espressif32@6.7.0 +platform = espressif32@6.9.0 board = lolin_s2_mini lib_deps = ${env:esp32-wroom32-minimal.lib_deps} build_flags = ${env.build_flags} @@ -244,7 +244,7 @@ monitor_filters = esp32_exception_decoder [env:esp32-s2-mini-de] -platform = espressif32@6.7.0 +platform = espressif32@6.9.0 board = lolin_s2_mini lib_deps = ${env:esp32-wroom32-minimal.lib_deps} build_flags = ${env:esp32-s2-mini.build_flags} @@ -253,7 +253,7 @@ monitor_filters = esp32_exception_decoder [env:esp32-c3-mini] -platform = espressif32@6.7.0 +platform = espressif32@6.9.0 board = lolin_c3_mini lib_deps = ${env:esp32-wroom32-minimal.lib_deps} build_flags = ${env.build_flags} @@ -277,7 +277,7 @@ monitor_filters = esp32_exception_decoder [env:esp32-c3-mini-de] -platform = espressif32@6.7.0 +platform = espressif32@6.9.0 board = lolin_c3_mini lib_deps = ${env:esp32-wroom32-minimal.lib_deps} build_flags = ${env:esp32-c3-mini.build_flags} @@ -286,7 +286,7 @@ monitor_filters = esp32_exception_decoder [env:opendtufusion-minimal] -platform = espressif32@6.7.0 +platform = espressif32@6.9.0 board = esp32-s3-devkitc-1 upload_protocol = esp-builtin lib_deps = ${env:esp32-wroom32-minimal.lib_deps} @@ -312,7 +312,7 @@ monitor_filters = esp32_exception_decoder, colorize [env:opendtufusion] -platform = espressif32@6.7.0 +platform = espressif32@6.9.0 board = esp32-s3-devkitc-1 upload_protocol = esp-builtin lib_deps = ${env:esp32-wroom32-minimal.lib_deps} @@ -331,7 +331,7 @@ monitor_filters = esp32_exception_decoder, colorize [env:opendtufusion-de] -platform = espressif32@6.7.0 +platform = espressif32@6.9.0 board = esp32-s3-devkitc-1 upload_protocol = esp-builtin lib_deps = ${env:esp32-wroom32-minimal.lib_deps} @@ -341,7 +341,7 @@ monitor_filters = esp32_exception_decoder, colorize [env:opendtufusion-16MB] -platform = espressif32@6.7.0 +platform = espressif32@6.9.0 board = esp32-s3-devkitc-1 board_upload.flash_size = 16MB board_build.partitions = default_16MB.csv @@ -352,7 +352,7 @@ monitor_filters = esp32_exception_decoder, colorize [env:opendtufusion-16MB-de] -platform = espressif32@6.7.0 +platform = espressif32@6.9.0 board = esp32-s3-devkitc-1 upload_protocol = esp-builtin lib_deps = ${env:esp32-wroom32-minimal.lib_deps}