httpd exposed TaskHandle_t ?

Baldhead
Posts: 515
Joined: Sun Mar 31, 2019 5:16 am
Location: Brazil

httpd exposed TaskHandle_t ?

Postby Baldhead » Tue Oct 21, 2025 1:07 am

Hi,

I would like to know if it is possible to get the TaskHandle_t from the httpd task, if it is only a single task.

I created a centralized task ( "gatekeeper task" ) to access shared data, like (set() and get() functions, all encapsulated functions.

I want to take advantage of this same task to implement some way of notifying/routing information that has changed.

So, i need httpd TaskHandle_t, but I'm open to other suggestions.

I would like to do something like this:

Code: Select all

typedef struct
{        
    server_state_t data;
    my_server_state_command_t cmd_id;
    TaskHandle_t task_handle;    
}mss_task_dev_t;

static QueueHandle_t mss_data_queue = NULL;
mss_data_queue = xQueueCreate( 4, sizeof(mss_task_dev_t) );

// gatekeeper task call this function.
static void task_send_notification_to_interested_tasks(const mss_task_dev_t* mss_msg)
{
    ESP_LOGI(MY_SERVER_STATE_TAG, LOG_USER1("[%s:] Notify Tasks.", __func__));
            
    // Message came from the server ?
    if (mss_msg->task_handle == httpd_task)    
    {
        // test if any data has changed, just notify if the data has changed.
        
        // notify hardware task.
        // notify ui task.        
        // notify all client connected to the server, except the one that sent the information (I need to see how to identify this yet).
    }

    // Message came from the gui ?
    if (mss_msg->task_handle == gui_task)  
    {
        // test if any data has changed, just notify if the data has changed.
            
        // notify hardware task.         
        // update_clients_state();  // notify all clients connected to the server.
    }
}

// Lib interface
void set_server_state(server_state_t st)
{    
    mss_task_dev_t var;
    memset(&var, 0, sizeof(mss_task_dev_t));    
    var.cmd_id = CMD_SET_ALL_STRUCT;
    var.data = st;
    var.task_handle = xTaskGetCurrentTaskHandle();  // handle of the task that called this function.
    
    BaseType_t ret = xQueueSend(mss_data_queue, (void *)&var, 0);
    
    if (ret == errQUEUE_FULL)
    {        
        ESP_LOGW(MY_SERVER_STATE_TAG, "[%s] Queue [mss_data_queue] full, cannot send command to task [%s], returning without blocking the task.", __func__, pcTaskGetName(my_server_state_task_Handle) );        
        return;
    }
}

Thank's.

MicroController
Posts: 2669
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: httpd exposed TaskHandle_t ?

Postby MicroController » Tue Oct 21, 2025 9:37 am

Using task handles may not be the best approach to identify the source of an event: The handles' values may change, e.g. when the HTTPd is restarted in response to network changes. Pre-defined constant values could avoid issues with this; which suggests that the IDF event loop may be a viable alternative for your use case.

Baldhead
Posts: 515
Joined: Sun Mar 31, 2019 5:16 am
Location: Brazil

Re: httpd exposed TaskHandle_t ?

Postby Baldhead » Wed Oct 22, 2025 6:51 pm

Using task handles may not be the best approach to identify the source of an event: The handles' values may change, e.g. when the HTTPd is restarted in response to network changes. Pre-defined constant values could avoid issues with this; which suggests that the IDF event loop may be a viable alternative for your use case.
It's a bit strange that I have to use an identification tag in the set() function, for example:

Code: Select all

// Lib interface
void set_server_state(server_state_t st, task_identification tag)
{    
    mss_task_dev_t var;
    memset(&var, 0, sizeof(mss_task_dev_t));    
    var.cmd_id = CMD_SET_ALL_STRUCT;
    var.data = st;
    var.tag = tag;
    //var.task_handle = xTaskGetCurrentTaskHandle();  // handle of the task that called this function.
    
    BaseType_t ret = xQueueSend(mss_data_queue, (void *)&var, 0);
    
    if (ret == errQUEUE_FULL)
    {        
        ESP_LOGW(MY_SERVER_STATE_TAG, "[%s] Queue [mss_data_queue] full, cannot send command to task [%s], returning without blocking the task.", __func__, pcTaskGetName(my_server_state_task_Handle) );        
        return;
    }
}

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot], Qwantbot, RandomInternetGuy, Semrush [Bot] and 3 guests