[Solved] OpenHAB2 MQTT bad performance or something else?

Hi community!

First of all I apologize if this is some simple problem which is solved 100 times already on forum. I’m a beginner and possible problem is that I don’t recognize solution when I see one. I wasted 4 days already trying to make it work and nothing worked so I’m looking for your help.

I just started my home automation project using rPI Zero W with openHABian and some Sonoff smart switches flashed with ESPEasy firmware to support MQTT.

Problem I have is following… My OpenHAB seems to get stuck periodically every cca 5 seconds and stops responding on MQTT message. System seams to work in this period normally.

My first setup is very simple and falls under “Proof of concept” category. I have only one Sonoff switch. If you are familiar with Sonoff switch you will know what I talking about but if not here is short explanation:
Sonoff has one “manual” button on it and there is one relay which actually turns on the light. If you press the button it sends MQTT message with its state and when you release the button it send new state again. It also reacts to MQTT message which actually switches relay state.

Now on to openHAB config…
I have 1 switch defined like this, one item named “light.items” with following content

Switch light "light [%s]" {mqtt="<[mosquitto:Lights/Sonoff/Button/Pressed:state:ON:1], <[mosquitto:Lights/Sonoff/Button/Pressed:state:OFF:0], >[mosquitto:Lights/Sonoff/gpio/12:command:ON:1], >[mosquitto:Lights/Sonoff/gpio/12:command:OFF:0] "}

This should receive MQTT button state and if it is pressed “light” should indicate in BasicUI that is on and new MQTT message should be generated to change relay state and actually turn on the light.

This item is added to sitemap so it can be controlled from BasucUI

Additionally, I track all the MQTT messages with MQTT.fx.

So… now the to get back to what seams to be the problem.
This configuration works for few seconds and then it stops. After few seconds it starts to work again and then again stops. When it is working I can see MQTT message that button is pressed and OpenHAB send its message to switch the relay but when it stops working I can see only “Button pressed” messages and not OpenHAB response. So problem is not on the Sonoff side. All the Sonoff messages are generated correctly and Sonoff reacts on every “relay change” request so this problem is on OpenHAB side.

Sorry for the long post but I’m trying to give as much info as I can.
Thank you in advance!

This is a fairly resource-constrained device, esp compared to the PI 3’s that some people run. It has a single-core and 512MB RAM.

I’d first double check what’s going on using Linux level tools (eg. top or maybe vmstat 5) and make sure the machine itself is healthy.

For reference… just after rebooting, and with nothing running, top on mine reports as follows:

%Cpu(s):  0.0 us,  1.6 sy,  0.0 ni, 98.0 id,  0.3 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:    493804 total,    83656 used,   410148 free,     7936 buffers
KiB Swap:   102396 total,        0 used,   102396 free.    42536 cached Mem

My config is the minimal Jessie (Raspian Jessie Lite, no GUI). I’ve also dialed back the memory for the GPU to 16M using raspi-config. The numbers will be a lot different if you’re running the Linux Desktop etc.

If these are working fine, then it’d be worth checking the typical files in /var/log/, such as messages, syslog and/or kern.log to see if there are any hickups in the Wifi connectivity.

Beyond that, you’ll get into standard openHAB debugging…

Thanks for your answer.

I rechecked everything you said and eventually ended up looking at openhab logs…

Apparently, I have two broker connection initialized. Don’t know how this happened.

2017-04-03 11:39:47.586 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to 'broker' was lost: Connection lost : ReasonCode 32109 : Cause : null
...
2017-04-03 11:39:57.729 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to 'mosquitto' was lost: Connection lost : ReasonCode 32109 : Cause : null

Same problem as in MQTT config under OH2
Solution in the topic suggest connecting with Karaf console but for some reason this does not work for me. Do I need to installed it first or something?

Actually, all the info is stored in file:

/var/lib/openhab2/config/org/openhab/mqtt.config

and there was two connection defined in it. After deleting this file and letting openHAB reloading mqtt.cfg everything works ok.

1 Like