How to publish MQTT messages with a Kura component?

Hi,

This seems to be a very simple question, but I’m stuck with that for a longer time. Also just googling “kura publish MQTT” brings no satisfying results.

I want to publish MQTT messages with an individual JSON format on an individual topic.

In docu is the heater demo bundle as an example publishing application. It uses CloudService / CloudPublisher for publishing the messages.

It can only publish on the topic: //heater/data and it can only publish KuraPayload with metrics which are always in the format:

{ 
  "metrics": { 
    "String name" : "Object Value",   
  } 
} 

Is there a way to change topic and metrics using CloudService? Or is CloudService only for communication with a remote Kura server and I must use DataService? But then I’m wondering why there is not a single example using DataService.

1 Like

Hi,
the best option would be to create your version of the cloud connector. So that you can change your format for the message.
If you want to use the default connector, you can try to use the data service API and provide directly the formatted message as a byte[]. But you will lose all the advantages provided by the publish API, support for Wires, etc.

If somebody found this thread and wants to use the DataService, there is a good example on how to publish MQTT messages via DataService:

1 Like