Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Kura » Configure broker URL automatically(Can I configure the MQTT broker URL without web admin?)
icon5.gif  Configure broker URL automatically [message #1746512] Mon, 31 October 2016 13:23 Go to next message
Nyiri András is currently offline Nyiri AndrásFriend
Messages: 14
Registered: September 2016
Junior Member
Hello,
I want to install Kura on multiple Raspberrys automatically.
Can I configure the MqttDataTransport broker URL somehow in a configuration file before starting Kura? I can use the MQTT calls to configure services after this has been configured...
I'm thinking maybe I should upload a previously created snapshot to its snapshots directory, but haven't tried yet. Could that work? Whats exactly stored inside these snapshots?


Thanks!

EDIT:
Tryed out the snapshots, the problem is that I need to configure the broker URL at runtime, so a fixed configuration snapshot is not good for me and it looks like I can't dynamically change the IP in the snapshot because I can not deserialize it.

[Updated on: Mon, 31 October 2016 14:03]

Report message to a moderator

Re: Configure broker URL automatically [message #1746599 is a reply to message #1746512] Tue, 01 November 2016 15:08 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hello,

You should be able to accomplish what you want with snapshots. What problem are you seeing? Note, the networking part could be a little tricky. I would recommend setting up one Raspberry Pi as you want, then use that snapshot file as your baseline.

Thanks,
--Dave
Re: Configure broker URL automatically [message #1746671 is a reply to message #1746599] Wed, 02 November 2016 18:01 Go to previous messageGo to next message
Nyiri András is currently offline Nyiri AndrásFriend
Messages: 14
Registered: September 2016
Junior Member
Yes, what you recommended was the first think I tried but unfortunately it is not good enough for me, because I have to configure all PIs differently, like adding different MQTT client ID (I know the default MAC is unique but I need something different in my case), and also the MQTT broker URL have to be configurable because it is different in every environment. The problem is that these snapshot files doesn't look editable.

If I write a HTTP servlet, place it in the right directory for Kura to automatically start it and after started I provide the necessary configuration parameters via it's REST API, I could change the MqttDataTransport configuration this way dynamically, right?

[Updated on: Wed, 02 November 2016 18:04]

Report message to a moderator

Re: Configure broker URL automatically [message #1746805 is a reply to message #1746671] Fri, 04 November 2016 19:09 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hello,

The snapshot files are not directly editable from the command line, but you can download one through the Kura web UI (Settings->Snapshots). From here you could make the changes you need and copy them to the /opt/eclipse/kura/data/snapshots directory making sure you remove any existing snapshots and naming it snapshot-0.xml. On restart, Kura should pull in your changes.

Yes, you could also use REST APIs if you have that working in Kura. The easiest way to do this is to use the ConfigurationService [1].

[1] http://download.eclipse.org/kura/releases/2.0.0/docs/apidocs/org/eclipse/kura/configuration/ConfigurationService.html

Thanks,
--Dave
Re: Configure broker URL automatically [message #1747360 is a reply to message #1746805] Sun, 13 November 2016 18:43 Go to previous messageGo to next message
Nyiri András is currently offline Nyiri AndrásFriend
Messages: 14
Registered: September 2016
Junior Member
Thank you for you answer.
Now I'm trying to deploy a simple web bundle which would receive the new MQTT configurations via REST and set it via ConfigurationService.
I'm looking at the org.eclipse.kura.web project as an example for this but trying a simplified approach. Unfortunately it looks like my bundles activate method is not called.
My OSGI-INF/web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" 
               activate="activate"
               configuration-policy="require"
               deactivate="deactivate"
               modified="updated"
               name="my.project.RestConfigurator">
   <implementation class="my.project.RestConfigurator"/>
   <property name="servlet.alias.root" value="/configurator"/>
   <reference name="HttpService" 
              bind="setHttpService"
              unbind="unsetHttpService"
              interface="org.osgi.service.http.HttpService"/>   
   <property name="app.root" type="String" value="/configurator"/>
   <property name="service.pid" type="String" value="my.project.RestConfigurator"/>
   <service>
      <provide interface="my.project.RestConfigurator"/>
   </service>   
</scr:component>

MANIFEST.MF:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: my.project
Bundle-SymbolicName: my.project;singleton:=true
Bundle-Version: 1.0.0.qualifier
Service-Component: OSGI-INF/*.xml
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: javax.servlet;version="2.6.0",
 javax.servlet.http;version="2.6.0",
 org.eclipse.kura.configuration;version="[1.0,2.0)",
 org.eclipse.kura.configuration.metatype;version="[1.0,2.0)",
 org.eclipse.kura.core.configuration;version="[1.0,2.0)",
 org.eclipse.kura.core.configuration.metatype;version="[1.0,2.0)",
 org.eclipse.kura.core.configuration.util;version="[1.0,2.0)",
 org.eclipse.kura.core.net.util;version="[1.0,2.0)",
 org.osgi.framework;version="1.7.0",
 org.osgi.service.http,
 org.slf4j;version="1.6.4"

I also have these methods in my activator class:
public void setHttpService(HttpService httpService) {
		s_logger.info("Setting HttpService...");
		this.m_httpService = httpService;
	}

	public void unsetHttpService(HttpService httpService) {
		s_logger.info("Unsetting HttpService...");
		this.m_httpService = null;
	}


Does anyone have any idea what could cause that my activator method is not called (I know its not because I have a comment in the beginning of it)?
Also, the setHttpService method is not called...

[Updated on: Sun, 13 November 2016 18:44]

Report message to a moderator

Re: Configure broker URL automatically [message #1747913 is a reply to message #1747360] Wed, 16 November 2016 17:34 Go to previous message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hello,

Sorry for the delayed response. It looks like you are using "lazy activation" for your service. This means the service won't start until some other service requests it. If you want your service to start immediately, add the following to your component XML:

enabled="true" immediate="true"


Most of the Kura examples use this [1], so you can look at this for reference.

[1] https://github.com/eclipse/kura/blob/develop/kura/examples/org.eclipse.kura.example.ble.tisensortag/OSGI-INF/bleExample.xml

Thanks,
--Dave
Previous Topic:Problem with Advertising Scan of a Beacon
Next Topic:How to reduce kura boot time
Goto Forum:
  


Current Time: Fri Apr 26 13:44:48 GMT 2024

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

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

Back to the top