How to pass payload to a task
Posted: Tue Oct 02, 2018 8:39 pm
Hi,
I'd like to pass the payload (event->data and event->topic) to a task from the mqtt_event_handler.
The event handler receives a pointer to the struct esp_mqtt_event_handle_t and it can be processed in the event handler itself.
In my understanding this event handler is kind of call back function and data processing which might consume time and/or requires other resources is not suggested to be placed here. Therefore I'd like to move the processing to a separate task which can be notified from within the event handler.
What is not clear for me is the availability of the event struct. I guess this is created/instantiated somewhere in the mqtt driver and a pointer is passed to the event handler. So passing this pointer forward to my task is not safe. This struct might/will be destroyed by the driver some time. If I want to ensure that the payload is available for my task I have to create a copy of it. And not only the event struct, but also the data and topic buffers, since these fields are only pointers to the exact data.
Can someone explain this process in more detail? Is there an example available for a similar solution?
Thanks for your kind help in advance.
Best regards,
Blaise
I'd like to pass the payload (event->data and event->topic) to a task from the mqtt_event_handler.
The event handler receives a pointer to the struct esp_mqtt_event_handle_t and it can be processed in the event handler itself.
In my understanding this event handler is kind of call back function and data processing which might consume time and/or requires other resources is not suggested to be placed here. Therefore I'd like to move the processing to a separate task which can be notified from within the event handler.
What is not clear for me is the availability of the event struct. I guess this is created/instantiated somewhere in the mqtt driver and a pointer is passed to the event handler. So passing this pointer forward to my task is not safe. This struct might/will be destroyed by the driver some time. If I want to ensure that the payload is available for my task I have to create a copy of it. And not only the event struct, but also the data and topic buffers, since these fields are only pointers to the exact data.
Can someone explain this process in more detail? Is there an example available for a similar solution?
Thanks for your kind help in advance.
Best regards,
Blaise