1
0
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:
Matthijs Kooijman
2015-07-02 13:01:05 +02:00
parent 73f5be4e5c
commit 6879df86f6
5 changed files with 25 additions and 34 deletions

View File

@ -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