Skip to content
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

put AIO_AUTH_FAILED to use and fix AIO_ERROR_PRINT #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

markwal
Copy link

@markwal markwal commented Jan 27, 2023

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.

also, fix mqtt connect status error printing
@markwal
Copy link
Author

markwal commented Feb 7, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant