Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Eclipse SmartHome » How to read / save Binding config(How to read / save Binding config)
How to read / save Binding config [message #1775395] Sun, 29 October 2017 12:36 Go to next message
Martin K is currently offline Martin KFriend
Messages: 2
Registered: October 2017
Junior Member
Hey all,

after searching for quite a while I was not able to determine how to save and load config data for a binding.

The background is that I only want to add things once the user is successfully logged in to a page.
This works fine for the first time the plugin is started.
After entering the credentials things will be discovered and added to the inbox. After a reboot though things are still present but not configured.
I don't want to configure each thing seperately but use the factoryhandler instead as a single point of configuration.

So far my code looks like this.
I added a config section to my binding.xml
        <parameter name="username" type="text">
            <description>Username, used @</description>
        <parameter name="password" type="text">
            <description>Password, used @</description>

And my factory:
public abstract class NedapPowerRouterHandler extends BaseThingHandler
    protected void activate(ComponentContext componentContext) {

        Dictionary<String, Object> properties = componentContext.getProperties();
        String user = (String) properties.get("username");
        String pass = (String) properties.get("password");

        if (StringUtils.isEmpty(user) || StringUtils.isEmpty(pass)) {
            logger.warn("Username / Password needs to be configured!");
        logger.debug("Binding credentials updated with {} / {}", user, pass);


        try {
            logger.debug("Login to was {} ", routerClient.isUserLoggedIn());
        } catch (ClientProtocolException e) {
        } catch (IOException e) {

        if (routerClient.isUserLoggedIn()) {
        } else {
            logger.error("Wrong credentials provided or not reachable");


Now this method is called each time I configure the binding but how do I read config date I set previously?
For Classes extending BaseThingHandler there is a getConfigAs() method available.
Is there something similiar for the factory or am I totally wrong and against the pattern which should normally be used?

Kind regards

Re: How to read / save Binding config [message #1775439 is a reply to message #1775395] Mon, 30 October 2017 08:57 Go to previous messageGo to next message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 673
Registered: December 2011
Senior Member
I do not really understand your code. The snippet above "extends BaseThingHandler" and "overrides activate", a method that does not exist at all in BaseThingHandler.

All there is to do is to implement "initialize()" in your handler and check the credentials in there. If all is fine, go ahead and discover other devices, add channels to the current Thing or do whatever you like. If the credentials are incorrect, set the Thing status to OFFLINE / configuration error.
Re: How to read / save Binding config [message #1775591 is a reply to message #1775439] Wed, 01 November 2017 21:20 Go to previous messageGo to next message
Martin K is currently offline Martin KFriend
Messages: 2
Registered: October 2017
Junior Member

thank you for your fast response.
I made a mistake during copy and paste..
It's meant to be
public class NedapPowerRouterHandlerFactory extends BaseThingHandlerFactory

Trying to explain my problem again with different words:

  1. Binding is loaded the very first time (no credentials for are set) My autodiscovery service will stop immediately since no credentials are provided so far.
  2. Once credentials are entered in the binding a connection to the previously mentioned website will be established and available features are checked
  3. Depending on the features (some people have batteries attached to their solar panels, some don't..) the discovery service will be started again and things are added accordingly to the inbox

It works fine this way. But after I restart project within the Dev-Environment (eclipse ide)
Things are still present but the binding lost the previously entered credentials...
Since my NedapPowerRouterHandlerFactory contains the httpclient which establishes the connection to gather data, all things won't be able to retrieve any data.
I use only one http-connection for all things which is located in
the HandlerFactory
All scheduled jobs from the things which retrieve data just call
    public static NedapHttpClient getRouterClient() {
        return routerClient;

and work on this instance.

Thats why I ask for how to save and load configuration settings within the
HandlerFactory and not the ThingHandler.

Hopefully I explained my problem a bit more precise.
Sorry for asking such dumb questions but I want to share my work with the community and I don't want the user to configure credentials in each thing seperatly

Re: How to read / save Binding config [message #1775783 is a reply to message #1775591] Mon, 06 November 2017 10:12 Go to previous message
Henning Treu is currently offline Henning TreuFriend
Messages: 44
Registered: April 2017
Hi Martin,

first of all I´m looking forward to your contribution!

Regarding your question I will first try to describe your current problem with vanishing configurations and then suggest a solution which addresses the modelling of your binding and things:

When configuring a binding through PaperUI (which I assume you do) the values are handed over to OSGi ConfigAdmin and stored on disk. In the IDE setup however the OSGi runtime is started with the
which will clean the ConfigAdmin settings on every startup.

From a modelling perspective you may implement a BridgeHandler and configure a Bridge thing with the credentials for a account. The Bridge thing may then create an instance of the http client from the given credentials. Other ThingHandlers and the auto discovery may then use the http client from the bridge thing to communicate with This approach also allows users to connect to multiple accounts from a single ESH instance by setting up multiple bridges.

Let me know if you have further questions. Cheers.
Previous Topic:Stuck on finalizing installation
Next Topic:Questions about best practices implementing bindings
Goto Forum:

Current Time: Mon Jun 24 16:11:16 GMT 2024

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

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

Back to the top