mqtt_set_credentials

Sets the user name and password.

C Language

int mqtt_set_credentials( MQTT handle, const char* username, const char* password);

ExampleMQTT Vuser Functions

Arguments

NameComments
handleThe MQTT client handle returned by mqtt_create.
usernameThe account name used to log on to the broker during connection.
passwordPassword or MQTT_NONE.

General

mqtt_set_credentials sets the user name and password of a broker server account. Call this function before mqtt_connect.

If invalid arguments are passed, the Vuser aborts, even if Continue on error is set.

Return Values

MQTT_SUCCESS or MQTT_FAIL

Parameterization

Standard parameterization is available for this function.

Exception: password cannot be parametrized (to avoid exposure in the output log).

Example

MQTT client = mqtt_create();

// Set credentials for authentication, store password in encrypted form

mqtt_set_credentials(client, "sensor1", lr_unmask("582c4eee24119befgffb"));

mqtt_connect(client, "tcp://test.broker.com:1883");