You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
If I'm not mistaken, this is because mqtt_connect seems to only queue the CONNECT message without actually sending it.
It's the first mqtt_sync call after the mqtt_connect that will really send the pending CONNECT request.
So, when mqtt_connect returns, the library cannot possibly yet know if the username/password are correct.
You can see that connect failed if mqtt_sync returns either:
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);
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);
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);
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.
The text was updated successfully, but these errors were encountered: