[SOLVED] Mqtt binding (1.13 SNAPSHOT) is not subscribing

I have a new issue…

I have installed the MQTT binding to listen for inbound temperature reports from a couple of ESP8266’s I’ve built and configured with DHT22’s. The 8266’s work fine. And I can see the messages being published in my mosquito service. e.g.

539963042: Received PUBLISH from ESP8266Client (d0, q0, r0, m0, 'sensor/temperature', ... (58 bytes))

But although I see the MQTT connection from openhab

1539962577: New client connected from 192.168.254.115 as openhab (c1, k60, u'temps').

I don’t see any subscriptions being made in response to my configured items (e.g.

Switch MQTT_Test "Testing..." { mqtt="<[mosquitto:testing/mqtt/topic:state:default], >[broker:testing/mqtt/back-topic:command:*:default]" }
Number MasterBR_Temp "temp [%.1f]" {mqtt="<[mosquitto:sensor/temperature:state:REGEX(temp (\\d*.\\d*) ):000336da]" }

And the mqtt config is…

root@piman-301:/etc/openhab2# cat services/mqtt.cfg
pid:org.openhab.mqtt
mosquitto.url=tcp://mqtt.travellingkiwi.com:1883
mosquitto.clientId=openhab
mosquitto.user=temps
mosquitto.pwd=*****
mosquitto.qos=1
mosquitto.retain=true
mosquitto.async=false
root@piman-301:/etc/openhab2#

Meanwhile I can see the messages if I run mosquitto_sub to subscribe to the channel from the command line

In openhab.og I see the items being loaded…

2018-10-19 16:24:55.157 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mqtt.items'
2018-10-19 16:24:55.174 [ERROR] [sql.internal.MysqlPersistenceService] - mySQL: Unable to find table for query 'MQTT_Test'.
2018-10-19 16:24:55.182 [ERROR] [sql.internal.MysqlPersistenceService] - mySQL: Unable to find table for query 'MasterBR_Temp'.
2018-10-19 16:24:56.209 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'mqtt.items'

including the complaints about the persistence not being there yet…

Have I done something wrong? I even added the testing config from MQTT Binding (v1.11) Getting Started 101 but no joy…

Well, I can say that your second Item is configured to only process messages that match the regular expression 000336da.

> `mqtt="<direction>[<broker>:<topic>:<type>:<transformer>:<regex_filter>]`

I’m pretty sure that isn’t what you want. It isn’t clear to me what that 000336ad is supposed to represent.

The regex on your second Item looks suspect as well. Is the message being published “temp xx.xx” where the x’s are digits? If there is anything before that or after that in the message then this regex will not return anything. You must match the whole message.

REGEX(.*temp (\\d*\\.\\d*).*)

Note, I escaped the . because unescaped it will match any character.

For your first Item, it will only successfully command the Item if the message is “ON” or “OFF”. Case must match.

The messages have the format

pi@piman-202:~ $ mosquitto_sub -t sensor/temperature
-1396737822 000336da : humid 53.70 temp 19.00 heat_ind 18.35
-1366530318 000336da : humid 55.80 temp 19.00 heat_ind 18.41

The 000336ad is a regex to match the chipid that’s logged in the second field. That enables me to have a single config for all the ESP8266’s (As they have different chipid’s). Just plug them in and use regex to scrape just the ones you want.

However, that’s not the problem…

The problem is that the MQTT client (OpenHAB) is not subscribing to the channel (Topic) in the first place. Neither for my own item on sensor/temperature or the one that’s copied and pasted from the 1.11 guide elsewhere in the forums… No reg means it never gets as far as the regex or transform or anything else.

Thinking about you statement on matching the whole string in the regex…

The docs for the REGEX transform imply (In the examples given) that in a grouping the . is a literal . Not that I believe it, that’s just weird, but given it doesn’t understand [] I’ll fight that one when I actually get some data flowing to test it.

I’m not sure why the example has .* at the start and end of the regex or why you say it has to match the whole string. Normally that just a waste of processing cycles in a regex. e.g. (.MATCHME.) should be the same as (MATCHME). And the example for replacement even has a regex that doesn’t match the whole string. e.g.

And it understands anchors… So if there’s implied anchors (i.e. from your statement that you have to match the whole string) why would there be an option to add them… They’d be superfluous. Except in example 1 of course.

Seems a bit wooly to me…

That’s not how the regex works with the MQTT binding. Your expressions must match the WHOLE string. Both of them must match the whole string or else you will get no match at all.

I didn’t implement it. I haven’t looked at the code. But my 3+ years worth of experience using the binding indicates that you must match the full string in the transform and most especially in the filter regex or you will not get any match at all.

OK. That’s fine…

The binding is still not subscribing to the topic on the MQTT server though. So it never gets as far as the regex… I’ve even pared the item down to something like

Switch Simple "Testing" { mqtt="<[mosq:simple:*:default]" }

(Yes that as after shortening the name of the broker just in case there was some weird 8 character max or something).

But even that doesn’t subscribe. The MQTT binding is connected. I see that in the mosquitto logs no problems at all (Once I’d found and sorted the old config problem that it has). But no subscribing. ever. And no logs even at debug level to hint why.

Well bugger.

I found the problem. I had loaded ‘MQTT Action’ and not ‘MQTT Bindings’. I didn’t notice (Or even know what the difference is) until I stumbled across another posting where someone asked the user to make sure they didn’t have MQTT Actions loaded…

What is the difference anyway? And why does it use the same mqtt.cfg as the MQTT Binding?

So… Now it works… I did notice that there’s both a v1 and v2 binding for MQTT. I tried the v2 one. And couldn’t figure out how to configure it. I don’t see any docs one that. The v1 MQTT Binding (Not Action) seems to work find.

The answers are in the docs:

Actions are predefined methods that are called from openHAB rules and scripts.

Publish a message to a topic on an MQTT broker.

In addition to the MQTT Action service, the MQTT binding (1.x) must be installed and configured.

In other words, the MQTT Action lets you publish messages to topics in Rules without needing to set up Items. It depends upon the MQTT binding and therefore uses its config.

The MQTT 2 binding is in beta and will be released with OH 2.4. It is a 2.x version binding so it uses Things and Channels instead of binding configs at the Item. It also supports automatic discovery of topics. It is not compatible with the MQTT Action though.

Thanks. I worked out why I was (initially) confused… Lack of familiarity with the PaperUI interface. I went to addons and just searched for MQTT… but by default it’s on Actions and only shows the matches in Actions…

sigh…