Skip to content

Fix connectErrorString return type for ESP-32 BSP 2.0.8 #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Adafruit_MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,11 @@ 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) {
#else

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it work to just continue returning a F() for all cases? And then only add preproc around the function line to set the specific return type to match what F() ends up being. That would let the function code itself remain unchanged.

Copy link
Member Author

@brentru brentru Apr 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@caternuson I do not think so as F() provides different return types in different architectures. Could you give me a quick example of what you mean? Having trouble visualizing this solution.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this maybe?

#ifdef ARDUINO_ARCH_ESP32
const char *Adafruit_MQTT::connectErrorString(int8_t code) {
#else
const __FlashStringHelper *Adafruit_MQTT::connectErrorString(int8_t code) {
#endif
  switch (code) {
  case 1:
    return F(
        "The Server does not support the level of the MQTT protocol requested");

Basically just changing the return type as needed for whatever F() ends up being on a given platform.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in a94f4d5, requesting a re-review before I make the same change to the Arduino Adafruit IO Library.

const __FlashStringHelper *Adafruit_MQTT::connectErrorString(int8_t code) {
#endif
switch (code) {
case 1:
return F(
Expand Down
10 changes: 9 additions & 1 deletion Adafruit_MQTT.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Adafruit MQTT Library
version=2.5.2
version=2.5.3
author=Adafruit
maintainer=Adafruit <[email protected]>
sentence=MQTT library that supports the FONA, ESP8266, ESP32, Yun, and generic Arduino Client hardware.
Expand Down