mqtt publish error | transport_read() error: errno=128 esp32

richucj
Posts: 2
Joined: Sat Aug 08, 2020 5:46 pm

mqtt publish error | transport_read() error: errno=128 esp32

Postby richucj » Sat Aug 08, 2020 6:12 pm

Hi all,
I am trying to send a message to dynamically created topic (mqtt).
but it is returning this error every time and it reboots.
E (32573) MQTT_CLIENT: mqtt_message_receive: transport_read() error: errno=128
E (32573) MQTT_CLIENT: mqtt_process_receive: mqtt_message_receive() returned -1

this is the code..

Code: Select all

    if(strstr(dataf, "check")){
              char *token=strtok(dataf,"check_");
              char *topic;
              topic = (char*)malloc( 50 * sizeof(char) );
              strcpy(topic,"vi/ven/vi002/");
              strcat(topic,token);
              topic = realloc(topic,sizeof(topic) * sizeof(int));
              msg_id = esp_mqtt_client_publish(client,topic, "Tr", 0, 1, 0);
     }
what is wrong?
regards,
richu

ESP-Marius
Posts: 74
Joined: Wed Oct 23, 2019 1:49 am

Re: mqtt publish error | transport_read() error: errno=128 esp32

Postby ESP-Marius » Mon Aug 10, 2020 1:41 am

First of all, are you sure your error is related to the dynamically created topic, does it work if you just use a static topic instead?

As for your code:

Code: Select all

topic = realloc(topic,sizeof(topic) * sizeof(int));
What are you trying to achieve here? You do it after strcat, so if this is to protect against overflow then it's already too late. And it probably doesn't do what you want it to do. sizeof(topic) gives you the size of the pointer (4 bytes) not the size of the string. And I'm not sure why you are multiplying it with sizeof(int).

Who is online

Users browsing this forum: No registered users and 172 guests