MQTT-Binding: cannot read values with | (pipe) in topic

Hi,

I got the following problem during the migriation from MQTT 1.x to 2.x:
I use the “psmqtt” software for monitoring (CPU, RAM, HDD, etc…) some PCs in my network.
For getting states of the harddisks, the mountpoint (on Linux systems) is part of the topic name. So therfore I use the folling topic name in the openHAB thing configuration: “psmqtt/bart/disk_usage/percent/|”

Unfortunatly I do non get any value on the corresponding item. But with the MQTTbinding 1.x it worked in prior. There is also no error message shown in the log file.

So I guess there is some problem with the | (Pipe) character within the topic name. Or should it be escaped in someway?

Abstract of my configuration:

Thing topic psmqtt {
Channels:
Type number : monitoring_bart_cpu_percent [ stateTopic=“psmqtt/bart/cpu_percent” ]
Type number : monitoring_bart_memory_percent [ stateTopic=“psmqtt/bart/virtual_memory/percent” ]
Type number : monitoring_bart_disk_percent “Bart Disk Percent” [ stateTopic=“psmqtt/bart/disk_usage/percent/|” ]

The channels “monitoring_bart_cpu_percent” and “monitoring_bart_memory_percent” are working!

Thanks in advance,
Robert

I would check to see what arrives at the broker, it may be a character encoding problem (should be UTF-8)

Try sending a test command topic from openHAB including a pipe, see what arrives at broker. Might offer a clue.

Welcome to the OpenHAB community Robert!
Just an idea, you might already know, install mqttfx or another mqtt client

Thank you for your replies!

I already use mqtt-spy for testing :wink:

Now I simply defined a test item (Topic: “test/test|”) :

Things:
Type switch : mqtt_test [ stateTopic=“test/test|”, commandTopic=“test/test|” ]

Items:
Switch mqtt_test “MQTT-Test” (gMonitoring) { channel=“mqtt:topic:broker1:psmqtt:mqtt_test” }

Result: ON or OFF was published to the broker with the correct topic name (including the pipe as well) when I change the button state in BasicUI.
But when I am publishing a state back to openHAB with mqtt-spy and the same topic-name (copy-paste), openHAB did not receive an update of the item.

It is very strange! May you have some other hints?

Thanks,
Robert

You might check in your broker log to see if/what openHAB subscribes to

Now, I activated the DEBUG log of the Mosquitto broker:

openHAB successfully subscribes the topic and the broker also send Publish message to openHAB when a new value is received from psmqtt.

But in the meanwhile, I figured out the following workaround:

Defining the channel topic with a wildcard ‘psmqtt/bart/disk_usage/percent/+’ and using a rule which triggers when an update on this channel were received. Within the rule I have to interpret the topic name and trigger a manual update of the corresponding topic.

I think this may work, but how can I get the topic name within the rule?

Thanks,
Robert

Now I found a quite simplier solution for this problem:

I simply changed the | (Pipe) character, which is the replacement for /, to ~ (tilde) in the Python sourcecode of psmqtt. Consequently I subscribe now to the topic named “psmqtt/bart/disk_usage/percent/~” and it WORKS!

Nevertheless, it is still a mystery why the pipe in topic names do not work…

Thanks a lot for your support and hints,
Robert

Hi, I’m the author of psmqtt utility and can offer you a bit different configuration to avoid the issue with a pipe character. You can use kind of alias in the schedule, e.g. for disk usage:

schedule = {
    "every 60 minutes"  :     "disk_usage/percent/|"
}

could be converted to

schedule = {
    "every 60 minutes"  :     {
         "disk_usage/percent/|" : "disk_usage_alias"
    }
}

and disk usage will be published to the disk_usage_alias topic

If it’s still not clear please provide your configuration and I’ll show how to change it

3 Likes

MQTT 2.5 Event Bus will show an example.

It’s unclear to me, dod you try escaping the pipe?

While this is likely to be a rare problem for most, it would seem as far as I can tell that the pipe character should be allowed and if it is not an issue should be filed on the binding so others would not need to use this work around.

@eschava
First of all, thank you for psmqtt, it is a really nice and straightforward utility! Please keep on going!
The alias feature for topic names (which I even not known yet) is in my opinion the prettiest solution for that issue. It simply avoid using the pipe character within openHAB.

@rlkoshak
Thank you also for your reply! Yes, I tried to escape the pipe in the topic name, but it won’t work too. It is also very confusing that openHAB successfully subcribes with the right topic name to the broker and the broker also publishes messages back to openHAB regarding to this topic…
Nevertheless, as you already mentioned, it would be a very rare problem. So therefore the best solution is not using topics with pipes in their names.

1 Like

The really best option is to file an issue on the binding so the problem gets fixed. How to file an Issue