http client lwip stm32h745-DISCO
Hello!
I need to implement a task in FreeRTOS for my project that makes GET, POST, and PATCH requests to a server. So far, I have managed to send a UDP message to a specific port on a PC thanks to the following post:
Now, I would like to implement the task to send the requests. I have searched the forum but haven't found a clear conclusion. What catches my attention is that in the project I created with STM32CubeMX, there is the file http_client.h in Middleware -> Third_Party -> LwIP -> src -> include -> apps, but I can't find the http_client.c file with the functions.
I have found in the following link (https://github.com/yarrick/lwip/blob/master/src/apps/http/http_client.c) I have copy the http folder in Middleware -> Third_Party -> LwIP -> src -> apps.
And I have tried with the following code:
void http_get_task(void const *pvParameters) {
// Initialize the LWIP stack (only if not already initialized elsewhere)
lwip_init();
// HTTP connection settings
httpc_connection_t settings;
settings.use_proxy = 0; // No proxy
settings.result_fn = http_result_callback;
settings.headers_done_fn = http_headers_done_callback;
ip_addr_t server_addr;
IP4_ADDR(&server_addr, 192, 168, 4, 250); // Server IP address
const char *uri = "/path/to/resource"; // Resource URI
u16_t port = 3000; // Server port
httpc_state_t *connection = NULL;
// Make the HTTP GET request
err_t err = httpc_get_file(&server_addr, port, uri, &settings, NULL, NULL, &connection);
if (err != ERR_OK) {
printf("Failed to start HTTP GET request. Error: %d\n", err);
vTaskDelete(NULL); // Delete the task if the request fails
return;
}
printf("HTTP GET request initiated. Waiting for response...\n");
// Main task loop to handle timeouts and connection
while (connection != NULL) {
sys_check_timeouts(); // Process LWIP timeouts
vTaskDelay(pdMS_TO_TICKS(100)); // Delay to avoid busy-waiting
}
printf("Task complete. Exiting.\n");
vTaskDelete(NULL); // Delete the task when done
}
When compilig the next error appears: undefined reference to `httpc_get_file' main.c. I have included the http_client.h in main.c (#include "lwip/apps/http_client.h"). Also I have verified that the macros LWIP_TCP && LWIP_CALLBACK_API are at 1.
Apart from these compilation issues, I wonder if I am heading in the right direction or if there is another way to set up an HTTP client. Any help is welcome, thanks. :)
