decode topic MQTT for multi-sensor

mohasrj
Posts: 33
Joined: Mon Jan 20, 2020 9:38 am

decode topic MQTT for multi-sensor

Postby mohasrj » Wed Jul 22, 2020 4:21 pm

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 :
Attachments
topic.png
topic.png (55.35 KiB) Viewed 2519 times

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

Re: decode topic MQTT for multi-sensor

Postby ESP_Sprite » Thu Jul 23, 2020 7:42 am

'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.

Who is online

Users browsing this forum: No registered users and 74 guests