1
0
mirror of https://github.com/adafruit/Adafruit_MQTT_Library.git synced 2025-07-29 02:02:00 +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

@ -122,18 +122,7 @@ void loop() {
Serial.println(F("Connecting to MQTT..."));
int8_t ret, retries = 5;
while (retries && (ret = mqtt.connect()) != 0) {
switch (ret) {
case 1: Serial.println(F("Wrong protocol")); break;
case 2: Serial.println(F("ID rejected")); break;
case 3: Serial.println(F("Server unavail")); break;
case 4: Serial.println(F("Bad user/pass")); break;
case 5: Serial.println(F("Not authed")); break;
case 6: Serial.println(F("Failed to subscribe")); break;
default: {
Serial.println(F("Connection failed"));
break;
}
}
Serial.println(mqtt.connectErrorString(ret));
Serial.println(F("Retrying MQTT connection"));
retries--;
if (retries == 0) halt("Resetting system");