MQTT duplicated messages

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
agroszer
Normal user
Posts: 28
Joined: 02 Jan 2023, 16:36

MQTT duplicated messages

#1 Post by agroszer » 23 Oct 2023, 08:43

Hi,

I'm getting here MQTT messages duplicated, like:

Code: Select all

Topic: homeassistant/esp_01_3/bojler/Temperature
22
2023-10-23 08:28:22:807

Topic: homeassistant/esp_01_3/room/Temperature
22.2
2023-10-23 08:28:22:903

Topic: homeassistant/esp_01_3/room/Humidity
52
2023-10-23 08:28:23:006

Topic: homeassistant/esp_01_3/bojler/Temperature
22
2023-10-23 08:28:23:108

Topic: homeassistant/esp_01_3/room/Temperature
22.2
2023-10-23 08:28:23:209

Topic: homeassistant/esp_01_3/room/Humidity
52
2023-10-23 08:28:23:310
I'm building a battery powered sensor, so having the least communication and uptime would be great.

MQTT config as attached, sensor update interval is 9999 seconds.

I'm using a rule to measure, submit and sleep:

Code: Select all

On MQTT#Connected Do //when the broker is connected
  If [sleepenabled#State]=1
    taskrun,1 // run and send to MQTT
    taskrun,2 // run and send to MQTT
    // deepsleep,300 //go to deepsleep
    timerSet,1,1
  EndIf
EndOn

On Rules#Timer=1 Do
  deepsleep,300 //go to deepsleep
EndOn
Attachments
Screenshot_2023-10-23_08-40-13.png
Screenshot_2023-10-23_08-40-13.png (70.42 KiB) Viewed 1441 times

bidrohini
Normal user
Posts: 106
Joined: 03 Nov 2022, 16:24

Re: MQTT duplicated messages

#2 Post by bidrohini » 07 Nov 2023, 13:26

9999 seconds interval is extremely long. The sensor may be retransmitting the same data before it goes into deep sleep. You can make this interval smaller to see if the duplication disappears.

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

Re: MQTT duplicated messages

#3 Post by TD-er » 07 Nov 2023, 16:26

@bidrohini

The Task interval in ESPEasy is used to schedule a new call to PLUGIN_READ.
However whenever the task is run by using the command "taskrun", the scheduler will schedule a new call to PLUGIN_READ again at that moment using the "Interval" setting.

Thus the interval of 9999 is perfectly fine as it will probably never automatically call PLUGIN_READ as it would have been called in the mean time via the "TaskRun" command via rules.


About the duplicated messages.
Does ESPEasy loose connection often?
Or maybe the MQTT broker does not acknowledge the published messages and the controller thus retries to send?
Maybe you can also set the nr. of retry attempts in the controller settings to 0?

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], angelo67, Semrush [Bot] and 35 guests