cancel
Showing results for 
Search instead for 
Did you mean: 

http client lwip stm32h745-DISCO

RafaelS
Associate III

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:

https://community.st.com/t5/stm32-mcus/how-to-create-a-project-for-stm32h7-with-ethernet-and-lwip-stack/ta-p/49308

 

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. :)

4 REPLIES 4

@RafaelS wrote:

When compiling the next error appears: undefined reference to `httpc_get_file' main.c.


It's telling you that it can't find any definition for the httpc_get_file() function.

 


@RafaelS wrote:

I have included the http_client.h in main.c (#include "lwip/apps/http_client.h")


A header file would not be expected to provide a definition - just a declaration (aka "prototype").

So do you actually have a .c file in your project which does define the httpc_get_file() function?

Hello Andrew,

I have download the http folder from https://github.com/yarrick/lwip/tree/master/src/apps/http,

and  after I have added the path of the folder in the Include paths of MCU/MPU GCC Compiler.

 

In the http folder there is an http_client.c that define the httpc_get_file https://github.com/yarrick/lwip/blob/master/src/apps/http/http_client.c in line 641.

Well, your linker is not seeing that.

Is that file actually getting built?

I have selected the option -v and yes, the file are not getting built. I have copied the folder http outside of CM7 project.

I have moved the folder in CM7 and now the function httpc_get_file is compiled.

There were another compiling errors due to some file in makefsdata folder is for WIN or LINUX. In makefsdata.c ->

 

#ifdef WIN32

#define GETCWD(path, len)             GetCurrentDirectoryA(len, path)
#define GETCWD_SUCCEEDED(ret)         (ret != 0)
#define CHDIR(path)                   SetCurrentDirectoryA(path)
#define CHDIR_SUCCEEDED(ret)          (ret == TRUE)

#elif __linux__ || __APPLE__

#define GETCWD(path, len)             getcwd(path, len)
#define GETCWD_SUCCEEDED(ret)         (ret != NULL)
#define CHDIR(path)                   chdir(path)
#define CHDIR_SUCCEEDED(ret)          (ret == 0)

#else

#error makefsdata not supported on this platform

#endif

 

I have deleted the files related to fs, and now there are no compilation errors... but I am not confident that the library I downloaded is suitable for a microcontroller.

Anyway, I have programmed the STM32H745, and the debugger in httpc_get_file function returns an "invalid parameters" error. I will review the function's consistency and the parameters supplied.