Open markwal opened 1 year ago
TL/DR of above:
Before change code passes AIO status code to _mqtt->connectErrorString() which clearly expects a mqtt->connect() return value.
Before change, the library can never return AIO_AUTH_FAILED because it always translates auth failure to AIO_CONNECT_FAILED.
So, if you're implementing AIO for the first time and you've got your auth wrong, you're missing an easily available clue. Or if auth changes for some reason.
This change distinguishes a failure due to authorization from other connection failure reasons. The source defines AIO_AUTH_FAILED but can't return it under any circumstances (only reference is in AdafruitIO::statusText()).
The changes are in AdafruitIO::mqttStatus which is where the mqtt->connect() is called and it's return result is translated to an AIO_ status result.
The main risk to this change is if library client's test for AIO_CONNECT_FAILED precisely. This seems unlikely since the library can return other failures (like AIO_DISCONNECTED here and other status's elsewhere in the code). The examples use < AIO_CONNECTED to mean failure or >= AIO_CONNECTED to be success.
The other part of this change is to make the AIO_ERROR_PRINT's in this routine more useful. There are two problems with the ones added by 0074998:
First, it uses an AIO status code to send to the routine that expects an mqtt status code (connectErrorString) and it only sends that when it is known to be AIO_CONNECT_FAILED which always produces the result "Unknown".
Second, it prints the result when a quick return is to occur and no change in outcome possible (rather than when the error occurred).
I've moved the ERROR_PRINT's to where the error occurred and used the correct status code to generate the string.