Home » Eclipse Projects » Kura » Kura Configurable Components(REST API for Kura configurable components)
Kura Configurable Components [message #1724522] |
Wed, 24 February 2016 06:05  |
Eclipse User |
|
|
|
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 #1726926 is a reply to message #1726507] |
Thu, 17 March 2016 10:01   |
Eclipse User |
|
|
|
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
|
|
| | | |
Goto Forum:
Current Time: Sat Aug 30 18:55:56 EDT 2025
Powered by FUDForum. Page generated in 0.05851 seconds
|