Expanding existing ESP-IDF project to make an HTTP call

66 views Asked by At

Trying to expand this project with a simple additional function - make a HTTP GET call.

  1. I have downloaded this HTTP client and put it in the compoenents folder
  2. I made sure the CMakeLists.txt file exists with the following content
FILE(GLOB_RECURSE app_sources "./src/*.c")

idf_component_register(
                    SRCS ${app_sources}
                    INCLUDE_DIRS "./include"
                    REQUIRES esp_http_client esp-tls json
                    )
  1. I then proceed to add #include <http_rest_client.h> in one of the apps, specifically in main\apps\app_temp_demo\gui\gui_temp_demo.cpp
  2. Added a function that perform the call as per example(s) in the library repo
void sendrequest()
{
    http_rest_recv_buffer_t response_buffer = {0};

    // do the request
    ESP_ERROR_CHECK(http_rest_client_get("https://catoftheday.com/", &response_buffer));

    char buffer[50]; // Buffer to hold the resulting string
    int status_code = response_buffer.status_code; // Your status code
    sprintf(buffer, "Status Code %d", status_code); // Write to buffer

    // print response status
    // sprintf("Status Code %d", response_buffer.status_code);

    // do something with the data
    printf("%s", response_buffer.buffer);

    // clean up
    http_rest_client_cleanup(&response_buffer);    
}

Up to this point building the project (idf.py build) is a success, unfortunately once I add a call to hte sendrequest function I get the following warnings/errors:

enter image description here

It feels like the library isnt picked up and built. Any suggestion on what I might be missing or potentially a better approach i.e. differnt library, etc?

1

There are 1 answers

0
sebo1234 On

Going out on a limb here after scanning the projects you are referencing, but I think you are missing the extern C hence your want to use a C library in a C++ project.
Adding something like

extern "C"{
#include <http_rest_client.h> 
}

should help. Alternatively you could adapt the header files of the referenced component.