MQTT 2.4.0 at OH2.4 wont install

I’ve just installed the embedded MQTT browser in OH2.4

I’ve got this message. I tried the installation sometimes without success.

What is needed, too?

I’m using a Pi3

2019-01-04 21:55:19.289 [ERROR] [ipse.smarthome.io.mqttembeddedbroker] - bundle org.eclipse.smarthome.io.mqttembeddedbroker:0.10.0.oh240 (255)[org.eclipse.smarthome.io.mqttembeddedbroker.internal.EmbeddedBrokerServiceImpl(309)] : The activate method has thrown an exception
java.net.BindException: Address already in use
	at sun.nio.ch.Net.bind0(Native Method) ~[?:?]
	at sun.nio.ch.Net.bind(Net.java:433) ~[?:?]
	at sun.nio.ch.Net.bind(Net.java:425) ~[?:?]
	at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) ~[?:?]
	at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:128) ~[?:?]
	at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:558) ~[?:?]
	at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1283) ~[?:?]
	at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:501) ~[?:?]
	at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:486) ~[?:?]
	at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:989) ~[?:?]
	at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:254) ~[?:?]
	at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:364) ~[?:?]
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) ~[?:?]
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404) ~[?:?]
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463) ~[?:?]
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886) ~[?:?]
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]

==> /var/log/openhab2/events.log <==
2019-01-04 21:55:19.602 [thome.event.ExtensionEvent] - Extension 'misc-mqttbroker' has been installed.

You are already running an MQTT broker. Mosquitto perhaps.

Nope. That’s my first try with MQTT on OH2.4

Though it’s better to use the “internal” broker instead of external services.

Is there somewhere a how-to to setup the new internal broker? I didn’t found anything here.

OH2.4 Embedded MQTT Broker is waiting for something… but what?

bundle:list|grep -i mq
254 x Active   x  80 x 1.2.0                  x Paho MQTT Client
255 x Waiting  x  80 x 0.10.0.oh240           x Eclipse SmartHome Embedded MQTT Broker
256 x Active   x  80 x 0.10.0.oh240           x Eclipse SmartHome MQTT Transport Bundle

See the log file. Another process is blocking the standard MQTT port. There is definitely another broker running. Or for some bizarre reasons the embedded broker started twice. But I really doubt that.

Check the command output of netstat -tulpen | grep 1883.

Or something else using that port on your machine

Hey guys.

You were right. There was Mosquitto installed from previously tests some weeks / month ago.

I’ve removed all old packages.

pi@pi3:/etc/openhab2 $ netstat -tulpen | grep 1883
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN      0          10742      -                   
tcp6       0      0 :::1883                 :::*                    LISTEN      0          10743      -                   
pi@pi3:/etc/openhab2 $ dpkg -l | grep mosq
ii  libmosquitto1:armhf             1.4.10-3+deb9u2              armhf        MQTT version 3.1/3.1.1 client library
ii  mosquitto                       1.4.10-3+deb9u2              armhf        MQTT version 3.1/3.1.1 compatible message broker
ii  mosquitto-clients               1.4.10-3+deb9u2              armhf        Mosquitto command line MQTT clients
pi@pi3:/etc/openhab2 $ 

I’ve removed OH2.4 broker and reinstalled. Now I have this message.

2019-01-05 11:59:22.267 [WARN ] [r.internal.EmbeddedBrokerServiceImpl] - Embedded broker offline - Reason unknown

But something is there at IPv6 1883
It must be OH2.4 because after removing Mosquitto there was nothing.

$ netstat -tulpen | grep 1883
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp6       0      0 :::1883                 :::*                    LISTEN      109        8339522    -

Just did it another time. Now with log data.

2019-01-05 12:14:51.518 [INFO ] [core.karaf.internal.FeatureInstaller] - Uninstalled 'openhab-misc-mqttbroker'
2019-01-05 12:17:26.103 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'localhost' with clientid paho954884091350266 and file store '/var/lib/openhab2/mqtt/localhost'
2019-01-05 12:17:28.219 [WARN ] [r.internal.EmbeddedBrokerServiceImpl] - Embedded broker offline - Reason unknown
2019-01-05 12:17:28.238 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to '127.0.0.1' with clientid embedded-mqtt-broker and file store '/var/lib/openhab2/mqtt/127.0.0.1'
2019-01-05 12:17:28.665 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=embedded-mqtt-broker
2019-01-05 12:17:28.690 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=embedded-mqtt-broker
2019-01-05 12:18:26.175 [INFO ] [.reconnect.PeriodicReconnectStrategy] - Try to restore connection to 'localhost'. Next attempt in 10000ms
2019-01-05 12:18:26.200 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'localhost' with clientid paho954884091350266 and file store '/var/lib/openhab2/mqtt/localhost'
2019-01-05 12:18:36.220 [INFO ] [.reconnect.PeriodicReconnectStrategy] - Try to restore connection to 'localhost'. Next attempt in 10000ms
2019-01-05 12:18:36.232 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'localhost' with clientid paho954884091350266 and file store '/var/lib/openhab2/mqtt/localhost'
2019-01-05 12:18:46.235 [INFO ] [.reconnect.PeriodicReconnectStrategy] - Try to restore connection to 'localhost'. Next attempt in 10000ms
2019-01-05 12:18:46.247 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'localhost' with clientid paho954884091350266 and file store '/var/lib/openhab2/mqtt/localhost'

And of course netstat before and after re-installing.

pi@pi3:/etc/openhab2 $ netstat -tulpen | grep 1883
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)

pi@pi3:/etc/openhab2 $ netstat -tulpen | grep 1883
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp6       0      0 :::1883                 :::*                    LISTEN      109        8346307    - 

Hope that helps.

Is 127.0.0.1 configured to be localhost on your system? That is required. Otherwise I don’t see a problem. The internal mqttconnection can’t establish a connection to the broker. That’s strange.

Try mosquitto_sub or any another mqtt client to connect to the broker.

localhost is defined and can be resolved.

pi@pi3:/etc/openhab2 $ host localhost
localhost has address 127.0.0.1
pi@pi3:/etc/openhab2 $ cat /etc/hosts
127.0.0.1	localhost
::1		localhost ip6-localhost ip6-loopback
ff02::1		ip6-allnodes
ff02::2		ip6-allrouters

127.0.1.1	pi3

But only at IPv6 address the broker seems to accept connections. How can I setup to accept on IPv4, too?

$ netstat -tulpen | grep 1883
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp6       0      0 :::1883                 :::*                    LISTEN      109        8346307    -              

The broker seem working (on IPv6) …

Published

pi@pi3:/etc/openhab2 $ mosquitto_pub -h localhost -t "testing/send" -m "test"
pi@pi3:/etc/openhab2 $ mosquitto_pub -h localhost -t "testing/send" -m "test"
pi@pi3:/etc/openhab2 $ mosquitto_pub -h localhost -t "testing/send" -m "test123"

Published from another machine

$ mosquitto_pub -h pi3.fritz.box -t "testing/abc123" -m abc123
$ mosquitto_pub -h pi3.fritz.box -t "testing/abc123" -m abc1234

Subscribed

pi@pi3:~ $ mosquitto_sub -h localhost -t "#"
test
test
test123
abc123
abc1234

Have also some log info from OH2.4 about Sessions. PLease, can you explain what this means?

2019-01-05 12:17:28.665 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=embedded-mqtt-broker
2019-01-05 12:17:28.690 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=embedded-mqtt-broker

2019-01-05 12:33:56.600 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=mosqsub/21723-pi3
2019-01-05 12:33:56.612 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=mosqsub/21723-pi3

2019-01-05 12:35:21.578 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=mosqpub/21786-pi3
2019-01-05 12:35:21.593 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=mosqpub/21786-pi3

2019-01-05 12:35:27.752 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=mosqsub/21809-pi3
2019-01-05 12:35:27.758 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=mosqsub/21809-pi3

2019-01-05 12:35:50.632 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=mosqsub/21908-pi3
2019-01-05 12:35:50.641 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=mosqsub/21908-pi3

2019-01-05 12:35:55.960 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=mosqpub/21911-pi3
2019-01-05 12:35:55.966 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=mosqpub/21911-pi3

2019-01-05 12:36:21.654 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=mosqpub/21940-pi3
2019-01-05 12:36:21.660 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=mosqpub/21940-pi3

2019-01-05 12:36:24.888 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=mosqpub/21944-pi3
2019-01-05 12:36:24.896 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=mosqpub/21944-pi3

2019-01-05 12:43:01.568 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=mosqpub|3575-jupiter
2019-01-05 12:43:01.571 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=mosqpub|3575-jupiter

2019-01-05 12:43:21.290 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=mosqpub|3584-jupiter
2019-01-05 12:43:21.295 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=mosqpub|3584-jupiter

2019-01-05 12:44:06.846 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=mosqsub/22323-pi3
2019-01-05 12:44:06.849 [WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=mosqsub/22323-pi3

That’s normal. Coming from the broker, I have no influence on that. Will probably change with a broker update at some point (there is a new release already available).

IPv6… ok. The brokerconnection class should be IP agnostic. Apparently it isn’t. And the reason is simple: It doesn’t connect to “localhost”, it connects to “127.0.0.1”… Sigh. Could you please create a bug report on github on the eclipse smarthome project? Thanks.

The workaround is: Disable IPv6 interfaces while booting up openHAB and re-enable them after. IPv6 is the future so shouldn’t permanently be disabled.

Will do.

But a question I have … Why shows netstat only an IPv6 connection for 1883 and no IPv4 as Mosquitto has done?

Because it binds to an ipv6 socket if your system is ipv6 enabled. Will work for ipv4/ipv6 connections though.

Ok. I can connect the broker through localhost (host lookup is 127.0.0.1, IPv4) and 127.0.0.1 (IPv4) and ::1 (IPv6)

Using Paper UI

Configuration > Services > MQTT system broker connection -> host 

Nothing will work. Tried localhost, 127.0.0.1, ::1