I’m trying to use MQTT in openHAB 2 within a binding I’m currently developing (for a research project). The idea is that MQTT is used under the hood instead of having a user to manually specifying the MQTT channels.
However, I face two problems preventing me from testing my code:
- When running the binding from within Eclipse, everything compiles, openHAB starts, I can create a new Thing in the PaperUI. However, the binding can’t subscribe or publish to any topic, because there are no connections visible to it. Interestingly, there is one connection (to a mosquitto instance running locally) somehow according to the logs:
[DEBUG] [o.i.t.m.i.MqttBrokerConnection:294 ] - Creating new client for 'tcp://localhost:1883' using id 'paho97636217526118' and file store '/tmp/mosquitto'
To my code: I’m using OSGI Declarative services getting a
MqttService in the
ThingHandlerFactory and pass this to newly created ThingHandlers. However,
mqttService.getAllBrokerConnections() always returns an empty collection.
- In my attempt to package the binding and test it in a running openHAB 2 instance (on a Raspberry Pi), the build process (
mvn clean install) fails to resolve the import
org.eclipse.smarthome.io.transport.mqtt.MqttBrokersObserver, which is weird, because Eclipse does resolve it.
Can you point me to a solution, or documentation on how to use MQTT (programmatically) within openHAB, other than https://docs.openhab.org/addons/bindings/mqtt1/readme.html#using-the-transport-orgopenhabiotransportmqtt-bundle?
If any information/code is missing, I’m happy to provide it.