Page 1 of 1

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

Posted: Fri Mar 15, 2019 12:20 pm
by Zeni241
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);

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

Posted: Fri Mar 15, 2019 2:53 pm
by Zeni241
I was missing setting retained flag!
Now following deleted retained message on broker:
esp_mqtt_client_publish(mqttclient, "mytopic"," ",0, 0, 1)

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

Posted: Thu Sep 05, 2024 7:02 am
by regan.xavier
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!

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

Posted: Fri Sep 06, 2024 2:14 am
by ESP_Sprite
You could select the menuconfig option to make the task wdt panic; that should give you a backtrace that may give us more info.

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

Posted: Fri Sep 06, 2024 2:30 am
by chegewara

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

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

Posted: Fri Sep 06, 2024 4:42 am
by regan.xavier
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.