MQTT connection lost

does openHAB establish a stable connection to the mosquitto now?

check with

lsof -i :1883
netstat -atn |grep 1883

monitor also the mosquitto.log file

i think not?

[10:39:57] openhabian@openHABianPi:/etc/openhab2$ sudo lsof -i :1883
[sudo] password for openhabian:
COMMAND   PID      USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mosquitto 438 mosquitto    4u  IPv4  10339      0t0  TCP *:1883 (LISTEN)
mosquitto 438 mosquitto    5u  IPv4   6942      0t0  TCP openHABianPi.fritz.box:1883->sonoff1-3424.fritz.box:9590 (ESTABLISHED)
mosquitto 438 mosquitto    6u  IPv4   6984      0t0  TCP localhost:1883->localhost:43550 (ESTABLISHED)
java      907   openhab  127u  IPv6  12652      0t0  TCP localhost:43550->localhost:1883 (ESTABLISHED)
[10:40:11] openhabian@openHABianPi:/etc/openhab2$ sudo netstat -atn |grep 1883
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN
tcp        0      0 192.168.178.173:1883    192.168.178.160:9590    ESTABLISHED
tcp        0      0 127.0.0.1:1883          127.0.0.1:43550         ESTABLISHED
tcp6       0      0 127.0.0.1:43550         127.0.0.1:1883          ESTABLISHED

looks good and clean ! does it work?

You have only the needed connections listed:

mosquitto 438 mosquitto    4u  IPv4  10339      0t0  TCP *:1883 (LISTEN)

mosquitto listening to the world

mosquitto 438 mosquitto    5u  IPv4   6942      0t0  TCP openHABianPi.fritz.box:1883->sonoff1-3424.fritz.box:9590 (ESTABLISHED)

mosquitto link with sonoff

mosquitto 438 mosquitto    6u  IPv4   6984      0t0  TCP localhost:1883->localhost:43550 (ESTABLISHED)

mosquitto link to openhab (only 1!.. that’s good)

java      907   openhab  127u  IPv6  12652      0t0  TCP localhost:43550->localhost:1883 (ESTABLISHED)

openhab link (only 1!) to mosquitto (don’t ask me why it appears as IPv6 and not IPv4 as it should
 :slight_smile:)

I’ll do these steps later today (I’ve deinstalled and installed MQTT Action), but I’d like to ask:

which file log can I see the MQTT Action publish command?? I looked at openhab log /mosquitto.log and even if I move the switch nothing appears at this log


Paulo

no :frowning:

switching from tasmota/sonoff1 webinterface does this:

[16:38:06] openhabian@openHABianPi:~$ mosquitto_sub -v -t 'tasmota/#'
tasmota/sonoff1/tele/LWT Online
tasmota/sonoff1/stat/RESULT {"POWER":"ON"}
tasmota/sonoff1/stat/POWER ON
tasmota/sonoff1/stat/RESULT {"POWER":"OFF"}
tasmota/sonoff1/stat/POWER OFF

switching with openhab does nothing von “mosquitto_sub -v -t ‘tasmota/#’”:
openhab.log

2017-07-23 16:39:53.140 [DEBUG] [inding.mqtt.internal.MqttItemBinding] - Publishing command ON to tasmota/sonoff1/cmnd/POWER

events.log

2017-07-23 16:39:53.122 [ItemCommandEvent          ] - Item 'Sonoff_TH16A' received command ON
2017-07-23 16:39:53.144 [ItemStateChangedEvent     ] - Sonoff_TH16A changed from NULL to ON

nothing on mosquitto.log

1500820404: New connection from 192.168.178.160 on port 1883.
1500820404: New client connected from 192.168.178.160 as OH2MQTT (c1, k15, u'DVES_USER').
1500820456: New connection from 127.0.0.1 on port 1883.
1500820456: New client connected from 127.0.0.1 as openHAB2 (c1, k60).
1500820699: New connection from 127.0.0.1 on port 1883.

no need for the action binding?

It should be in your mosquitto.log if your setup is working:

1500783927: New connection from 192.168.2.181 on port 1883.
1500783927: New client connected from 192.168.2.181 as ESPClient1 (c1, k15).
1500783927: Sending CONNACK to ESPClient1 (0, 0)
1500783927: Received SUBSCRIBE from ESPClient1
1500783927: 	/esp8266one/# (QoS 0)
1500783927: ESPClient1 0 /esp8266one/#
1500783927: Sending SUBACK to ESPClient1
1500783927: Sending PUBLISH to ESPClient1 (d0, q0, r1, m0, '/esp8266one/dht22/temperature', ... (4 bytes))
1500783927: Sending PUBLISH to ESPClient1 (d0, q0, r1, m0, '/esp8266one/dht22/humidity', ... (3 bytes))
1500783927: Sending PUBLISH to ESPClient1 (d0, q0, r1, m0, '/esp8266one/light/intensity', ... (2 bytes))

At the log I got the connection message but no subscription


1500815962: mosquitto version 1.4.14 (build date Mon, 10 Jul 2017 23:48:43 +0100 ) starting
1500815962: Config loaded from /etc/mosquitto/mosquitto.conf.
1500815962: Opening ipv4 listen socket on port 1883.
1500815980: New connection from 10.0.0.104 on port 1883.
1500815980: New client connected from 10.0.0.104 as DVES_A7F83D (c1, k15, u’open habian’).
1500816043: New connection from 127.0.0.1 on port 1883.
1500816043: New client connected from 127.0.0.1 as openHAB2 (c1, k60, u’openhabi an’).

if I subscribe to the topic and send a message from MQTT.fx should I turn on/off the lamp?? Because I tried to do that and it doesn’t work too


Yes, I have uninstalled it and installed again


Result:

Pid: org.openhab.mqtt
BundleLocation: mvn:org.openhab.io/org.openhab.io.transport.mqtt/1.10.0
Properties:
raspberrypi.clientId = openHAB2
raspberrypi.pwd = password
raspberrypi.url = tcp://127.0.0.1:1883
raspberrypi.user = openhabian
service.pid = org.openhab.mqtt
openhab> config:list |grep -i broker
broker = raspberrypi
broker = raspberrypi

I’m testing the MQTT using MQTT fx. If I publish using MQTT fx, I can see the result at subscribe, but nothing appears at Sonoff. Same thing with Sonoff, the device sends messages from time to time but MQTT.fx doesn’t see them


no real need for the MQTT Action addon (unless you want to create rules that publish stuff to the broker like: publish(String brokerName, String topic, String message))

you item config should look like:

Switch Sonoff_TH16A "Sonoff Test" <light> { mqtt=">[mqttson:tasmota/sonoff1/cmnd/POWER:command:*:default],<[mqttson:tasmota/sonoff1/stat/POWER:state:default]" }

with mqtt.cfg:

mqttson.url=tcp://127.0.0.1:1883
mqttson.clientId=openHAB2

this means that the openHAB2 ↔ Broker connection is (still) not working
 (without any obvious reason
)

I would nuke the deployment...
1 Like

i you were me, you wouldn’t - trust me :wink:
look at this

every item is configured with “broker” -but it sould be “mqttson”: this i the connection between items and mqtt.cfg. seems pretty obvious, now that i see your definition of items.

i’ll re-configure my items as soon as i’m home!

1 Like

by the way: @ThomDietrich 's link to https://github.com/arendst/Sonoff-Tasmota/wiki/openHAB#requirements gives you all the info that you need (maybe with a small exception of a sample mqtt.cfg).

It is mentioned in that wiki entry that : “[
] you first need to install and activate the MQTT binding”

Anyway, I believe that if you fix the item configs
 it should work :slight_smile:
(there were no errors logged in openhab.log due to the wrong broker item config?)

no, openhab.log shows no errors.
i began the whole project with ThomDietrich’s link, but as you know there were some problems
 originally my first step was activating the mqtt binding =)

1 Like

i stopped OH2 using systemctl stop deleted all the tmp and cache files, after that I started the service again. But since then (5 hours have passed) the message “Please stand by while UIs are being installed. This can take several minutes.” still continues


What shall I do now??

Paulo

including the tmp folder itself? :slight_smile:
(if yes: recreate it
 with the correct permissions like the other folders)

1 Like

I just left the folders empty
 can I do a sudo reboot??? will it affect the configuration??

yeah, you can reboot. It doesn’t affect flat config files.

check the output of ls -al /var/lib/openhab2/

1 Like

YAY!
for me it’s working now! just had to correct the broker on my items!
BIG thanks to @Dim !
In the end i don’t know what exactly did the trick (besides correct items-definition), but after deleting so many configs i’m happy it’s working now!

2 Likes

nice :slight_smile:

My only concern is that we didn’t clearly identify the root cause, so don’t know what to write in the open issue here:

I may have to close it since I can’t provide steps to reproduce it :frowning:

after shutdown OH2 is online again, but still things isn’t working
 I’ll try to do things smoothly in order to understand what it is happening


BUT I see that although Sonoff is connecting even if I send mosquitto_pub to the topic nothing happens:

(Sonoff console)

00:00:00 APP: Project sonoff Sonoff (Topic sonoff-abajur, Fallback DVES_A7F83D, GroupTopic sonoffs) Version 5.2.1
00:00:00 Wifi: Connecting to AP1 Home in mode 11N as sonoff-abajur-6205

00:00:06 Wifi: Connected
00:00:06 mDNS: Initialized
00:00:06 HTTP: Webserver active on sonoff-abajur-6205.local with IP address 10.0.0.104
12:28:18 MQTT: Attempting connection

12:28:19 mDNS: Query done with 0 mqtt services found
12:28:19 MQTT: Connected
12:28:19 MQTT: tasmota/sonoff-abajur/tele/LWT = Online (retained)
12:28:19 MQTT: tasmota/sonoff-abajur/cmnd/POWER =
12:28:19 MQTT: tasmota/sonoff-abajur/tele/INFO1 = {“Module”:“Sonoff Basic”, “Version”:“5.2.1”, “FallbackTopic”:“DVES_A7F83D”, “GroupTopic”:“sonoffs”}
12:28:19 MQTT: tasmota/sonoff-abajur/tele/INFO2 = {“WebserverMode”:“Admin”, “Hostname”:“sonoff-abajur-6205”, “IPaddress”:“10.0.0.104”}
12:28:19 MQTT: tasmota/sonoff-abajur/tele/INFO3 = {“Started”:“Power on”}
12:28:20 MQTT: tasmota/sonoff-abajur/stat/RESULT = {“POWER”:“OFF”}
12:28:20 MQTT: tasmota/sonoff-abajur/stat/POWER = OFF

what does it mean " Query done with ZERO mqtt services found" ?

(Mosquitto log)

1500982093: Client DVES_A7F83D has exceeded timeout, disconnecting.
1500982093: Socket error on client DVES_A7F83D, disconnecting.
1500982098: New connection from 10.0.0.104 on port 1883.
1500982098: New client connected from 10.0.0.104 as DVES_A7F83D (c1, k15, u’openhabian’).
1500982341: New connection from 127.0.0.1 on port 1883.

(the second connection is from the mosquitto.fx)

Really don’t know where to go now


@Dim i don’t know, either
 just followed your insctructions and the problem(s) went away


2 Likes