How to incorporate username and password for the MQTT broker authentcation in mqtt sample

I am using samples/net/mqtt for MQTT connection. I have a custom MQTT broker with SSL/TLS encryption which also requires username and password for authentication. I am confused as to where to add this.

I am using actnius icarus ns

sdk 2.3.0

Parents
  • Hi,

    You can set the username in the struct mqtt_helper_conn_params conn_params in connect_work_fn in transport.c.

    However, the mqtt_helper library does not support setting a password. So you will have to add that to the mqtt_helper_conn_params struct and client_connect function in the mqtt_helper library.

    Best regards,

    Didrik

  • What do you mean by adding password to the mqtt_conn_params struct and client_connect function, where can I locate the mqtt_helper library? could you please elaborate more with an example? I am new to using Nrf9160. Do I need to make changes anywhere else?

    P.S: I cannot locate the file mqtt_helper.h anywhere in the sdk or the project

  • User_PP said:
    Do I need to make changes anywhere else?

    Yes, you will need to add password handling to the mqtt_helper library.

    mqtt_helper.h can be found here: nrf\include\net\mqtt_helper.h

    mqtt_helper.c can be found here: nrf\subsys\net\lib\mqtt_helper\mqtt_helper.c

    The library already handles the username, and both the username and password are handled the same way by the underlying MQTT client library, so you should be able to just copy what the mqtt_helper library does with the username.

Reply
  • User_PP said:
    Do I need to make changes anywhere else?

    Yes, you will need to add password handling to the mqtt_helper library.

    mqtt_helper.h can be found here: nrf\include\net\mqtt_helper.h

    mqtt_helper.c can be found here: nrf\subsys\net\lib\mqtt_helper\mqtt_helper.c

    The library already handles the username, and both the username and password are handled the same way by the underlying MQTT client library, so you should be able to just copy what the mqtt_helper library does with the username.

Children
Related