Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Kura » how to receive MQTT messages using the DataService?
how to receive MQTT messages using the DataService? [message #1715163] Thu, 19 November 2015 17:20 Go to next message
Sabrina anirbas is currently offline Sabrina anirbasFriend
Messages: 45
Registered: April 2015
Member
Hello,

How can I receive the MQTT messages published on a specific topic? I can publish messages on the MQTT broker but I dont know how to receive messages?

Here is my component xml:

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" name="arduinoCommunicator">
   <implementation class="arduinoCommunicator.ArduinoCommunicator"/>
   <reference bind="setDataService" cardinality="1..1" interface="org.eclipse.kura.data.DataService" name="DataService" policy="static" unbind="unsetDataService"/>
   <service>
      <provide interface="org.eclipse.kura.data.DataServiceListener"/>
   </service>
</scr:component>



Here is my bundle activator class, I only kept the needed code, I implement the DataServiceListener, I subscribe to the topic on the onConnectionEstablished() and I imagine that I got the message on the function onMessageArrived, the problem is I don't see the logs that the subscription has been made and the function onMessageArrived() is not executed:

public class ArduinoCommunicator implements DataServiceListener {
public static DataService dataService; 


@Override
public void onConnectionEstablished() {
    String topic="egmkey/device2/cmd/PING";
    System.out.println("connection has been established");
    try {
        ArduinoCommunicator.dataService.subscribe(topic, 1);//egmkey/device2/cmd/PING
        System.out.println("subscription done to topic"+topic);
    } catch (KuraException e) {
        System.out.println("failed to subscribe: "+ e);
    }
}

@Override
    public void onMessageArrived(String topic, byte[] payload, int qos, boolean retained) {
        System.out.println("message received!!!!!!!!!!!!!!!!!!!!!!:"+topic);
    }
}



What have I missed to be able to receive MQTT messages using DataService on KURA? Thanks.
Re: how to receive MQTT messages using the DataService? [message #1715188 is a reply to message #1715163] Fri, 20 November 2015 01:12 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hello,

Is that the entire class? If so, you are missing the setDataService and unsetDataService methods. If that is only a part of the code, read below.

Can you please login to the OSGi console and provide the output of the 'ls' command? To do this, follow these steps:

1. Login to device running Kura
2. Issue command: telnet localhost 5002
3. At the OSGi prompt, type: ls

Also, check for errors in the log files (/var/log/kura.log and /var/log/kura-console.log).

Thanks,
--Dave
Re: how to receive MQTT messages using the DataService? [message #1715216 is a reply to message #1715188] Fri, 20 November 2015 10:24 Go to previous message
Benjamin Cabé is currently offline Benjamin CabéFriend
Messages: 201
Registered: July 2009
Location: Toulouse, France
Senior Member

Hi Sabrina,

I've answered your question on Stack Overflow. See http://stackoverflow.com/questions/33810131/kura-how-to-receive-mqtt-messages-using-the-dataservice/33811369#33811369


Previous Topic:Errors starting kura with greenhouse example
Next Topic:404 ProxyServlet: /kura
Goto Forum:
  


Current Time: Fri Apr 19 12:32:25 GMT 2024

Powered by FUDForum. Page generated in 0.01973 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top