Connecting to Private MQTT broker

Dear Nordic Team, 

I am currently using nrf9160 for MQTT transmission. I have successfully connected to a public MQTT broker which is HiveMQ and transmitted data to HiveMQ. The next step I am trying to achieve is to transfer data to a private MQTT broker which will require a username and password. May I know how I configure these parameters in the prj.conf file? The image below is my configuration for HiveMQ. 

Parents Reply
  • Hello, 

    Looking at the last project that you have attached, there is no username or password added to client_init().

    Both are configured to NULL.

    Have a look at the sample zephyr\samples\net\cloud\mqtt_azure. I.e. this shows how to configure the username and password. The sample uses KConfig to define the Kconfig symbols which you can add value to in prj.conf. In client_init() the following is added:

    //add to top off client_init()
    static struct mqtt_utf8 password;
    static struct mqtt_utf8 username;
    
    
    client->client_id.utf8 = (uint8_t *)MQTT_CLIENTID;
    client->client_id.size = strlen(MQTT_CLIENTID);
    
    password.utf8 = (uint8_t *)CONFIG_SAMPLE_CLOUD_AZURE_PASSWORD;
    password.size = strlen(CONFIG_SAMPLE_CLOUD_AZURE_PASSWORD);
    
    client->password = &password;
    
    username.utf8 = (uint8_t *)CONFIG_SAMPLE_CLOUD_AZURE_USERNAME;
    username.size = strlen(CONFIG_SAMPLE_CLOUD_AZURE_USERNAME);
    
    client->user_name = &username;

    This can be used as an example to get your project up and running.

Children
Related