Changing message format in KURA MQTT cloud client

0 votes

I'm running Eclipse Kura with a MQTT cloud client to publish messages. But, now I need to change that format of my MQTT messages. 

Like, in this following format:  #account-name/#client-id/#API-ID/topic  

what if I didn't want the account name or the client id in it?

Any suggessions??? Thanks!

Jul 24, 2018 in IoT (Internet of Things) by Bharani
• 4,660 points
1,184 views

1 answer to this question.

0 votes

The Eclipse Kura communicates with a MQTT broker using any one of the following two mechanisms:
1 --> Using CloudClient
2 --> Using DataService

I'm guessing the CloudClient you are using might have some restrictions imposed on the topic namespace segregation due to the hierarchy of the communication structure between the devices and the gateways.

If you'd rather have your own namespace segregation, I'd advice using the DataService to directly define your own MQTT namespace for both publishing and receiving MQTT messages.
You'll need to use the OSGi framework and direct it to inject the instance into your component class like in this following sample code:
public class MyComponent {
    private DataService m_dataService;

    public void setDataService(DataService dataService) {
        m_dataService = dataService;
    }
    public void unsetDataService(DataService dataService) {
        m_dataService = null;
    }
    // activate() deactivate() and all required methods
    public void publish() {
        String topic = "your/topic";
        String payload = "Hello!";
        int qos = 0;
        boolean retain = false;
        try {
            m_dataService.publish(topic, payload.getBytes(), qos, retain, 2);
            s_logger.info("Publish ok");
        } catch (Exception e) {
            s_logger.error("Error while publishing", e);
        }
    }
}

Now, inside your component OSGI-INF/mycomponent.xml, you'll need to set the methods that you want the OSGi to call for injecting the DataService. You can do that by adding the following:
<reference name="DataService"
    interface="org.eclipse.kura.data.DataService"
    bind="setDataService"
    unbind="unsetDataService"
    cardinality="1..1"
    policy="static" />

After you've done the above, you should be able to pass your topic to the method DataService.publish(...). And, make sure to convert Payloads to byte[] arrays. 

answered Jul 29, 2018 by DataKing99
• 8,250 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer

MQTT server sending a message to a client declaring unauthorization

It would return a CONNACK packet with ...READ MORE

answered Apr 25, 2019 in IoT (Internet of Things) by Upasana
• 8,620 points
1,229 views
0 votes
1 answer

Faster communication between two ESP8266 in client-server setup

Try following. Server loop void loop() { // ...READ MORE

answered Jul 13, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points
6,859 views
0 votes
0 answers

MQTT-Google Cloud pub/sub connection status!

Please help! So, I have a couple of ...READ MORE

Jul 20, 2018 in IoT (Internet of Things) by Bharani
• 4,660 points
853 views
0 votes
1 answer

AWS IoT login from android MQTT client using IAM is not working

Seeing your comments and questions. I had ...READ MORE

answered Jul 24, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points
2,366 views
0 votes
1 answer

MQTT protocol connection error

Ok so you need two libraries to ...READ MORE

answered Jul 6, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points

reshown Jul 6, 2018 by Vardhan 3,097 views
0 votes
1 answer

Mosquitto 1.4.2 Websocket support

down vote In the dir mosquitto-1.4.X edit the ...READ MORE

answered Jul 9, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points
1,450 views
0 votes
1 answer

IoT request response protocol

Based on your requirement of a light ...READ MORE

answered Jul 13, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points
1,864 views
0 votes
1 answer

What is the maximum message length for a MQTT broker?

It's not entirely clear what you're asking ...READ MORE

answered Jul 17, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points
9,483 views
0 votes
1 answer

RPMs for IoT Agents of Backend Device Management GE in FIWARE IoT ecosystem

The RPMs for IDAS component are availaible. ...READ MORE

answered Jul 30, 2018 in IoT (Internet of Things) by DataKing99
• 8,250 points
831 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP