Page 1 of 1

publish empty MQTT Topic in rules

Posted: 31 Jan 2023, 13:58
by Arne
Hi All,
i want to publish an empty MQTT Topic via an rule.
The required topic looks like R/blabla/keepalive

without any content.

right now my approach looks like

Code: Select all


On Rules#Timer=1 do
timerset,1,5
let,1,
Publish R/blabla/keepalive,%v1%
endon

But in this case it is published with a value of 0.

Can someone provide me with the right code snipplet?

Re: publish empty MQTT Topic in rules

Posted: 31 Jan 2023, 14:54
by Ath
%v1% is representing a numerical variable, and by default that's 0, you could remove that, but keep the comma, and try that

Re: publish empty MQTT Topic in rules

Posted: 31 Jan 2023, 15:04
by Arne

Code: Select all


On Rules#Timer=1 do
timerset,1,5

Publish R/blabla/keepalive,

endon

with that code the esp stops to publish that topic

Re: publish empty MQTT Topic in rules

Posted: 31 Jan 2023, 15:42
by TD-er
Not sure whether the MQTT standard allows to have empty messages.
When sending a MQTT message, the header must tell how long the message will be (including the topic and MQTT header stuff).
Whenever this does not match with what you're sending, you will be disconnected by the MQTT broker.

So I do think '0' might not be a valid topic length for MQTT.

Re: publish empty MQTT Topic in rules

Posted: 31 Jan 2023, 15:44
by Arne
With MQTT Explorer i am able to publish the required topic.

Re: publish empty MQTT Topic in rules

Posted: 31 Jan 2023, 15:47
by TD-er
And when you try:

Code: Select all

Publish R/blabla/keepalive,""

Re: publish empty MQTT Topic in rules

Posted: 31 Jan 2023, 16:05
by Arne
In that case the topic is also not published

Re: publish empty MQTT Topic in rules

Posted: 31 Jan 2023, 16:28
by Ath
The Publish command wont start sending if the net value is empty, and "" will effectively return an empty string.
Trying to work around that, can you try:

Code: Select all

Publish R/blabla/keepalive,'""'
that just wraps the empty string with a set of other quotes (fully supported by ESPEasy), to 'trick' the command into sending the actual quotes (which should be parsed as empty string by the recipient).

Re: publish empty MQTT Topic in rules

Posted: 31 Jan 2023, 16:38
by Arne
Sorry, that doesn't change the behaviour.

Re: publish empty MQTT Topic in rules

Posted: 31 Jan 2023, 16:41
by Ath
Can you see what is logged by ESPEasy when sending something valid versus sending the empty string?

You might want to set logging to Debug (when available in your build)

Re: publish empty MQTT Topic in rules

Posted: 31 Jan 2023, 19:11
by Arne
Currently It just says:

10093737: ACT : Publish R/blabla/keepalive,''''

I will try to update the firmware later.

Re: publish empty MQTT Topic in rules

Posted: 31 Jan 2023, 22:29
by Ath
I've opened a pull request, PR #4492, to enable the Publish command to have an empty payload/value.

@Arne, can you test this Github Actions build once it's finished, and report your findings? You will need a (free) Github account to be able to download the Binaries.zip.

Re: publish empty MQTT Topic in rules

Posted: 01 Feb 2023, 17:29
by Arne
Hi @Ath
so i used the ESP_Easy_mega_20230131_normal_ESP8266_4M1M.bin from your mentioned Action build.
In the Rules editor i used:

Code: Select all

Publish R/blabla/keepalive
And it seems to work like expected.
The topic is published like describe, and also the other device which requires this topic is reacting on it like it is intended to do.

So many thanks for your help,
If you like you can send me your paypal adress (if available) so that i can invite you to a beer, or at least send you a small donation equivilant to a beer :)

Re: publish empty MQTT Topic in rules

Posted: 01 Feb 2023, 22:07
by Ath
Arne wrote: 01 Feb 2023, 17:29 So many thanks for your help,
If you like you can send me your paypal adress (if available) so that i can invite you to a beer, or at least send you a small donation equivilant to a beer :)
I've updated my signature with my PayPal.me link, for those that feel generous, TIA :D