Create new binding and install to karaf (OH2)

Hi there,

I experiment with my first very own binding for a Vallox KWL central venting unit (see openhab-vallox ).

I wonder how to deploy this thing to a running OH2 karaf installation.
I tried this:

  1. Create target platform
  2. Create tycho build for OSGI bundle build with maven
  3. run mvn package
  4. copy the resulting org.eclipse.smarthome.binding.vallox-1.0.0-SNAPSHOT.jar to my raspberry pi which runs the OH2 beta 4 to its karaf deploy directory
  5. in the log I get the exception below

What does it mean?
Is there another approach on developing new bindings? Should I clone the openhab2-addons and develop there and make a pr? The bundle is highly experiemental…

20:15:04.746 [ERROR] [apache.karaf.shell.support.ShellUtil] - Exception caught while executing command
org.apache.karaf.shell.support.MultiException: Error installing bundles:
        Unable to install bundle mvn:org.eclipse.smarthome.binding.vallox/1.0.0-SNAPSHOT
        at org.apache.karaf.shell.support.MultiException.throwIf(MultiException.java:61)
        at org.apache.karaf.bundle.command.Install.execute(Install.java:116)[39:org.apache.karaf.bundle.core:4.0.4]
        at org.apache.karaf.shell.impl.action.command.ActionCommand.execute(ActionCommand.java:83)[56:org.apache.karaf.shell.core:4.0.4]
        at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:67)[56:org.apache.karaf.shell.core:4.0.4]
        at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:87)[56:org.apache.karaf.shell.core:4.0.4]
        at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:480)[56:org.apache.karaf.shell.core:4.0.4]
        at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:406)[56:org.apache.karaf.shell.core:4.0.4]
        at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)[56:org.apache.karaf.shell.core:4.0.4]
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:182)[56:org.apache.karaf.shell.core:4.0.4]
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:119)[56:org.apache.karaf.shell.core:4.0.4]
        at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:94)[56:org.apache.karaf.shell.core:4.0.4]
        at org.apache.karaf.shell.impl.console.ConsoleSessionImpl.run(ConsoleSessionImpl.java:270)[56:org.apache.karaf.shell.core:4.0.4]
        at java.lang.Thread.run(Thread.java:745)[:1.8.0_65]
Caused by: java.lang.Exception: Unable to install bundle mvn:org.eclipse.smarthome.binding.vallox/1.0.0-SNAPSHOT
        at org.apache.karaf.bundle.command.Install.execute(Install.java:79)[39:org.apache.karaf.bundle.core:4.0.4]
        ... 11 more
Caused by: org.osgi.framework.BundleException: Error reading bundle content.
        at org.eclipse.osgi.storage.Storage.install(Storage.java:471)[org.eclipse.osgi-3.10.2.v20150203-1939.jar:]
        at org.eclipse.osgi.internal.framework.BundleContextImpl.installBundle(BundleContextImpl.java:146)[org.eclipse.osgi-3.10.2.v20150203-1939.jar:]
        at org.apache.karaf.bundle.command.Install.execute(Install.java:77)[39:org.apache.karaf.bundle.core:4.0.4]
        ... 11 more
Caused by: java.io.IOException: Error resolving artifact org.eclipse.smarthome.binding.vallox:1.0.0-SNAPSHOT:jar:LATEST
        at org.ops4j.pax.url.mvn.internal.AetherBasedResolver.resolve(AetherBasedResolver.java:630)[4:org.ops4j.pax.url.mvn:2.4.5]
        at org.ops4j.pax.url.mvn.internal.AetherBasedResolver.resolve(AetherBasedResolver.java:570)[4:org.ops4j.pax.url.mvn:2.4.5]
        at org.ops4j.pax.url.mvn.internal.AetherBasedResolver.resolve(AetherBasedResolver.java:548)[4:org.ops4j.pax.url.mvn:2.4.5]
        at org.ops4j.pax.url.mvn.internal.AetherBasedResolver.resolve(AetherBasedResolver.java:523)[4:org.ops4j.pax.url.mvn:2.4.5]
        at org.ops4j.pax.url.mvn.internal.Connection.getInputStream(Connection.java:123)[4:org.ops4j.pax.url.mvn:2.4.5]
        at org.eclipse.osgi.storage.Storage.install(Storage.java:469)[org.eclipse.osgi-3.10.2.v20150203-1939.jar:]
        ... 13 more
Caused by: shaded.org.eclipse.aether.resolution.VersionRangeResolutionException: No highest version found for org.eclipse.smarthome.binding.vallox:1.0.0-SNAPSHOT:jar:(0.0,]
        at org.ops4j.pax.url.mvn.internal.AetherBasedResolver.resolveLatestVersionRange(AetherBasedResolver.java:810)[4:org.ops4j.pax.url.mvn:2.4.5]
        at org.ops4j.pax.url.mvn.internal.AetherBasedResolver.resolve(AetherBasedResolver.java:614)[4:org.ops4j.pax.url.mvn:2.4.5]
        ... 18 more

Cheers,
Hauke

Hi,
I’m not very sure about this, since I only started developing in OSGi / openHAB recently as well, but it seems, that some version definition is missing somewhere (see Caused by: shaded.org.eclipse.aether.resolution.VersionRangeResolutionException: No highest version found for org.eclipse.smarthome.binding.vallox:1.0.0-SNAPSHOT:jar:(0.0,] ), I would suspect in the pom.xml.

On how to develop: To set up the dev environment, it seems to be easiest to follow the suggestions here: http://docs.openhab.org/developers/development/ide.html which will kind of automagically set a complete environment with an own instance of eclipse, git repos and so on, which seems reasonable on second sight because of the size and complexity of the project.
I then started a new project with an own repository within this environment and made sure the new binding bundle will get started via Run configurations > Plugins.
This way you can start, debug and stop a dev instance of openHAB 2 whenever you need it on your local machine.

Hope this helps…?

Cheers,
Hanno

Could be related to your Version information.
Version of a binding has to be in line (not higher) with the core., so for a ESH binding, It would be 0.9.0-SNAPSHOT, for a openHAB 2.0 binding, it would be 2.0-SNAPSHOT

Hi Hanno, thanks for the hints. However, I already developed successfully against the Eclipse Smart Home projects in my workspace and started it via run configuration. This worked in developing and debugging the bundle from within Eclipse quite fine.
However, the next step is to provide the bundle for test to someone else who has a running installation, e.g. of OH2.
I think the problem was that an ESH binding is not automatically running in an OH2 karaf container.

Thanks, @hmerk. That was finally it. I changed the version number of my binding from 1.0.0-SNAPSHOT to 2.0.0-SNAPSHOT and now it works fine in an OH2 karaf container.

Actually, so far I tested against an ESH workspace and started everything from a run configuration.

Still, I do not understand, why from an OSGi perspective, the start of the bundle should fail just due to a low version number. OH2 could not have any explicit dependency to my bundle… Is that some karaf property?

Sorry, I am neither an OSGI nor a karaf expert, just made a good guess,
So now your ESH binding uses version 2.0.0-SNAPSHOT ?
Did not think this should work. If you use archtype to setup a complete new binding for development, it will have version 0.9.0-SNAPSHOT.

Ah, ok, I did not realize that there is a difference between an OH and ESH binding. I started with an ESH binding and tested it successfully against a plain ESH setup from the Eclipse IDE. Now I changed the version and run it only in an OH2 context. So for debugging issues I guess I need to change the Eclipse IDE run configuration to start OH2 and not ESH. However, I understood that there is no run configuration for the OH2 karaf container…