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

nrf9160 MQTT sample problem

Hello. I have problem with MQTT sample. I use NB-IoT network.

If I use public MQTT server without username and password, then MQTT sample ist works. But if I use MQTT server with username and password, then I have this response

Error 61 is for Connection refused, right ? I use this configure

And user name + password

It's good ? 

User name, password, port and IP, MQTT version for the server is good. I use another MQTT client with same configuration, and this is works.

This is output from the server, during connection from nrf9160

What am I doing wrong ? Thank you

  • Bug is maybe on the line with HOSTNAME.

    If I use hostname

    #define CONFIG_MQTT_BROKER_HOSTNAME "iot.eclipse.org"

    Then on the console is output

    ERROR: getaddrinfo failed 22
    ERROR: mqtt_connect -47
    

    And error 22 is for Invaid argument ? 

    But if I use IP address on the this format 

    #define CONFIG_MQTT_BROKER_HOSTNAME "198.41.30.241"

    Then I have on the console this 

    ***** Booting Zephyr OS v1.14.99-ncs1 *****
    The MQTT simple sample started
    LTE Link Connecting ...
    LTE Link Connected!
    IPv4 Address found 0xf11e29c6
    Exception occurred in Secure State
    ***** HARD FAULT *****
      Fault escalation (see below)
    ***** BUS FAULT *****
      Precise data bus error
      BFAR Address: 0x50008120
    ***** Hardware exception *****
    Current thread ID = 0x20020284
    Faulting instruction address = 0x1b8c0
    Fatal fault in ISR! Spinning...

    But why ? What I'm doing wrong ? 

  • It looks like an code optimization error. I must to add a print NAME and PASS  to the console, and then it works. Thank you. Please close ticket.

    static void client_init(struct mqtt_client *client)
    {
    	mqtt_client_init(client);
    
    	broker_init();
    
    	/* MQTT client configuration */
    	client->broker = &broker;
    	client->evt_cb = mqtt_evt_handler;
    	client->client_id.utf8 = (u8_t *)CONFIG_MQTT_CLIENT_ID;
    	client->client_id.size = strlen(CONFIG_MQTT_CLIENT_ID);
    	//client->password = NULL;
    	//client->user_name = NULL;
    
            struct mqtt_utf8 pass,name;
            pass.size = (u32_t) strlen("PASS");
            pass.utf8 =(u8_t*)"PASS";
            printk("pass: %d,%s\n",pass.size,pass.utf8);
            name.size = (u32_t) strlen("NAME");
            name.utf8 = (u8_t*)"NAME";
            printk("name: %d,%s\n",name.size,name.utf8);
    
            client->password = &pass;
            client->user_name = &name;
    	client->protocol_version = MQTT_VERSION_3_1_1;
    
    	/* MQTT buffers configuration */
    	client->rx_buf = rx_buffer;
    	client->rx_buf_size = sizeof(rx_buffer);
    	client->tx_buf = tx_buffer;
    	client->tx_buf_size = sizeof(tx_buffer);
    
    	/* MQTT transport configuration */
    	client->transport.type = MQTT_TRANSPORT_NON_SECURE;
    }

Related