Hello,

I can't make the above MQTT example work by changing the WLAN and MQTT Broker settings in the file 'AppController.h'. I get the foolowing error message:

...

INFO | XDK DEVICE 1: WLANPersonalWPA2Connect : Connected to WPA network successfully. 
 INFO | XDK DEVICE 1: MqttEventHandler : Event - 0
 INFO | XDK DEVICE 1: MQTT_Subsribe : Subscribing to topic: XDK110/out, Qos: 1
 INFO | XDK DEVICE 1: MqttEventHandler : Event - 8
 INFO | XDK DEVICE 1: MqttEventHandler : Event - 15
 INFO | XDK DEVICE 1: MqttEventHandler : Event - 14
 INFO | XDK DEVICE 1: AppMQTTSubscribeCB : #1, Incoming Message:
 INFO | XDK DEVICE 1:     Topic: XDK110/out
 INFO | XDK DEVICE 1:     Payload: 
 INFO | XDK DEVICE 1: """
 INFO | XDK DEVICE 1: Environmental Data -
 INFO | XDK DEVICE 1:     Humidity : 59
 INFO | XDK DEVICE 1:     Pressure : 97666
 INFO | XDK DEVICE 1:     Temperature : 22.211000ø
 INFO | XDK DEVICE 1: """
 INFO | XDK DEVICE 1: Error in XDK110 Application package.
 INFO | XDK DEVICE 1:     Package ID: 153    Module ID: 36    Severity code: 2    Error code: 122
 INFO | XDK DEVICE 1: Error in XDK110 Application package.
 INFO | XDK DEVICE 1:     Package ID: 153    Module ID: 36    Severity code: 2    Error code: 122

...

I am currently using the 'iot.eclipse.org' broker with port 1883 (no security), so I kept the 'APP_MQTT_SECURE_ENABLE' as 0. Would that be my mistake? When connecting through other devices I normally include username and password, but these options are not available to be eddited in the file.

In addition, I have noticed that only the Humidity, Pressure and Temperature readings are available? How can I add more sensors (light and battery level for example)?

 

Thank you very much !

Eduardo

0 (0 Votes)
RE: Can't get MQTT connected through "SendDataOverMQTT" example
Answer
11/5/18 5:32 PM as a reply to Eduardo Baleeiro.
Dear Eduardo,

As far as I can observe, the return values from the MQTT event handler are all indicating correct behavior of the example. You also successfully receive the first subscription on the first published MQTT message.

Only the afterwards sent messages are throwing the error message, which indicates the publish process failure. This might have multiple reasons.
How often do you get this behavior?

In regards to your configuration, APP_MQTT_SECURE_ENABLE only enables an encrypted connection to the eclipse MQTT broker. Could you please provide the information how you configured the option APP_MQTT_DATA_PUBLISH_PERIODICITY ?

In regards to the extension of additional sensor data, you need to extend the publishDataFormat in line 299 and the added sensor data in line 352 in the implementation file AppController.c .

For the light sensor, you only need to enable it within the global struct SensorSetup at line 110 in the implementation file AppController.c . Adding its sensor data can be done with the same procedure like with the environmental sensor.

In regards to the battery level, you need to add its complete implementation with the interface BatteryMontor.h , which means initializing it in the function AppControllerSetup() and adding its reading function BatteryMonitor_MeasureSignal() into AppControllerFire() .
Everything else is similar to the light sensor.

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: Can't get MQTT connected through "SendDataOverMQTT" example
Answer
11/5/18 8:17 PM as a reply to Franjo Stjepandic.

Hello Franjo,

Thanks a lot for your valuebles hints. I will try to add more sensors as soon as I manage to get an stable MQTT transmission.

To you questions:

. Always when I restart the XDK it transmits the data and then I get permanently the previously mentioned error messages.

. I have uninstalled the workbench and started with the MQTT example from scretch, setting the 

APP_MQTT_DATA_PUBLISH_PERIODICITY

value as "10000" (previously was "1000" - miliseconds I suppose). Now I get the following result on debbuging:

 INFO | XDK DEVICE 1: WLANPersonalWPA2Connect : Connected to WPA network successfully. 
 INFO | XDK DEVICE 1: MqttEventHandler : Event - 0
 INFO | XDK DEVICE 1: MQTT_Subsribe : Subscribing to topic: XDK110/out, Qos: 1
 INFO | XDK DEVICE 1: MqttEventHandler : Event - 8
 INFO | XDK DEVICE 1: MqttEventHandler : Event - 15
 INFO | XDK DEVICE 1: MqttEventHandler : Event - 14
 INFO | XDK DEVICE 1: AppMQTTSubscribeCB : #1, Incoming Message:
 INFO | XDK DEVICE 1:     Topic: XDK110/out
 INFO | XDK DEVICE 1:     Payload: 
 INFO | XDK DEVICE 1: """
 INFO | XDK DEVICE 1: Environmental Data -
 INFO | XDK DEVICE 1:     Humidity : 53
 INFO | XDK DEVICE 1:     Pressure : 96424
 INFO | XDK DEVICE 1:     Temperature : 24.191000ø
 INFO | XDK DEVICE 1: """
 INFO | XDK DEVICE 1: MqttEventHandler : Event - 15
 INFO | XDK DEVICE 1: MqttEventHandler : Event - 14
 INFO | XDK DEVICE 1: AppMQTTSubscribeCB : #2, Incoming Message:
 INFO | XDK DEVICE 1:     Topic: XDK110/out
 INFO | XDK DEVICE 1:     Payload: 
 INFO | XDK DEVICE 1: """
 INFO | XDK DEVICE 1: Environmental Data -
 INFO | XDK DEVICE 1:     Humidity : 52
 INFO | XDK DEVICE 1:     Pressure : 96425
 INFO | XDK DEVICE 1:     Temperature : 24.301000ø
 INFO | XDK DEVICE 1: """
 INFO | XDK DEVICE 1: MqttEventHandler : Event - 15
 INFO | XDK DEVICE 1: MqttEventHandler : Event - 14
 INFO | XDK DEVICE 1: AppMQTTSubscribeCB : #3, Incoming Message:
 INFO | XDK DEVICE 1:     Topic: XDK110/out
 INFO | XDK DEVICE 1:     Payload: 
 INFO | XDK DEVICE 1: """
 INFO | XDK DEVICE 1: Environmental Data -
 INFO | XDK DEVICE 1:     Humidity : 51
 INFO | XDK DEVICE 1:     Pressure : 96424
 INFO | XDK DEVICE 1:     Temperature : 24.421000ø
 INFO | XDK DEVICE 1: """
 INFO | XDK DEVICE 1: asserted at Filename 3rd-party/ServalStack/src/Msg/TcpMsg.c , line no  91 
 INFO | XDK DEVICE 1: Error in XDK110 Application package.
 INFO | XDK DEVICE 1:     Package ID: 153    Module ID: 36    Severity code: 2    Error code: 122
 INFO | XDK DEVICE 1: Error in XDK110 Application package.
 INFO | XDK DEVICE 1:     Package ID: 153    Module ID: 36    Severity code: 2    Error code: 122

 

Could you please give me further hints? 

What should I do if I want (or need) to connect to the MQTT broker with username and password?

 

Thanks a lot !

Eduardo

0 (0 Votes)
RE: Can't get MQTT connected through "SendDataOverMQTT" example
Answer
11/7/18 3:58 PM as a reply to Eduardo Baleeiro.
Hello Eduardo,

thank you for posting the changed output.

In regards of transmitting a username and password to the MQTT broker, the latest version of the Serval MQTT library does integrate the functionality to add a username and password but would require a small configuration within the source code.

First, I recommend to take a view at the MQTT article within the XDK Knowledgebase . The article can be accessed after a free registration and be found by choosing Protocols and MQTT in the left menu. The interesting part starts from the section Advanced API Setup and Overview , reaches down to the full code example at the bottom of the article.

This full code example implements the earlier mentioned Serval MQTT library and only needs to be complemented by adding two new object parameters (username and password) from the struct MqttSession_S and the right conversion to the function configSetConnectData() , so it looks basically like the code below.
 

void configSetConnectData(void) {
static char *device_name = "YOUR_XDK_DEVICE";
session_ptr->MQTTVersion = 4;
session_ptr->keepAliveInterval = 100;
session_ptr->cleanSession = true;
session_ptr->will.haveWill = false;
StringDescr_T device_name_descr;
StringDescr_wrap(&device_name_descr, device_name);
session_ptr->clientID = device_name_descr;
// username and password --------------------------------------
static char * device_uname = "YOUR_USERNAME";
static char * device_pw = "YOUR_PASSWORD";
// conversion of username and password ------------------------
StringDescr_T uname;
StringDescr_set(&uname, device_uname, strlen(device_uname));
session_ptr->username = uname;
StringDescr_T pw;
StringDescr_set(&pw, device_pw, strlen(device_pw));
session_ptr->password = pw;
//-------------------------------------------------------------
}


A different solution would be the use of a third party lib, such as MQTT paho to your XDK application and to use it instead of the Serval MQTT implementation.

Another good looking solution is the XDK2MAM project, which is guided in detail on the linked page and is worth the view.

Regarding your current issue, there might be just the right solution in this earlier community ticket to solve the assertion problem.

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: Can't get MQTT connected through "SendDataOverMQTT" example
Answer
11/11/18 8:16 PM as a reply to Franjo Stjepandic.

Hello Franjo,

Thanks once again for your hints ! After implementing the solution you suggested from an old ticket the MQTT connection was stable. The problem was, when I tried to connect from a Raspberry Pi with Node-Red to listen to the topic the connection got broken. Is there any restrition on number of different connections?

Regarding your sample code for connecting with user ans password, in which file do I have to implement it? Should I just include the code and change parameters or should I include as part of an existing function?

Sorry for the basic questions. I have been struglling with the XDK also because of my poor knowleadge of C programming...

Thanks,

Eduardo

0 (0 Votes)
RE: Can't get MQTT connected through "SendDataOverMQTT" example
Answer
11/12/18 5:03 PM as a reply to Eduardo Baleeiro.
Hello Eduardo,

You are welcome. I am glad, you were able to establish a stable connection, at least with one device.

Usually the state of the publishing connection from your XDK to the MQTT broker should not be affected by an external subscriber device like your raspberry pi.

Please check, if they share the same device ID, which is to send to the broker and be sure the keep alive time interval at both sides, the pi and the broker, is not too short.

Actually, at first, I recommend you to try hitting your goal of publishing data to the MQTT broker without external subscriber devices like your raspberry pi. You still can expand the scenario later, if everything works fine.

Regarding your connection to the MQTT broker with the use of username and password:
  1. Please open the MQTT article from the XDK Knowledgebase, as described in the earlier post.
  2. Click on the table of content's chapter Advanced API Setup and Overview.
  3. Open the XDK Workbench and create a new XDKApplicationTemplate project.
  4. Open the AppController.c file from your new project.
  5. For better understanding, I recommend to read through the Knowledgebases MQTT article by starting from the earlier mentioned chapter Advanced API Setup and Overview and reading down to the bottom of the page.
  6. If you are done reading and learned about the background functionality behind this example, copy the whole Advanced Full Code Example code and replace it with the existing code of your new project's file AppController.c.
  7. Copy the code snippet from my previous post, which contains the implementation of transmitting username and password to the MQTT broker and replace this whole function configSetConnectData() with the existing one.
  8. Edit your broker connection, MQTT username and password and also your Wi-Fi's SSID and password within the AppController.c file.
  9. Build and flash the project, then you should be ready to go.
If you struggle with the language C, I hardly recommend you to start with the Knowledgebase chapter Getting Started and take the time to learn the language from the root by using tutorials and guides.

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Votes)