Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Eclipse SmartHome » Binding using MqttService(I am trying to develop an openhab2 binding using the MqttService)
Binding using MqttService [message #1769933] Sun, 06 August 2017 12:59 Go to next message
sebastian irimi is currently offline sebastian irimiFriend
Messages: 3
Registered: August 2017
Junior Member
Hello all,

I am trying to use a binding that subscribes to some topics and publishes some messages for an mqtt enabled thing i built.

The binding is openhab2 and I am trying to use the eclipse.smarthome.io.transport.mqtt package for the MqttService. In the IDE runtime, I manage to config and run everything, however, when I port my binding to a downloaded openhab2.1.0 instance, I cannot get the MqttService reference satisfied. To get a reference to the service, I use the following:

<scr:component xmlns:scr="redacted(You can only use links to eclipse.org sites while you have fewer than 1 message.)" immediate="true" name="MqttHandlerService">
   <implementation class="org.openhab.binding.captidom.handler.MqttHandlerService"/>
   <service>
      <provide interface="org.openhab.binding.captidom.handler.MqttHandlerService"/>
   </service>
   <reference bind="setMqttService" cardinality="1..1" interface="org.openhab.io.transport.mqtt.MqttService" name="MqttService" policy="dynamic" unbind="unsetMqttService"/>
   <reference bind="setThingRegistry" cardinality="1..1" interface="org.eclipse.smarthome.core.thing.ThingRegistry" name="ThingRegistry" policy="static" unbind="unsetThingRegistry"/>
   <reference bind="setDiscoveryService" cardinality="1..1" interface="org.openhab.binding.captidom.discovery.CaptidomDiscoveryService" name="CaptidomDiscoveryService" policy="dynamic" unbind="unsetDiscoveryService"/>
</scr:component>


What I see happens in openhab2.1.0 with my binding added, the config is being picked up by openhab.io.transport.mqtt and I don't get a reference to the esh.io.transport.mqtt service. I cannot manage to get a reference in my binding to the openhab.io.transport.mqtt because of a dependency on org.openhab.core.events and that is part of oh1 addon compat1.x, and I can't figure out how to satisfy this reference at compile time.

Anyoe has any thoughts on this, how I should correctly reference the MqttService and how it should pickup the config file - or why is it different in IDE runtime vs downloaded isntance runtime?

Thanks!
Re: Binding using MqttService [message #1769941 is a reply to message #1769933] Sun, 06 August 2017 18:00 Go to previous messageGo to next message
David Graeff is currently offline David GraeffFriend
Messages: 17
Registered: April 2016
Junior Member
 <reference bind="setMqttService" cardinality="1..1" interface="org.openhab.io.transport.mqtt.MqttService" name="MqttService" policy="dynamic" unbind="unsetMqttService"/>


In this line you clearly say that you want the openhab MqttService instead of the Eclipse Smarthome one. Be aware that both exists and they are both different. The Openhab one is the older one (Openhab 1.x), in newer projects you should use the ESH one.

Cheers,
David
Re: Binding using MqttService [message #1770935 is a reply to message #1769941] Fri, 18 August 2017 22:28 Go to previous messageGo to next message
sebastian irimi is currently offline sebastian irimiFriend
Messages: 3
Registered: August 2017
Junior Member
Hello and thanks for your reply!

The snippet had openhab.io.transport.mqtt by mistake after many trial and error changes. I now reverted it back to esh.io.transport.mqtt and it is not clear to me how this should work (how does the mqtt.cfg get loaded? I noticed that for oh1 there is the mqtt binding that loads this file). I tried the following:

1. create OH2 binding, test in IDE, everything works fine
2. move said OH2 binding.jar to downloaded openhab 2.1.0 and place in addons folder
3. place org.esh.io.transport.mqtt in addons folder (oh complains in log that it misses this dependency for said binding if i don't do this)
4. Added mqtt.cfg under conf/services/

When I run this, the binding is loaded, but for the love of GOD, I can't have the mqtt service connect. Is there anything else I need to do?
Do I need anything else to use this MqttService?

I also noticed in the logs, not sure if relevant:
Quote:

2017-08-19 01:24:50.171 [ERROR] [.eclipse.smarthome.io.transport.mqtt] - FrameworkEvent ERROR - org.eclipse.smarthome.io.transport.mqtt
org.osgi.framework.BundleException: Could not resolve module: org.eclipse.smarthome.io.transport.mqtt [180]
Another singleton bundle selected: osgi.identity; osgi.identity="org.eclipse.smarthome.io.transport.mqtt"; type="osgi.bundle"; version:Version="0.9.0.201708051248"; singleton:="true"

at org.eclipse.osgi.container.Module.start(Module.java:434)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1582)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1562)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1533)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1476)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]



LE: I would like to add outputs of following commands (Captidom Binding is what i am trying to build):

Quote:

openhab> service:list org.eclipse.smarthome.io.transport.mqtt.MqttService
[org.eclipse.smarthome.io.transport.mqtt.MqttService, org.osgi.service.cm.ManagedService]
-----------------------------------------------------------------------------------------
service.pid = org.eclipse.smarthome.mqtt
component.name = MQTT Connection Service
component.id = 4
service.id = 142
service.bundleid = 176
service.scope = bundle
Provided by :
Eclipse SmartHome MQTT Transport Bundle (176)
Used by:
Captidom Binding (178)

openhab> bundle:list | grep 178
178 | Active | 80 | 2.2.0.201708182131 | Captidom Binding

openhab> bundle:list | grep -i MQTT
176 | Active | 80 | 1.0.2 | Paho MQTT Client
177 | Active | 80 | 0.9.0.201708041325 | Eclipse SmartHome MQTT Transport Bundle

openhab> feature:list | grep -i mqtt
esh-tp-paho | 0.9.0.SNAPSHOT | | Started | distro-2.2.0-SNAPSHOT | MQTT v3 Client
esh-io-transport-mqtt | 0.9.0.SNAPSHOT | x | Started | distro-2.2.0-SNAPSHOT |
openhab-transport-mqtt | 2.2.0.SNAPSHOT | | Uninstalled | distro-2.2.0-SNAPSHOT | MQTT Transport
openhab-action-mqtt | 1.11.0.SNAPSHOT | | Uninstalled | addons-2.2.0-SNAPSHOT | MQTT Action
openhab-binding-mqtt1 | 1.11.0.SNAPSHOT | | Uninstalled | addons-2.2.0-SNAPSHOT | MQTT Binding
openhab-binding-mqttitude1 | 1.11.0.SNAPSHOT | | Uninstalled | addons-2.2.0-SNAPSHOT | OwnTracks (formerly MQTTitude) Binding
openhab-persistence-mqtt | 1.11.0.SNAPSHOT | | Uninstalled | addons-2.2.0-SNAPSHOT | MQTT Persistence

openhab> config:list
[...]
Pid: org.openhab.mqtt
BundleLocation: null
Properties:
captidomBroker.clientId = "yii2.0_webapp"
captidomBroker.pwd = "yii"
captidomBroker.url = tcp://192.168.10.254:1883
captidomBroker.user = "yii"
service.pid = org.openhab.mqtt
[...]



I also fail to see in the log "Starting MQTT Service" message, which would indicate that the MqttService isn't activated

[Updated on: Sat, 19 August 2017 00:57]

Report message to a moderator

Re: Binding using MqttService [message #1770958 is a reply to message #1770935] Sat, 19 August 2017 18:09 Go to previous messageGo to next message
David Graeff is currently offline David GraeffFriend
Messages: 17
Registered: April 2016
Junior Member
The configuration file is called org.eclipse.smarthome.io.transport.mqtt.cfg I think, without looking at the code. The default config name is the package name. OH1 renamed that to the short form mqtt.cfg. we don't do that for the eclipse MQTT. It's not done by the binding by the way but by the config admin OSGi service that finds config files for started services.

Cheers David
Re: Binding using MqttService [message #1770989 is a reply to message #1770958] Sun, 20 August 2017 16:07 Go to previous message
sebastian irimi is currently offline sebastian irimiFriend
Messages: 3
Registered: August 2017
Junior Member
Hey, that worked! although the package name of the service is org.eclipse.smarthome.io.transport.mqtt.MqttService, the correct file name is org.eclipse.smarthome.mqtt.cfg because this is the declared service.pid.

Now everything works as expected. Thanks!
Previous Topic:extending ExpiringCache with IsChanged
Next Topic:How to get Infos from Sonos-Binding for our binding
Goto Forum:
  


Current Time: Tue Apr 23 11:10:47 GMT 2024

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

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

Back to the top