This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

mqtt_simple example: mqtt_connect error -12

Hello everyone,

I started an evaluation for the Nordic Thingy91 using the "mqtt_simple" example from the SDK1.6.0 version. The Thingy91 is HW-version 1.4.0. Programming is done in SES V5.50c.

The standard-example works (which connects to mqtt.eclipseprojects.io).

I tried to connect to another server without a username and a password and it also worked as intended. I did this by changing the "MQTT_BROKER_HOSTNAME" in Kconfig and the "CONFIG_MQTT_BROKER_HOSTNAME" in prj.conf. I know, only the prj.conf needs to be changed, I changed both to be sure.

Then I changed the host a server which need a specific username or a password. TLS is not used.

I added the username and password in the main.c:

The result is  "mqtt_connect -12":

I found this topic (mqtt connect error - Nordic Q&A - Nordic DevZone - Nordic DevZone (nordicsemi.com))  and increased the buffer size in the prj.conf and Kconfig to 512:

CONFIG_MQTT_MESSAGE_BUFFER_SIZE=512
CONFIG_MQTT_PAYLOAD_BUFFER_SIZE=512

In the mentioned topic, the connect error -12 was solved by increasing buffer sizes. For me, the problem persisted, as shown in the second picture.

What can I do to find the error?

With other MQTT Clients I can connect to the server using the same username and password,

Parents Reply Children
  • Dear Øyvind,

    I set the username and password as suggested by you in the main.c. 

    After starting the debug and running the program, the serial console shows:

    After a minute, the debugger stops here:

    When I press "Continue Execution" in SES the first time, the debugger stops at the same code position immediately. When pressing "Continue Execution" again a second time, a minute later, the debugger stops at the same position again. When I continue execution a third time, the debugger stops there again, but the serial console is updated:

    At this point, the error seems to be reproducible.

    I am happy to try out more ideas, just let me know,

    Chris

  • Hey Chris, 

    Sorry, I forgot to clarify that both password and user_name are structs with a pointer and a size  Ref. zephyr\include\net\mqtt.h

    /** @brief Abstracts UTF-8 encoded strings. */
    struct mqtt_utf8 {
    	const uint8_t *utf8;       /**< Pointer to UTF-8 string. */
    	uint32_t size;             /**< Size of UTF string, in bytes. */
    };

    Please retry with the following, tested by our developer and should work with your application:

     

    struct mqtt_utf8 password = {
     .utf8 = "password",
     .size = strlen("password")
     };
     
     struct mqtt_utf8 username = {
     .utf8 = "username",
     .size = strlen("username")
     };
     
     /* MQTT client configuration */
     client->broker = &broker;
     client->evt_cb = mqtt_evt_handler;
     client->client_id.utf8 = client_id_get();
     client->client_id.size = strlen(client->client_id.utf8);
     client->password = &password;
     client->user_name = &username;
     client->protocol_version = MQTT_VERSION_3_1_1;

    Kind regards,
    Øyvind

Related