Skip to content

Commit

Permalink
0.8.152
Browse files Browse the repository at this point in the history
fix ESP8266 compile
  • Loading branch information
lumapu committed Oct 7, 2024
1 parent 76899a6 commit 78cbd77
Showing 1 changed file with 44 additions and 9 deletions.
53 changes: 44 additions & 9 deletions patches/espMqttClientSemaphore.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
diff --git a/src/Helpers.h b/src/Helpers.h
index 05ab136..50b4c2f 100644
--- a/src/Helpers.h
+++ b/src/Helpers.h
@@ -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 <https://opensource.org/licenses/MIT> or
the LICENSE file.
*/
@@ -13,6 +13,7 @@ the LICENSE file.
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_task_wdt.h"
+ #define EMC_SEMAPHORE_TAKE_CHECK() if(pdTRUE == xSemaphoreTake(_xSemaphore, portMAX_DELAY))
#define EMC_SEMAPHORE_TAKE() xSemaphoreTake(_xSemaphore, portMAX_DELAY)
#define EMC_SEMAPHORE_GIVE() xSemaphoreGive(_xSemaphore)
#define EMC_GET_FREE_MEMORY() std::max(ESP.getMaxAllocHeap(), ESP.getMaxAllocPsram())
@@ -25,9 +26,11 @@ the LICENSE file.
// _xSemaphore defined as std::atomic<bool>
#define EMC_SEMAPHORE_TAKE() while (_xSemaphore) { /*ESP.wdtFeed();*/ } _xSemaphore = true
#define EMC_SEMAPHORE_GIVE() _xSemaphore = false
+ #define EMC_SEMAPHORE_TAKE_CHECK() EMC_SEMAPHORE_TAKE
#else
#define EMC_SEMAPHORE_TAKE()
#define EMC_SEMAPHORE_GIVE()
+ #define EMC_SEMAPHORE_TAKE_CHECK()
#endif
#define EMC_GET_FREE_MEMORY() ESP.getMaxFreeBlockSize()
// no need to yield for ESP8266, the Arduino framework does this internally
diff --git a/src/MqttClient.cpp b/src/MqttClient.cpp
index dc21f74..d4b35c4 100644
index dc21f74..d524e50 100644
--- a/src/MqttClient.cpp
+++ b/src/MqttClient.cpp
@@ -1,7 +1,7 @@
Expand All @@ -11,7 +44,7 @@ index dc21f74..d4b35c4 100644
For a copy, see <https://opensource.org/licenses/MIT> or
the LICENSE file.
*/
@@ -148,16 +148,19 @@ uint16_t MqttClient::publish(const char* topic, uint8_t qos, bool retain, const
@@ -148,16 +148,20 @@ uint16_t MqttClient::publish(const char* topic, uint8_t qos, bool retain, const
#endif
return 0;
}
Expand All @@ -20,14 +53,15 @@ index dc21f74..d4b35c4 100644
- 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()) {
+ EMC_SEMAPHORE_TAKE_CHECK() {
+ 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())
+ EMC_SEMAPHORE_TAKE_CHECK() {
+ packetId = 0;
+ }
+ }
EMC_SEMAPHORE_GIVE();
- _onError(packetId, Error::OUT_OF_MEMORY);
Expand All @@ -39,7 +73,7 @@ index dc21f74..d4b35c4 100644
return packetId;
}

@@ -174,16 +177,19 @@ uint16_t MqttClient::publish(const char* topic, uint8_t qos, bool retain, espMqt
@@ -174,16 +178,20 @@ uint16_t MqttClient::publish(const char* topic, uint8_t qos, bool retain, espMqt
#endif
return 0;
}
Expand All @@ -48,14 +82,15 @@ index dc21f74..d4b35c4 100644
- 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()) {
+ EMC_SEMAPHORE_TAKE_CHECK() {
+ 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())
+ EMC_SEMAPHORE_TAKE_CHECK() {
+ packetId = 0;
+ }
+ }
EMC_SEMAPHORE_GIVE();
- _onError(packetId, Error::OUT_OF_MEMORY);
Expand All @@ -67,7 +102,7 @@ index dc21f74..d4b35c4 100644
return packetId;
}

@@ -237,11 +243,13 @@ void MqttClient::loop() {
@@ -237,11 +245,13 @@ void MqttClient::loop() {
case State::connectingMqtt:
#if EMC_WAIT_FOR_CONNACK
if (_transport->connected()) {
Expand All @@ -76,7 +111,7 @@ index dc21f74..d4b35c4 100644
- _checkIncoming();
- _checkPing();
- EMC_SEMAPHORE_GIVE();
+ if(pdTRUE == EMC_SEMAPHORE_TAKE()) {
+ EMC_SEMAPHORE_TAKE_CHECK() {
+ _sendPacket();
+ _checkIncoming();
+ _checkPing();
Expand Down

0 comments on commit 78cbd77

Please sign in to comment.