Page 1 of 1

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

Posted: Sat Aug 08, 2020 6:12 pm
by richucj
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

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

Posted: Mon Aug 10, 2020 1:41 am
by ESP-Marius
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).