From dd72b39489685edf2d6b40f4e8bc75c9d747f4e3 Mon Sep 17 00:00:00 2001 From: brentru Date: Fri, 21 Apr 2023 13:05:51 -0400 Subject: [PATCH 1/2] fix return type for esp bsp 2.0.8 --- Adafruit_MQTT.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ Adafruit_MQTT.h | 10 +++++++++- library.properties | 2 +- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/Adafruit_MQTT.cpp b/Adafruit_MQTT.cpp index da50bce..274f1fc 100644 --- a/Adafruit_MQTT.cpp +++ b/Adafruit_MQTT.cpp @@ -327,6 +327,47 @@ uint16_t Adafruit_MQTT::readFullPacket(uint8_t *buffer, uint16_t maxsize, return ((pbuff - buffer) + rlen); } +#ifdef ARDUINO_ARCH_ESP32 +const char *Adafruit_MQTT::connectErrorString(int8_t code) { + const char *statusMsg; + switch (code) { + case 1: + statusMsg = + "The Server does not support the level of the MQTT protocol requested"; + break; + case 2: + statusMsg = + "The Client identifier is correct UTF-8 but not allowed by the Server"; + break; + case 3: + statusMsg = "The MQTT service is unavailable"; + break; + case 4: + statusMsg = "The data in the user name or password is malformed"; + break; + case 5: + statusMsg = "Not authorized to connect"; + break; + case 6: + statusMsg = "Exceeded reconnect rate limit. Please try again later."; + break; + case 7: + statusMsg = "You have been banned from connecting. Please contact the MQTT " + "server administrator for more details."; + break; + case -1: + statusMsg = "Connection failed"; + break; + case -2: + statusMsg = "Failed to subscribe"; + break; + default: + statusMsg = "Unknown error"; + break; + } + return statusMsg; +} +#else const __FlashStringHelper *Adafruit_MQTT::connectErrorString(int8_t code) { switch (code) { case 1: @@ -354,6 +395,7 @@ const __FlashStringHelper *Adafruit_MQTT::connectErrorString(int8_t code) { return F("Unknown error"); } } +#endif bool Adafruit_MQTT::disconnect() { diff --git a/Adafruit_MQTT.h b/Adafruit_MQTT.h index 01b373b..f0257f1 100644 --- a/Adafruit_MQTT.h +++ b/Adafruit_MQTT.h @@ -166,11 +166,19 @@ class Adafruit_MQTT { int8_t connect(); int8_t connect(const char *user, const char *pass); - // Return a printable string version of the error code returned by +#ifdef ARDUINO_ARCH_ESP32 + // Returns a printable string version of the error code returned by + // connect(). Preprocessor due to breaking change within + // Arduino ESP32 BSP v2.0.8 + // see: https://github.com/espressif/arduino-esp32/pull/7941 + const char *connectErrorString(int8_t code); +#else + // Returns a printable string version of the error code returned by // connect(). This returns a __FlashStringHelper*, which points to a // string stored in flash, but can be directly passed to e.g. // Serial.println without any further processing. const __FlashStringHelper *connectErrorString(int8_t code); +#endif; // Sends MQTT disconnect packet and calls disconnectServer() bool disconnect(); diff --git a/library.properties b/library.properties index a2dbe7a..2bd2907 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Adafruit MQTT Library -version=2.5.2 +version=2.5.3 author=Adafruit maintainer=Adafruit sentence=MQTT library that supports the FONA, ESP8266, ESP32, Yun, and generic Arduino Client hardware. From a94f4d512e966718f466d4b97ecb129a67e38347 Mon Sep 17 00:00:00 2001 From: brentru Date: Fri, 21 Apr 2023 15:23:01 -0400 Subject: [PATCH 2/2] carter feedback implemented --- Adafruit_MQTT.cpp | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/Adafruit_MQTT.cpp b/Adafruit_MQTT.cpp index 274f1fc..c31d0c1 100644 --- a/Adafruit_MQTT.cpp +++ b/Adafruit_MQTT.cpp @@ -329,46 +329,9 @@ uint16_t Adafruit_MQTT::readFullPacket(uint8_t *buffer, uint16_t maxsize, #ifdef ARDUINO_ARCH_ESP32 const char *Adafruit_MQTT::connectErrorString(int8_t code) { - const char *statusMsg; - switch (code) { - case 1: - statusMsg = - "The Server does not support the level of the MQTT protocol requested"; - break; - case 2: - statusMsg = - "The Client identifier is correct UTF-8 but not allowed by the Server"; - break; - case 3: - statusMsg = "The MQTT service is unavailable"; - break; - case 4: - statusMsg = "The data in the user name or password is malformed"; - break; - case 5: - statusMsg = "Not authorized to connect"; - break; - case 6: - statusMsg = "Exceeded reconnect rate limit. Please try again later."; - break; - case 7: - statusMsg = "You have been banned from connecting. Please contact the MQTT " - "server administrator for more details."; - break; - case -1: - statusMsg = "Connection failed"; - break; - case -2: - statusMsg = "Failed to subscribe"; - break; - default: - statusMsg = "Unknown error"; - break; - } - return statusMsg; -} #else const __FlashStringHelper *Adafruit_MQTT::connectErrorString(int8_t code) { +#endif switch (code) { case 1: return F( @@ -395,7 +358,6 @@ const __FlashStringHelper *Adafruit_MQTT::connectErrorString(int8_t code) { return F("Unknown error"); } } -#endif bool Adafruit_MQTT::disconnect() {