How to add username and password to MQTT_Publisher


Brenton Chetty <brent7984@...>
 

Hi, I am trying to get "mqtt_publisher" working with Eclipse Kapua using "qemu_x86".
I managed to get mqtt_publisher working with a simple mosquitto client, however I cannot connect to Kapua because I need to add a username and password.

How do I add username/password to the publisher?
I already tried directly inputting the values in "client_init" (client->password = "kapua-password";)
Using wireshark, it shows that the username and password flag has not been set.

With thanks
Brenton


Lubos, Robert
 

Hi Brenton,

 

Generally your approach is correct to set the username/password in the `client_init()` function of the sample, but please note that these fields are not plain C strings but rather `struct mqtt_utf8` pointers. So for instance for username you should create username struct (note the `size` parameter does count the NULL terminator) :

static struct mqtt_utf8 username = {

     .utf8 = "kapua-password",

     .size = sizeof("kapua-password") - 1

};

 

And then use it in the `client_init()`:

client->user_name = &username;

 

The same applies to the password field.

 

Regards,

Robert

 

From: devel@... <devel@...> On Behalf Of Brenton Chetty via lists.zephyrproject.org
Sent: wtorek, 8 czerwca 2021 20:40
To: devel@...
Subject: [Zephyr-devel] How to add username and password to MQTT_Publisher

 

Hi, I am trying to get "mqtt_publisher" working with Eclipse Kapua using "qemu_x86".

I managed to get mqtt_publisher working with a simple mosquitto client, however I cannot connect to Kapua because I need to add a username and password.

 

How do I add username/password to the publisher?

I already tried directly inputting the values in "client_init" (client->password = "kapua-password";)

Using wireshark, it shows that the username and password flag has not been set.

 

With thanks

Brenton