How can I send empty mqtt message to broker to delete some retained message?

Zeni241
Posts: 86
Joined: Tue Nov 20, 2018 4:28 am

How can I send empty mqtt message to broker to delete some retained message?

Postby Zeni241 » Fri Mar 15, 2019 12:20 pm

How can I send empty mqtt message to broker to delete some retained message?
I tried following but it is not working:

Code: Select all

esp_mqtt_client_publish(mqttclient, "mytopic"," ",0, 0, 0);
esp_mqtt_client_publish(mqttclient, "mytopic",' ',0, 0, 0);
esp_mqtt_client_publish(mqttclient, "mytopic",NULL,0, 0, 0);

Zeni241
Posts: 86
Joined: Tue Nov 20, 2018 4:28 am

Re: How can I send empty mqtt message to broker to delete some retained message?

Postby Zeni241 » Fri Mar 15, 2019 2:53 pm

I was missing setting retained flag!
Now following deleted retained message on broker:
esp_mqtt_client_publish(mqttclient, "mytopic"," ",0, 0, 1)

regan.xavier
Posts: 4
Joined: Thu Sep 05, 2024 6:45 am

Re: How can I send empty mqtt message to broker to delete some retained message?

Postby regan.xavier » Thu Sep 05, 2024 7:02 am

I am facing an issue while trying to delete a retained message from an MQTT topic. I use the following code to publish an empty message with the retained flag to clear the retained message on the topic:

  1. esp_mqtt_client_publish(mqtt_client, topic, " ", 0, 0, 1);
However, after calling this function, I encounter the following error:
  1. E (28226) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
  2. E (28226) task_wdt:  - IDLE1 (CPU 1)
  3. E (28226) task_wdt: Tasks currently running:
  4. E (28226) task_wdt: CPU 0: IDLE0
  5. E (28226) task_wdt: CPU 1: mqtt_task
  6. E (28226) task_wdt: Print CPU 1 backtrace

Could anyone suggest what might be causing the Task WDT to get triggered in this case? Any insights or suggestions on how to resolve this issue would be highly appreciated!

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: How can I send empty mqtt message to broker to delete some retained message?

Postby ESP_Sprite » Fri Sep 06, 2024 2:14 am

You could select the menuconfig option to make the task wdt panic; that should give you a backtrace that may give us more info.

chegewara
Posts: 2375
Joined: Wed Jun 14, 2017 9:00 pm

Re: How can I send empty mqtt message to broker to delete some retained message?

Postby chegewara » Fri Sep 06, 2024 2:30 am

Code: Select all

    /* Acceptable publish messages:
        data == NULL, len == 0: publish null message
        data valid,   len == 0: publish all data, payload len is determined from string length
        data valid,   len >  0: publish data with defined length
     */
    if (len <= 0 && data != NULL) {
        len = strlen(data);
    }
    
Did you try to send NULL msg instead?

BTW, your message seems to have 1 space in string, it is not empty string

regan.xavier
Posts: 4
Joined: Thu Sep 05, 2024 6:45 am

Re: How can I send empty mqtt message to broker to delete some retained message?

Postby regan.xavier » Fri Sep 06, 2024 4:42 am

Thanks chegewara for the response. I removed the single space in the payload.

And in the AWS after giving the access to receive zero-payloads, it got fixed.

Who is online

Users browsing this forum: No registered users and 102 guests