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
  • Hello, 

    Error -12 means #define ENOMEM 12 /* Not enough core */ and usually seen when there are no sockets available. Could you please share your project i.e. prj.conf and main.c? Please remember to change username and password in the file.

    Kind regards,
    Øyvind

  • Dear Øyvind,

    I would like to add an information to avoid confusion:

    in my uploaded main.c, the user is entered in the password field and the password is entered in the user field. In the main.c that I use for building, the correct information is entered. Nevertheless, the output is the same:



    Have a good day,

    Chris

  • Hi Chris, 

    I've discussed the issue with one of our developers. You need to add the size of each as well:

    client->password->utf8 = "user";
    client->password->size = strlen("user");
    client->user_name->utf8 = "password";
    client->user_name->size = strlen("password");

    Let me know how that works for you. 

    Kind regards,
    Øyvind

  • 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

Reply
  • 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

Children
  • 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