Skip to main content



      Home
Home » Eclipse Projects » Kura » Kura Configurable Components(REST API for Kura configurable components)
Kura Configurable Components [message #1724522] Wed, 24 February 2016 06:05 Go to next message
Eclipse UserFriend
Hi everyone,

I am still in the early stages of understanding Kura, and so far so good. I have managed to deploy a simple application into Raspberry pi 2 that connects and streams data into the cloud using both CloudService and DataService APIs. Both approaches work fine. My question is: Is there a different configuration mechanism (like REST API) within Kura that can be used to configure services like MqttDataTransport, CloudService and application specific parameters (e.g, topic, publish rate, etc.) apart from Kura web user-interface? I would like to configure them programmatically.

Information presented on this webpage suggests that there is a RESTFull way of doing this, but I cannot figure out how, and I couldn't find any example that demonstrate that. I have also come across tools like Eclipse Ponte and Apache ActiveMQ that provide REST APIs for interacting with Mqqt servers. But they are not exactly what I need as using them, you can only interact with application specific parameters.

Regards,
Saleh
Re: Kura Configurable Components [message #1724524 is a reply to message #1724522] Wed, 24 February 2016 06:29 Go to previous messageGo to next message
Eclipse UserFriend
Hi Saleh,

There is a library for MqTT called Paho. You can import Paho library to your project and use what you desire. I don't know to change parameters for internal services (CloudService etc.) , but this library can help you.

If there is a way to change parameters in code, of course would be better.

Regards,
Said.
Re: Kura Configurable Components [message #1724627 is a reply to message #1724524] Wed, 24 February 2016 17:01 Go to previous messageGo to next message
Eclipse UserFriend
Hi Mustafa,

Thanks for mentioning Paho. Actually, I have used Paho as a mqtt client but I don't think it can be used as an alternative to web user-interface. I have tried using it to configure application specific configurable parameters. But like Eclipse Ponte, Paho can only interacts with mqtt server.

Regards,
Saleh
Re: Kura Configurable Components [message #1724846 is a reply to message #1724627] Fri, 26 February 2016 09:11 Go to previous messageGo to next message
Eclipse UserFriend
Hello Saleh,

You found the proper documentation for performing REST type device management. There is an abstract class Cloudlet that you will need to extend to access this functionality. Please note, this is still leveraging MQTT for communication, but provides a REST style wrapper for specific MQTT traffic. I would refer here [1] for more information. You can also see an example of Kura using this feature here [2].

Let me know if you have further questions.

[1] http://download.eclipse.org/kura/releases/1.3.0/docs/apidocs/org/eclipse/kura/cloud/Cloudlet.html
[2] https://github.com/eclipse/kura/blob/develop/kura/org.eclipse.kura.core.cloud/src/main/java/org/eclipse/kura/cloud/app/command/CommandCloudApp.java

Thanks,
--Dave
Re: Kura Configurable Components [message #1726507 is a reply to message #1724846] Mon, 14 March 2016 07:15 Go to previous messageGo to next message
Eclipse UserFriend
Good morning Dave,

Thank you for your reply. I'm also very interested in the ability to control Kura programmatically, and would be interested to know if there are any usage examples of CommandCloudApp being used to achieve an example operation? This would be a huge help to extend this for other functionalities. I plan to assist building out an endpoint for much of Kura's management functionality and will be happy to contribute this back to the project.

All the best,
Matt
Re: Kura Configurable Components [message #1726926 is a reply to message #1726507] Thu, 17 March 2016 10:01 Go to previous messageGo to next message
Eclipse UserFriend
Hi everyone,

I have tried to extend the Cloudlet class as mentioned by David above, and then just override the doGet method (the logic is not complete yet). My code is as shown below:

public class CloudletServiceKura extends Cloudlet implements ConfigurableComponent{
	private static final Logger logger = LoggerFactory.getLogger(CloudletServiceKura.class);
	public static final String appId = "CONF-V1";
	private Map<String, Object> properties;
	
	private CloudService  cloudService;

	public static final String RESOURCE_CONFIGURATIONS = "configurations";	

	public CloudletServiceKura() {
		super(appId);			
	}
	
	
	@Override
	public void setCloudService(CloudService cloudService) {
		if (this.cloudService == null) {
			super.setCloudService(this.cloudService = cloudService);
		}
	}
	
	@Override
	public void unsetCloudService(CloudService cloudService) {
		if (this.cloudService == cloudService) 
			super.setCloudService(this.cloudService = null);
	}
	
	protected void activate(ComponentContext componentContext, Map<String, Object> props) {
		logger.info("Activating \" {} ...", appId );
		this.properties = props;
		for (String s : properties.keySet()) {
			logger.info("Activate - "+s+": "+props.get(s));
		}		
		super.setCloudService(cloudService);
		super.activate(componentContext);
		logger.info("Activating \" {} \" done", appId);
	}
	
	protected void deactivate(ComponentContext componentContext) 
	{
		if (getCloudApplicationClient() != null) {
			super.deactivate(componentContext);
		}
	}
	
	public void updated(Map<String, Object> props) {
		this.properties = props;		
		logger.info("Updating \" {} \"...", appId);
		for (String s : properties.keySet()) {
			logger.info("Update - "+s+": "+properties.get(s));
		}
		logger.info("Updating \" {} \" done", appId);	
	}

	@Override
	protected void doGet(CloudletTopic reqTopic, KuraRequestPayload reqPayload,
			KuraResponsePayload respPayload) throws KuraException {
		
		String [] resources = reqTopic.getResources();
			
		if (resources == null || resources.length == 0) {
			logger.error("Bad request topic: {}", reqTopic.toString()); 
			logger.error("Expected one resource but found {}", resources !=null ? resources.length: "none");
			respPayload.setResponseCode(KuraResponsePayload.RESPONSE_CODE_BAD_REQUEST);
			return;
		}
			
		logger.info("Get request received from topic \"{}\"", resources[0]);
		
		if (resources[0].equals(RESOURCE_CONFIGURATIONS)) {
			//doGetConfigurations(reqTopic, reqPayload, respPayload);
		} else {
			logger.error("Bad request topic: {}", reqTopic.toString());
			logger.error("Cannot find resource with name: {}", resources[0]);
			respPayload.setResponseCode(KuraResponsePayload.RESPONSE_CODE_NOTFOUND);
			return;
		}
	}
	
	@Override
	public void onConnectionEstablished() {
		logger.info("Cloud Client: Connection has been established");
		try {
			this.getCloudApplicationClient().subscribe("#", 0);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Override
	public void onControlMessageArrived(String deviceId, String appTopic, KuraPayload msg, int qos, boolean retain) {
		super.onControlMessageArrived(deviceId, appTopic, msg, qos, retain);
	}
	
	@Override
	public void onMessageArrived(String deviceId, String appTopic, KuraPayload msg, int qos, boolean retain) {
		if (msg.getBody() == null)
			return;	
		logger.info("message \"{}\" arrived on topic \"{}\"", new String(msg.getBody()), appTopic);
	}
}


I am also using two tools to interact with my mqtt server i.e. mqtt-spy to monitor and subscribing to topic , and Kura MQTT client utility (by Amit Kumar) to send requests (kura request payload).

The problem I am having is any message sent prefixed with $ is not being delivered. I am following the instructions on http://eclipse.github.io/kura/ref/mqtt-namespace.html. So my request is in the form of :
$EDC/kura/local/CONF-V1/GET/configurations
Request ID: REQUEST_EAGIGLBGK817NDH7C86QONJE76
Requester Client ID: CLIENT_JJJAODSAPV7AHI3UG1CO0EH1HP


And nothing also is happening if i subscribe to the reply topic:
$EDC/kura/CLIENT_JJJAODSAPV7AHI3UG1CO0EH1HP/CONF-V1/REPLY/REQUEST_EAGIGLBGK817NDH7C86QONJE76


What am I doing wrong here? my application is running in emulation mode without any error. In the webpage mentioned above it specify that:

Quote:
To ensure the delivery of request messages, applications that support request/response conversations via MQTT should subscribe to the following topic on startup:
$EDC/account_name/client_id/app_id/#


Does this has to be done inside the onConnectionEstablished method? I am already subscribing to kura/local/CONF-V1/# inside this method.

Regards
Saleh
Re: Kura Configurable Components [message #1727217 is a reply to message #1726926] Mon, 21 March 2016 07:53 Go to previous messageGo to next message
Eclipse UserFriend
OK, I have spent one week trying to figure out and solve this problem. Now I can say that it is finally resolved.

The problem was, recently I changed my mqtt server from Mosquitto to ActiveMQ without checking it version. It happened that I have been using mqtt v3.1.1 and this version doesn't like the dollar sign ($). After reverting to 3.1, everything works fine. I am quoting from Kura documentation here:

Quote:
NOTE: While Eclipse Kura currently requires "$EDC" as the prefix for control topics, this prefix may change in the future for the following reasons:

MQTT 3.1.1 discourages the use of topic starting with "$" for application purposes.

As a binding of LWM2M over MQTT is taking shape, it would makes sense to use a topic prefix for management messages like "LWM2M" or similar abbreviations e.g. "LW2", "LWM".


Amit's Kura MQTT Client Utility is also so helpful. Thanks. Now I can send a request to $EDC/kura/local/CONF-V1/GET/configurations with RequestId:REQUEST_01, and Requester Client ID:CLIENT_O1 and subscribe to $EDC/kura/CLIENT_01/CONF-V1/REPLY/REQUEST_01, and receive a bunch of information in xml file.

Thanks.
Saleh
Re: Kura Configurable Components [message #1732239 is a reply to message #1727217] Fri, 13 May 2016 12:54 Go to previous messageGo to next message
Eclipse UserFriend
Can you tell me how to receive a bunch of information in xml file ?
Re: Kura Configurable Components [message #1732327 is a reply to message #1732239] Sun, 15 May 2016 22:42 Go to previous message
Eclipse UserFriend
Hi , All
I solved it , thanks a lot.
Previous Topic:Kura WebUi giving 404
Next Topic:Sending a PUT request
Goto Forum:
  


Current Time: Sat Aug 30 18:55:50 EDT 2025

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

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

Back to the top