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,550 points
91 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,100 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 24 in IoT (Internet of Things) by Upasana
• 7,680 points
18 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,260 points
526 views
0 votes
0 answers

MQTT-Google Cloud pub/sub connection status!

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

Jul 19, 2018 in IoT (Internet of Things) by Bharani
• 4,550 points
103 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,260 points
201 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,260 points

reshown Jul 6, 2018 by Vardhan 284 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,260 points
68 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,260 points
167 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,260 points
81 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 29, 2018 in IoT (Internet of Things) by DataKing99
• 8,100 points
25 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.