Struggling with MQTT in development of new binding

Hi all!

I’m currently for the first time trying to develop a binding to control my Ziggo Next set-top-box.
As a lot of communication is running over MQTT with a Liberty Global server, but as the login credentials have to be periodically re-requested over HTTP, I couldn’t figure out a good way to do this using existing bindings.
So therefore I first made something work in Python scripts that I called from rules or ExecBinding items, but that’s far from ideal.

So, not having background in Java coding, no experience with Eclipse, Maven and so on, I gave it a shot. I’m slowly learning (and struggling :slight_smile: ), so if I’m making rookie mistakes: please forgive me and bare with me.

So I now came to the point where I want to set up an MQTT connection with the external servers of Liberty Global. And I simply cannot figure out what I should use. I know that Paho MQTT has been used in the past, but apparently it is not in the “standard package” in Eclipse, and org.eclipse.smarthome.io.transport.mqtt is. So I gave that a shot first, but when I try to run or resolve the app.bndrun in Eclipse, I start getting errors like these:

Resolution failed. Capabilities satisfying the following requirements could not be found:
    [<<INITIAL>>]
      ⇒ osgi.identity: (osgi.identity=org.openhab.binding.ziggonext)
          ⇒ [org.openhab.binding.ziggonext version=2.5.0.201911162153]
              ⇒ osgi.wiring.package: (&(osgi.wiring.package=org.eclipse.smarthome.io.transport.mqtt))
                  ⇒ [org.openhab.core.io.transport.mqtt version=2.5.0.201911150310]
                      ⇒ osgi.wiring.package: (&(osgi.wiring.package=com.hivemq.client.mqtt.datatypes)(&(version>=1.1.0)(!(version>=2.0.0))))
                          ⇒ [com.hivemq.client.mqtt version=1.1.2]
                              ⇒ osgi.wiring.package: (&(osgi.wiring.package=dagger))

Can someone tell me what I am doing wrong, and which MQTT implementation is recommended?

I‘m working on that. Unfortunately dagger is not an OSGi-bundle and therefore bnd can‘t resolve it.

Not much you can do at the moment without dirty hacks.

Let’s suppose I would be impatient and would be willing to resort to dirty hacks, what would I have to do?

Using Windows 7 and Java JDK & JRE 8

Add dagger as dependency to your binding, and add the dagger packages to bnd.exportpackage. That should work.

Thanks for your pointers Jan, but unfortunately unsuccessful so far.
I did what you said, and they, when I try to Run/Debug OSGi, I first get the popup:

could not resolve the bundles: []

Which in itself is a bit weird, but shortly after that, I get this in the console:

ERROR E.F.org.openhab.binding.ziggonext:? - FrameworkEvent ERROR
org.apache.felix.log.LogException: org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.ziggonext [117]
  Unresolved requirement: Import-Package: org.eclipse.smarthome.io.transport.mqtt

So I guessed I might need to either add it as a dependency as well…
If I try to add it as a dependency, real funky stuff starts to happen, as I then get an empty list under Browse Repos all of the sudden, and upon resolving, or clicking Debug OSGi, I get:

Resolution failed. Capabilities satisfying the following requirements could not be found:
    [<<INITIAL>>]
      ⇒ osgi.identity: (osgi.identity=org.eclipse.equinox.metatype)

(which obviously makes no sense whatsoever)

Any further ideas what I could do to resolve this, or am I really hitting a dead end here with binding development for OpenHAB?

i am running into the same situation

@J-N-K could you elaborate on how to do this? Where do i add dagger packge to bnd.exportpackage? and which file? the new way of setting up an IDE for custom-made 2.4 bundle to 2.5 really drives me to nut and confusing. TQ

It‘s not so easy and I don‘t understand why it is not working. I don‘t use Eclipse and don‘t use the demo app. I have a „normal“ snapshot installed on the same machine and start that in debug mode. Then you can attach every IDE debugger to that instance.

Is there a solution to this problem?

can you elaborate what IDE are you using? and how to attach every IDE debugger to that instance?

@J-N-K I am running into exactly the same problem when further developing the Niko Home Control binding. Is there any solution in sight for this?

As I said: that i not very high on my list. I’m currently hunting bugs that affect user experience and I don’t think I’ll come to this before 2.5 is released. I suggest to setup a local openhab instance, start in debug mode and attach the IDE debugger to that instance. This is pretty straight forward in both, Eclipse and IntelliJ.

What I ended up doing is the following: (And some of it might not be necesarry, but I have something that kind-of works now, so I don’t dare to touch it again)

  • Add dagger to the POM file of my binding:
        <dependency>
            <groupId>com.google.dagger</groupId>
            <artifactId>dagger</artifactId>
            <version>2.0</version>
        </dependency>
  • Make a lib folder in the root of the binding folder, and add dagger.jar and org.eclipse.smarthome.io.transport.mqtt.jar from Maven’s .m2 folder (should be easily found in there)
  • In Eclipse, add both files to the build path (expand the lib folder, right click on each .jar file > Build path > Add to build path.

So as said, some of those steps might be unnecessary, but I have been trying so many things that, as soon as it worked, I dared not to touch it again.
I do still experience some difficulties, because mostly related probably to version differences and stuff like calls to deprecated methods because somehow Maven can’t find the “new” version of the methods. (So I ended up just using the deprecated versions for now).
This will probably get me in trouble again when moving towards a PR, but that should be easy fixes then.

The dagger problem seems to be related to the way dagger is included. It is mvn wrapped in the feature and not made into a osgiif bundle like we do with the rest. So I’ve created a osgiif bundle of dagger, which has been merged. In the latest snapshots it uses this dependencies.

It might be you get an error when running the demo app.bndrun file. In that case add the following -runproperties (Open app.bndrun, and look into Source):

org.osgi.framework.bootdelegation="sun.misc"

@hilbrand Should the problem with the recent PRs around dagger be fixed? I reset the distro repository in Eclipse and added my nikohomecontrol binding to the pom.xml and bndrun again. I am still getting the following when trying to resolve:

Resolution failed. Capabilities satisfying the following requirements could not be found:
    [<<INITIAL>>]
      ⇒ osgi.identity: (osgi.identity=org.openhab.binding.nikohomecontrol)
          ⇒ [org.openhab.binding.nikohomecontrol version=2.5.0.201912141602]
              ⇒ osgi.wiring.package: (&(osgi.wiring.package=org.eclipse.smarthome.io.transport.mqtt.sslcontext))
                  ⇒ [org.openhab.core.io.transport.mqtt version=2.5.0.201912112236]
                      ⇒ osgi.wiring.package: (&(osgi.wiring.package=com.hivemq.client.mqtt.datatypes)(&(version>=1.1.0)(!(version>=2.0.0))))
                          ⇒ [com.hivemq.client.mqtt version=1.1.2]
                              ⇒ osgi.wiring.package: (&(osgi.wiring.package=dagger))

@Mherwege how is it going?

Still the same, but I managed to get remote debugging working, so I am using that instead.

@hilbrand how do we check whether the osgiif dagger is in my ide repo? It doesn’t seem to work and i am getting the same error as @Mherwege

I am working in the 2.5.x branch and had dagger problems with MQTT too.
For me the solution to fix “Resolution failed” was to add a dependency to dagger bundle in pom of demo app:

        <dependency>
    		<groupId>org.openhab.osgiify</groupId>
    		<artifactId>com.google.dagger</artifactId>
    		<version>2.20</version>
    		<scope>runtime</scope>
    	</dependency>

and add a run requirement to com.google.dagger.

2 Likes

This is working.