Open ftitius opened 4 years ago
After starting OH or adding the MySensors binding jar to addon folder a MQTT connection to the MQTT broker should be establiehed.
With OH 2.5 and MySensors binding as osgi bundle its not possible to get a working connection to MQTT broker. In the log you get:
[ERROR] [rotocol.mqtt.MySensorsMqttConnection] - MqttService is null! [ERROR] [rotocol.mqtt.MySensorsMqttConnection] - Failed connecting to bridge...next retry in 10 seconds (Retry No.:0)
No connection could be establiehed.
See https://community.openhab.org/t/oh-2-5-snapshot-and-mysensors-binding/86580/29. Until clarified why the osgi dependency injection for MqttService does not work we can use a workaround in MySensorsMqttConnection.establishConnection():
boolean connectionEstablished = false; //Start workaround if (MySensorsMqttService.getMqttService() == null) { BundleContext bc = FrameworkUtil.getBundle(getClass()).getBundleContext(); final ServiceReference sr = bc.getServiceReference(MqttService.class.getName()); if (sr != null) { final MqttService mqtt = (MqttService) bc.getService(sr); if (mqtt != null) { new MySensorsMqttService().setMqttService(mqtt); } } } //End workaround if (MySensorsMqttService.getMqttService() == null) {
Shortly after starting with this binding you see in the log:
[INFO ] [rotocol.mqtt.MySensorsMqttConnection] - Successfully connected to MySensors Bridge.
and the things are going online in paperui.
Define a MySensors MQTT Bridge via mysensors.things file
Bridge mysensors:bridge-mqtt:gwMQ01 [ brokerName="mosquitto", topicPublish="mygw1-in", topicSubscribe="mygw1-out", startupCheckEnabled=false ] { // no things yet }
} else if (bridgeuid.equals(THING_TYPE_BRIDGE_MQTT)) { gatewayConfig.setGatewayType(MySensorsGatewayType.MQTT); gatewayConfig.setBrokerName(conf.brokerName);
feature:install openhab-core-io-transport-mqtt feature:install openhab-transport-serial
Since changing to osgi bundling of the MySensors binding the dependency injection of the MQTT service ist not working.
Expected Behavior
After starting OH or adding the MySensors binding jar to addon folder a MQTT connection to the MQTT broker should be establiehed.
Current Behavior
With OH 2.5 and MySensors binding as osgi bundle its not possible to get a working connection to MQTT broker. In the log you get:
No connection could be establiehed.
Possible Solution
See https://community.openhab.org/t/oh-2-5-snapshot-and-mysensors-binding/86580/29. Until clarified why the osgi dependency injection for MqttService does not work we can use a workaround in MySensorsMqttConnection.establishConnection():
Shortly after starting with this binding you see in the log:
and the things are going online in paperui.
Steps to Reproduce (for Bugs)
Define a MySensors MQTT Bridge via mysensors.things file
Context
Since changing to osgi bundling of the MySensors binding the dependency injection of the MQTT service ist not working.
Your Environment