MQTT Connection lost every time an update is pushed

update - as soon as I open the Owntracks app on iOS (or switch to the app) this error occurs. I don’t need to manually press the publish button for it to happen.

My guess is you are using the same clientId for both connections (phone + openHAB). The broker will drop one of the connections if another attempt is made with the same clientId.

Thanks for your reply.

I’m using “oh” as client for openHAB and “jf” for my phone - unfortunately that doesn’t seem to be my issue.

Same problem here!

Seems like a service restart has resolved the issue.

I just restarted the Mosquitto service and kept an eye on the Mosquitto log file. In there I noticed this:

1477050274: New client connected from 127.0.0.1 as OpenHAB2 (c1, k60).
1477050278: New connection from 192.168.5.3 on port 1883.
1477050278: Client OpenHAB2 already connected, closing old connection.
1477050278: Client OpenHAB2 disconnected.
1477050278: New client connected from 192.168.5.3 as OpenHAB2 (c1, k60).

192.168.5.3 is localhost. Is OpenHAB somehow openning the connection twice and Mosquitto seeing two IP addresses?

You need to use different clients from different devices.

I use two different users, one for OpenHAB and one for Owntracks. You need to create a few users for mosquitto and use a different one on each “client”

Unless in this case it’s just mosquitto resetting the connection because of the OH restart.

And another unless you’ve got the binding defined twice - somehow? (not sure this is possible - just sharing thoughts)

OpenHAB has a unique client name. I’ve just changed the name in mqtt.cfg but didn’t see the new name come through, so I’m restarting the OpenHab2 service now

2 Likes

Odd - In services/mqtt.cfg I changed the client name to be OpenHAB_2, but I still see the client name as OpenHAB2 (as it was before the change

1 Like

I found that for some changes I have to completely restart service and sometimes reboot.

I also moved away from using my Pine64 to using a more powerful VM - MUCH quicker to startup! (off-topic, I know)

Even after a reboot of the Pi I’m still seeing the same OpenHAB2 client connect. It would be great if I could track down where in the config this is set. I’m not seeing anything if I run grep on the /etc/OpenHAB2/ directory.

1 Like

I’m experiencing the same behaviour. Changing the name of the client doesn’t take or creates a duplicate connection.

2016-11-03 21:06:45.089 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to 'oh2mqtt' was lost: Connection lost : ReasonCode 32109 : Cause : null
2016-11-03 21:06:45.091 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting connection helper to periodically try restore connection to broker 'oh2mqtt'
2016-11-03 21:06:55.094 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'oh2mqtt'
2016-11-03 21:06:59.245 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'temp1'
2016-11-03 21:08:17.573 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to broker was lost
Connection lost (32109) - java.io.EOFException
    at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:138)[197:org.openhab.io.transport.mqtt:1.9.0.201611020212]
    at java.lang.Thread.run(Thread.java:745)[:1.8.0_65]
Caused by: java.io.EOFException
    at java.io.DataInputStream.readByte(DataInputStream.java:267)[:1.8.0_65]
    at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:56)[197:org.openhab.io.transport.mqtt:1.9.0.201611020212]
    at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:100)[197:org.openhab.io.transport.mqtt:1.9.0.201611020212]
    ... 1 more
2016-11-03 21:08:17.580 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to 'oh2mqtt' was lost: Connection lost : ReasonCode 32109 : Cause : null
2016-11-03 21:08:17.581 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting connection helper to periodically try restore connection to broker 'oh2mqtt'


After change of client ID:
mysql.config:

localbroker.url=tcp://localhost:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a default one is generated.
localbroker.clientId=openhab1

# Optional. User id to authenticate with the broker.
#<broker>.user=<user>

# Optional. Password to authenticate with the broker.
#<broker>.pwd=<password>

# Optional. Set the quality of service level for sending messages to this broker.
# Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
localbroker.qos=0

# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.
localbroker.retain=true

Log file (after reboot):

2016-11-03 21:20:23.083 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'localbroker'
2016-11-03 21:20:23.105 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to broker was lost
Connection lost (32109) - java.io.EOFException
    at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:138)[197:org.openhab.io.transport.mqtt:1.9.0.201611020212]
    at java.lang.Thread.run(Thread.java:745)[:1.8.0_65]
Caused by: java.io.EOFException
    at java.io.DataInputStream.readByte(DataInputStream.java:267)[:1.8.0_65]
    at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:56)[197:org.openhab.io.transport.mqtt:1.9.0.201611020212]
    at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:100)[197:org.openhab.io.transport.mqtt:1.9.0.201611020212]
    ... 1 more
2016-11-03 21:20:23.111 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to 'oh2mqtt' was lost: Connection lost : ReasonCode 32109 : Cause : null
2016-11-03 21:20:23.125 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting connection helper to periodically try restore connection to broker 'oh2mqtt'
2016-11-03 21:20:33.130 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'oh2mqtt'
2016-11-03 21:20:33.147 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to broker was lost
Connection lost (32109) - java.io.EOFException
    at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:138)[197:org.openhab.io.transport.mqtt:1.9.0.201611020212]
    at java.lang.Thread.run(Thread.java:745)[:1.8.0_65]
Caused by: java.io.EOFException
    at java.io.DataInputStream.readByte(DataInputStream.java:267)[:1.8.0_65]
    at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:56)[197:org.openhab.io.transport.mqtt:1.9.0.201611020212]
    at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:100)[197:org.openhab.io.transport.mqtt:1.9.0.201611020212]
    ... 1 more
2016-11-03 21:20:33.151 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to 'localbroker' was lost: Connection lost : ReasonCode 32109 : Cause : null
2016-11-03 21:20:33.153 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting connection helper to periodically try restore connection to broker 'localbroker'


For some reason, both the old and new broker ids are both trying to connect. And both getting booted.

1 Like

See this post:

1 Like

This is indeed the solution!

In shell type: ssh -p 8101 openhab@localhost
password: habopen
Ana you are login in karaf.
If you type: config:edit org.openhab.mqtt - you see many brokers and clientId’s.
Then type config:delete org.openhab.mqtt and you get message:
This config is being edited. Cancel / update first, or use the --force option

I don’t know how to exit edit mode.

So - rebooting your device (eg RPI).
Exit in karaf: ctrl+d, then in usuaily console type reboot.

Then connect again to karaf and type config:delete org.openhab.mqtt.
And again rebooting your device.

And problem will be solved.
mqtt.cfg loaded as we need.

To delete garbage in mqtt config:

openhab-cli console
(password as set for openhab console - default is habopen)
openhab> config:edit org.openhab.mqtt
openhab> property-list
Maybe there is some garbage to delete.
property-delete ... for each unwanted parameter.
Then config:update to store the changes.
Then ctrl+d to exit in karaf console.

To not have it in there in the first place: :grinning:

How?
I delete mqtt broker from /etc/openhab2/services/mqtt.cfg and OH logview continues to write error about old broker. Even after reboots

Following the post I have linked you should have found:

pid:org.openhab.mqtt

Put that as first line in your mqtt.cfg, then a restart of openHAB may be needed.

If it still does not work:
delete file userdata/config/org/openhab/mqtt.config and restart openHAB.

1 Like