Skip to content

mqtt_connect does not generate a client.error if wrong username and/or password is provided #184

Description

@PitHerm

i tried your simple publisher example
and modified the parameter of mqtt_connect
from:

/* Send connection request to the broker. */
mqtt_connect(&client, client_id, NULL, NULL, 0, NULL, NULL, connect_flags, 400);

/* check that we don't have any errors */
if (client.error != MQTT_OK) {
    fprintf(stderr, "error: %s\n", mqtt_error_str(client.error));
    exit_example(EXIT_FAILURE, sockfd, NULL);
}

with the correct username and password to:
/* Send connection request to the broker. */
mqtt_connect(&client, client_id, NULL, NULL, 0, "paul", "paula", connect_flags, 400);

/* check that we don't have any errors */
if (client.error != MQTT_OK) {
    fprintf(stderr, "error: %s\n", mqtt_error_str(client.error));
    exit_example(EXIT_FAILURE, sockfd, NULL);
}

i received no errors and a connection which worked.
then i tried wrong username and wrong password

/* Send connection request to the broker. */
mqtt_connect(&client, client_id, NULL, NULL, 0, "otto", "otto", connect_flags, 400);

/* check that we don't have any errors */
if (client.error != MQTT_OK) {
    fprintf(stderr, "error: %s\n", mqtt_error_str(client.error));
    exit_example(EXIT_FAILURE, sockfd, NULL);
}

i received no errors and no connection to the broker was established
after pressing the ENTER key to send the time i received an error

./simple_publisher is ready to begin publishing the time.
Press ENTER to publish the current time.
Press CTRL-D (or any other key) to exit.

./simple_publisher published : "The time is 2023-10-25 06:55:24"
datetimeThe time is 2023-10-25 06:55:24
error: MQTT_ERROR_SOCKET_ERROR

if no connection was established to the broker there should be an error message.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions