publish empty MQTT Topic in rules

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Arne
New user
Posts: 7
Joined: 31 Jan 2023, 13:46

publish empty MQTT Topic in rules

#1 Post by Arne » 31 Jan 2023, 13:58

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?

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: publish empty MQTT Topic in rules

#2 Post by Ath » 31 Jan 2023, 14:54

%v1% is representing a numerical variable, and by default that's 0, you could remove that, but keep the comma, and try that
/Ton (PayPal.me)

Arne
New user
Posts: 7
Joined: 31 Jan 2023, 13:46

Re: publish empty MQTT Topic in rules

#3 Post by Arne » 31 Jan 2023, 15:04

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

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: publish empty MQTT Topic in rules

#4 Post by TD-er » 31 Jan 2023, 15:42

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.

Arne
New user
Posts: 7
Joined: 31 Jan 2023, 13:46

Re: publish empty MQTT Topic in rules

#5 Post by Arne » 31 Jan 2023, 15:44

With MQTT Explorer i am able to publish the required topic.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: publish empty MQTT Topic in rules

#6 Post by TD-er » 31 Jan 2023, 15:47

And when you try:

Code: Select all

Publish R/blabla/keepalive,""

Arne
New user
Posts: 7
Joined: 31 Jan 2023, 13:46

Re: publish empty MQTT Topic in rules

#7 Post by Arne » 31 Jan 2023, 16:05

In that case the topic is also not published

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: publish empty MQTT Topic in rules

#8 Post by Ath » 31 Jan 2023, 16:28

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).
/Ton (PayPal.me)

Arne
New user
Posts: 7
Joined: 31 Jan 2023, 13:46

Re: publish empty MQTT Topic in rules

#9 Post by Arne » 31 Jan 2023, 16:38

Sorry, that doesn't change the behaviour.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: publish empty MQTT Topic in rules

#10 Post by Ath » 31 Jan 2023, 16:41

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)
/Ton (PayPal.me)

Arne
New user
Posts: 7
Joined: 31 Jan 2023, 13:46

Re: publish empty MQTT Topic in rules

#11 Post by Arne » 31 Jan 2023, 19:11

Currently It just says:

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

I will try to update the firmware later.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: publish empty MQTT Topic in rules

#12 Post by Ath » 31 Jan 2023, 22:29

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.
/Ton (PayPal.me)

Arne
New user
Posts: 7
Joined: 31 Jan 2023, 13:46

Re: publish empty MQTT Topic in rules

#13 Post by Arne » 01 Feb 2023, 17:29

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 :)

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: publish empty MQTT Topic in rules

#14 Post by Ath » 01 Feb 2023, 22:07

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
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 37 guests