Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Kura » Mqtt subscribe problem(Mqtt subscribe problem)
icon5.gif  Mqtt subscribe problem [message #1731497] Fri, 06 May 2016 08:45 Go to next message
Shiao Jon is currently offline Shiao JonFriend
Messages: 13
Registered: May 2016
Junior Member
I'm install Kura 1.3.0 on Rasbperry Pi B+。
When I use Java to send request to mqttserver (iot.eclipse.org:1883) ,
I have no any response from mqttserver , and I don't know what wrong.
When I run below code , no occur messageArrived.
but I can use it to receive sensor's data by change topic (Greenhouse project).
I had try to change MQTT Protocol Version 3.1 and 3.11 , but it's no help.

what is the problem ?

NCU102552018 is my topic.context.account-name , and Kura_1 is my Client ID in kura MqttDataTransport configuration.

Code :
try {

			String Cid = MqttClient.generateClientId();
 			MqttClient mqttClient = new MqttClient(BROKER_URI, Cid, new MemoryPersistence());
			mqttClient.setCallback(new MqttCallback() {

				@Override
				public void messageArrived(String topic, MqttMessage message) throws Exception {

					try {

						System.out.println(topic + "--" + new String(message.getPayload()));

					} catch (RuntimeException e) {
						e.printStackTrace();
					}
				}

				@Override
				public void deliveryComplete(IMqttDeliveryToken token) {
					// not used
				}

				@Override
				public void connectionLost(Throwable cause) {
					System.out.println("Connection lost: " +         cause.getLocalizedMessage());
				}
			});
	        MqttConnectOptions connOpt = new MqttConnectOptions();
		 connOpt.setCleanSession(true);
		 connOpt.setKeepAliveInterval(30);
		 connOpt.setUserName("NCU102552018_broker");
		 connOpt.setPassword("********".toCharArray());
		 mqttClient.connect(connOpt);
		 mqttClient.subscribe("$EDC/NCU102552018/Kura_1/CONF-V1/#");
		 
		} catch (MqttException e) {
			e.printStackTrace();
		}
Re: Mqtt subscribe problem [message #1731521 is a reply to message #1731497] Fri, 06 May 2016 12:39 Go to previous messageGo to next message
Said Ucar is currently offline Said UcarFriend
Messages: 56
Registered: June 2015
Member
Hi Shiao,

The first thing, I can suggest you to use Kura CloudService to manage MqTT Connection. It is better solution I beleive. The second one is, AFAIK, the topic prefixes in kura added automatically. So, you don't need to add "$EDC........" prefixes when trying to subscribe to topic. Please check the 'kura.log' file to understand whats going on when your bundle start and connect to MqTT Server.

Thanks,
Said.
Re: Mqtt subscribe problem [message #1731541 is a reply to message #1731521] Fri, 06 May 2016 15:47 Go to previous messageGo to next message
Shiao Jon is currently offline Shiao JonFriend
Messages: 13
Registered: May 2016
Junior Member
Thanks , Said.

I just use paho-mqtt to subscribe "$EDC...." , will it not work ?
I can receive some message from mqttserver when I subscribe "$EDC/account-name/client id/#" by change configuration on kura web UI.

If I want to use Kura CloudService , that I should build Kura Developer's Workspace first ?
Re: Mqtt subscribe problem [message #1731590 is a reply to message #1731541] Sat, 07 May 2016 10:55 Go to previous messageGo to next message
Said Ucar is currently offline Said UcarFriend
Messages: 56
Registered: June 2015
Member
Hi Shiao,

You don't need to build developers workspace, it is already built and you can download here [1]. I strongly recommend you to use eclipse as a development environment. Import dev workspace an create a new project for your project. You can also check this [2] example project to learn how to use Services. Since CloudService is provided by Kura itself, it is compatible with the WEB UI settings etc. So you don't need to provide prefixes when subscribing a topic in your bundle. It will get prefixes from your WEB UI Settings (like device-name etc.).

Thanks,
Said.

[1] = https://s3.amazonaws.com/kura_downloads/user_workspace/release/1.4.0/user_workspace_archive_1.4.0.zip
[2] = http://eclipse.github.io/kura/doc/serial-example.html

[Updated on: Sat, 07 May 2016 10:56]

Report message to a moderator

Re: Mqtt subscribe problem [message #1731599 is a reply to message #1731590] Sat, 07 May 2016 15:36 Go to previous messageGo to next message
Shiao Jon is currently offline Shiao JonFriend
Messages: 13
Registered: May 2016
Junior Member
Hi , Said Ucar
Thanks !! It's very useful , but I want to remote setting Kura configurations without Kura Web UI.
What is I need ?
Should I use "Publishing Application" in Kura Doc ?

[Updated on: Sat, 07 May 2016 16:14]

Report message to a moderator

Re: Mqtt subscribe problem [message #1731739 is a reply to message #1731599] Mon, 09 May 2016 17:20 Go to previous messageGo to next message
Said Ucar is currently offline Said UcarFriend
Messages: 56
Registered: June 2015
Member
Hi Shiao,

What do you mean "remote setting Kura config." ? If you use CloudService, you have to feed information (broker-url, port-name etc.) from Web UI. If you want to give this information to your application in source code (I don't recommend), you can use Paho Library. There is an example code in project home page. If you use external library (like Paho), you have to include this library *.jar file within your bundle.

Publishing Application is really good example, I strongly recommend you to look at it. But it is simply publish sensor data over mqtt periodically. I don't see any relation between Kura Settings and Publishing Application directly.

Thanks,
Said.
Re: Mqtt subscribe problem [message #1731917 is a reply to message #1731739] Wed, 11 May 2016 02:34 Go to previous messageGo to next message
Shiao Jon is currently offline Shiao JonFriend
Messages: 13
Registered: May 2016
Junior Member
Hi , Said
I try to do "MQTT Request/Response Example"[2] via "kura-mqtt-client-utility"[1] .
But when I receive request.id , I don't know how to read data .
Do you know any example about this ?
When I slove this provlem then I can try to do "Remote OSGi ConfigurationAdmin Interactions via MQTT"[2] , it is I need.

https://github.com/amitjoy/Kura-MQTT-Client-Utility [1]
https://eclipse.github.io/kura/ref/mqtt-namespace.html [2]
Re: Mqtt subscribe problem [message #1732329 is a reply to message #1731917] Mon, 16 May 2016 02:43 Go to previous message
Shiao Jon is currently offline Shiao JonFriend
Messages: 13
Registered: May 2016
Junior Member
Hi , All
I solved it , thanks a lot.
Previous Topic:Sending a PUT request
Next Topic:what is the Minimum Harware Requirements for Kura
Goto Forum:
  


Current Time: Fri Apr 26 20:26:27 GMT 2024

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

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

Back to the top