Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Eclipse SmartHome » Management of the binding's webservice
Management of the binding's webservice [message #1720138] Thu, 14 January 2016 17:27 Go to next message
Jan Bender is currently offline Jan BenderFriend
Messages: 3
Registered: January 2016
Junior Member
As far as I know it is best practise to implement a bridge as "cloud connector". This bridge holds a webservice instance and connects to the webservice with credentials that are stored in the thing configuration.

More often than not all things (and other bridge) have to access the webservice as well in order to perform certain actions like sending new values to the device.

When a thing tries to access the webservice, it has to get the instance of the cloud connector in order to get the webservice. When you have a binding with a
bridge -> bridge -> thing
structure, the thing even has to refer to the first bridge which then has to get the webservice from the cloud connector.

We often find this quite cumbersome, especially for testing. Is this really the best solution for providing the things with a reference to the webservice? What is the reasoning behind implementing the webservice as a thing?
Re: Management of the binding's webservice [message #1720286 is a reply to message #1720138] Fri, 15 January 2016 22:54 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
Jan,

I am not sure I fully understand what you try to do, but you have in essence two options:
1. Integrate the web service into a Bridge, and have all Things pass trough commands to that Bridge. That can be done through an API you define adapted to the "cloud" you want to connect to
2. Integrate the web service directly into the Thing, if the web service itself is better represented by a Thing, e.g. physical device like

There are a few bindings out there you can look at to see how this can be done. For example, the Tesla binding uses web services to access Tesla's servers, and control the Tesla Model S vehicle. Here the web service is directly embedded in the ThingHandler. Another example is the Helios binding (see https://github.com/kgoderis/openhab2/blob/helios/addons/binding/org.openhab.binding.helios/src/main/java/org/openhab/binding/helios/handler/HeliosHandler213.java , as it not yet part of the official repo). And if you want a really wild example, have a look at https://github.com/kgoderis/openhab2/tree/atsadvanced/addons/binding/org.openhab.binding.atsadvanced , where Things use a Bridge that is both a web service client, as well as a web service end point that is called by a remote (proprietary) software that sits between the Handlers and the actual hardware.

In short, you do not have to implement a web service as a Thing, rather define the Thing (e.g. real world replication of a thing), and leverage the web service to talk to the device.

Regards
K
Re: Management of the binding's webservice [message #1720365 is a reply to message #1720286] Mon, 18 January 2016 08:34 Go to previous messageGo to next message
Jan Bender is currently offline Jan BenderFriend
Messages: 3
Registered: January 2016
Junior Member
Karel,

thanks for your response.

The first option is what we actually implement. In most cases we do have more than one thing so that integrating the webservice into a thing is not the best option. Instead our bridges contain an instance of a webservice and provide a getter method via an interface to obtain the webservice. So far so good.

Now let's assume the following case: We do have a "cloud connector" bridge. On this bridge the user can configure username and password as credentials for the webservice. The cloud connector will then initiate the webservice and login the user.
Furthermore we do have a bridge which represents a physical device, e.g. a gateway. If we want to send a command to that gateway, we need to obtain the webservice from the cloud connector.
And then we have our appliances which are additional things. If their thing handler 0swant to send a command to them, they must obtain their webservice from the bridge which then obtains it from the cloud connector.

In theory this works fine. And most of the time it works indeed. But there are some cases, especially during startup, in which the thing handler or not yet assigned (=null). When the thing tries to obtain the webservice before the bridge handler is instanciated, a NullPointerException occurs and it is not possible to send a command to the webservice. Can someone explain when thing handlers are assigned to the things and in which order?

My point is that a central instance for retrieving the webservice might be a good idea because a thing would be less dependend on other thing handlers.
Re: Management of the binding's webservice [message #1720369 is a reply to message #1720365] Mon, 18 January 2016 09:12 Go to previous messageGo to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
In this case, why don't you build a single bridge that represents the physical device, and that holds the web service stuff?

When in doubt, just try to mimic the real world/physical counterpart. The rest wil follow Wink
Re: Management of the binding's webservice [message #1720520 is a reply to message #1720369] Tue, 19 January 2016 07:43 Go to previous message
Andre Fuechsel is currently offline Andre FuechselFriend
Messages: 28
Registered: December 2015
Junior Member

I agree to Karel's suggestion. In addition, if you want to know in your ThingHandler, whether the bridge has been initialized or not, you only need to wait until bridgeHandlerInitialized has been called.
Previous Topic:What is the definition of a Thing!
Next Topic:Automation : how to get the result of the Actions that were executed by a Rule
Goto Forum:
  


Current Time: Fri Apr 26 05:37:20 GMT 2024

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

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

Back to the top