You've already forked Adafruit_MQTT_Library
mirror of
https://github.com/adafruit/Adafruit_MQTT_Library.git
synced 2025-06-13 10:01:31 +03:00
Add Adfruit_MQTT::connectErrorString() method
This easily allows printing error messages without having to hard-code return values in the sketch and makes the example sketches a bit more concise.
This commit is contained in:
@ -137,17 +137,7 @@ void MQTT_connect() {
|
||||
Serial.print("Connecting to MQTT... ");
|
||||
|
||||
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
|
||||
switch (ret) {
|
||||
case 1: Serial.println("Wrong protocol"); break;
|
||||
case 2: Serial.println("ID rejected"); break;
|
||||
case 3: Serial.println("Server unavailable"); break;
|
||||
case 4: Serial.println("Bad user/password"); break;
|
||||
case 5: Serial.println("Not authenticated"); break;
|
||||
case 6: Serial.println("Failed to subscribe"); break;
|
||||
default: Serial.print("Couldn't connect to server, code: ");
|
||||
Serial.println(ret);
|
||||
break;
|
||||
}
|
||||
Serial.println(mqtt.connectErrorString(ret));
|
||||
Serial.println("Retrying MQTT connection in 5 seconds...");
|
||||
mqtt.disconnect();
|
||||
delay(5000); // wait 5 seconds
|
||||
|
Reference in New Issue
Block a user