Page 1 of 1

decode topic MQTT for multi-sensor

Posted: Wed Jul 22, 2020 4:21 pm
by mohasrj
hi all,

iam using application with multi-sensor so i need to subscribe to may topic ,
usign ** mqtt_event_handler(esp_mqtt_event_handle_t event) ** https://github.com/espressif/espidf/blo ... app_main.c

the examples works fine, but to be honest I have not understood the concept how to use it right.

for subscribe iam using case MQTT_EVENT_DATA i dont know if there another method ?

so i want to decode topic but i have problem :

Re: decode topic MQTT for multi-sensor

Posted: Thu Jul 23, 2020 7:42 am
by ESP_Sprite
'topic' is not a zero-terminated string, so you cannot use 'strdup' on it. Suggest you malloc() a char array of the needed length (+1 for the zero terminator) manually, memcpy() the string into it and add the terminating zero at the right location.