Data from a subscribe on MQTT example
Antwort
15.10.18 17:29

Hello guys,

I'm running MQTT example, which is already implemented the published from sensors on XDK.

On my application, a personal computer publishes on a Topic of the broker.

The XDK must subscribe this topic, and based on the value, take an action.

How can I access the Sub data from a topic, using the XDK Api? What is the specific function that returns the value from the subscription? Must I write this one?

I'm getting some problems with that.

Thank you.

0 (0 Stimmen)
RE: Data from a subscribe on MQTT example
Antwort
16.10.18 15:12 als Antwort auf Jose Santos Junior.
Dear Jose,

Welcome you to the XDK community.

Am I right to assume that you referred to the SendDataOverMQTT example when you wrote MQTT example ? If this is the case, please note that this example already integrates the functionality to subscribe from the same topic as the sensor values are published to.

The specific struct to configure the parameters for subscribing a topic is the variable MqttSubscribeInfo . This variable of the type MQTT_Subcribe_T in context of the SendDataOverMQTT example is also used to configure the way in which incoming data gets processed.

For that, the configured function AppMQTTSubscribeCB() is used as a callback function, where further functionality can be implemented to take action, based on the subscribed data.

For the case you did not refer to the SendDataOverMQTT example, I would ask you to go more into detail about the example you are currently using.

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

Kind regards,
Franjo
0 (0 Stimmen)
RE: Data from a subscribe on MQTT example
Antwort
17.10.18 16:20 als Antwort auf Franjo Stjepandic.

Thank you for your answer, Mr. Stjepandic.

Yes! I asked about SendDataOverMQTT example. I have not found the subscription payloas, because i was developing with version 3.3 from Workbench.

With the actual version,  I got some problems to flash the code on XDK. 

 

0 (0 Stimmen)
RE: Data from a subscribe on MQTT example
Antwort
18.10.18 11:08 als Antwort auf Jose Santos Junior.

I've fixed the problem.

But I have realized that the function is a callback AppMQTTSubscribeCB for the incoming publish. Am I wrong?

I need to make a sub on a topic, take an action with the subscribed data, i can't publish on the same topic after, because it is beeing populated by other device.

Do we have any implemented on example any function to do that ?

Thank you

0 (0 Stimmen)
RE: Data from a subscribe on MQTT example
Antwort
18.10.18 17:23 als Antwort auf Jose Santos Junior.
Dear Jose,
I am glad to hear that you fixed the issue yourself.
The AppMQTTSubscribeCB() function is called upon receiving incoming MQTT message. The function copies the message into buffers and prints the topic and payload.
In regards to the republishing, there are, unfortunately, no examples available. This means, that you have to implement the functionality by yourself.

As starting point, I would recommend taking a look at the MQTT article at the XDK knowledgebase . Please note that a registration is necessary beforehand to access the content on the XDK knowledgebase.

There you can find the article within the protocols slider on the left side. Epecially the parts of publishing via MQTT should be interesting for you.
Additional, I recommend checking the implementation file MQTT.c in the XDK-Workbench, which you can find here:

SDK > xdk110 > Common > source

There line 592 and the following lines are important, since those will give you an insight in the implementation of MQTT_PublishToTopic .

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

Kind regards,
Franjo
0 (0 Stimmen)