SendDataOverMQTT username/password?
Antwort
05.04.19 11:01

Hi,

I would like to use username/password when connecting to a MQTT Borker.

Looking at the latest sample of the sample SendDataOverMQTT I miss an option to specify username/password for mqtt login.

In the sample I can follow the AppController.c invoking

Retcode_T MQTT_ConnectToBroker(MQTT_Connect_T * mqttConnect, uint32_t timeout)

Inside of MQTT_ConnectToBroker an internal MqttSession is generated. This MqttSession allows to specify:

	/// username for the connection, see MQTT spec 3.1.3.4.
	StringDescr_T username;
	/// password for the connection, see MQTT spec 3.1.3.5
	StringDescr_T password;

But this is not accessible from MQTT_ConnectToBroker.

Do I have to write my on implementation of MQTT_ConnectToBroker?

Retcode_T MQTT_ConnectToBroker(MQTT_Connect_T * mqttConnect, uint32_t timeout, MQTT_Credentials_T * cred)
{
...

    if (RC_OK != Mqtt_initializeInternalSession(&MqttSession))
	{
		retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_MQTT_INIT_INTERNAL_SESSION_FAILED);
	}
	MqttSession.username = cred->username;
	MqttSession.password = cred->password;
...
}

Will this work? Can I modify the MqttSession after its initialization?

 

--Christof

 

+1 (1 Stimme)
RE: SendDataOverMQTT username/password?
Antwort
08.04.19 06:11 als Antwort auf Christof Strack.

Hi Christof

You can add username and password inxdk110/Apps/SendDataOverMQTT/source/ AppController.h

#define WLAN_SSID                           "YourWifiNetwork"

#define WLAN_PSK                            "YourWifiPassword"

Thanks

Priyashi

0 (0 Stimmen)
RE: SendDataOverMQTT username/password?
Antwort
08.04.19 08:33 als Antwort auf Priyashi Yadav.

Hi, Priyashi,

I meant the credentials for the mqtt session.

You pointed out how to set the credentials for the WIFI network, this is different.

 

--Christof

0 (0 Stimmen)
RE: SendDataOverMQTT username/password?
Antwort
11.04.19 09:15 als Antwort auf Christof Strack.

Hello Christof,

a little while ago i implemented a MQTT API for the XDK. You can connect your MQTT client to a public or custom MQTT broker with username and password.

To do that i recommend to use the API "Serval_Mqtt.h". You can find the API in the following path:

YourProject/SDK/xdk110/Libraries/ServalStack/3rd-party/ServalStack/api/ServalMqtt.h

This API allows you to implement the username and password functionality.

Best regards,

Christian

0 (0 Stimmen)
RE: SendDataOverMQTT username/password?
Antwort
27.08.19 10:22 als Antwort auf Christian Köhler.

Hi Christian,

I tried to use secured MQTT over workbench 3.6.  I found the API as you suggested.

----------------------------------------------------------------------------------------------------

struct MqttSession_S

{

/// Version of MQTT to be used 3 for 3.1, 4 for 3.1.1. See MQTT spec 3.1.2.2 Protocol Level.

uint8_t MQTTVersion;

/// Identifier of the client, see MQTT spec 3.1.3.1.

StringDescr_T clientID;

/// username for the connection, see MQTT spec 3.1.3.4.

StringDescr_T username;

/// password for the connection, see MQTT spec 3.1.3.5

StringDescr_T password;

 

Where and how do I set the username and password?

Do I need to change the #define APP_MQTT_SECURE_ENABLE  0 in AppController.h to 1 too?

I am very new to RTOS programming. Please advise.

Best regards,

Sran S.

0 (0 Stimmen)