How cann I correctly import esp-idf code examples?

I found some similar topics, but found not solution for me.

I want to use this example esp-idf/examples/protocols/http_server/file_serving at master · espressif/esp-idf · GitHub

I have done following:

  1. I have downloaded the compleate esp-idf example folder and copyed the folder …esp-idf-master\examples\protocols\http_server\file_serving to the PlatformIO project folder (C:\Users\{USER_NAME}\Documents\PlatformIO\Projects).
  2. I have created a new PlatformIO project in VSC. (Name: “file_serving”, framework: “ESP-IDF” and default location)
  3. I moved in project folder all files from “main” folder to the “src” folder.

If I open main.c in src folder, I see two errors:
#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (C:\Users\{USER_NAME}\Documents\PlatformIO\Projects\file_serving\src\main.c).” and
“cannot open source file “protocol_examples_common.h””.

I found “protocol_examples_common.h” file in …esp-idf-master\examples\common_components\protocol_examples_common\include and coppyed to include folder of the PlatformIO project. (File CMakeLists.txt helped me.)

If I open “file_server.c” file, VSC give me 17 errors. Most of them are “identifier “HTTPD_404_NOT_FOUND” is undefined”, “identifier “HTTPD_500_INTERNAL_SERVER_ERROR” is undefined”, “struct “httpd_config” has no field “uri_match_fn””, “identifier “httpd_uri_match_wildcard” is undefined” e.t.c.

How I can solve this?

You need to watch out with the version. You’re downloading ESP-IDFs bleeding-edge git version, but PlatformIO uses specific relase versions, currently v3.2. So you need to checkout that branch / tag in github.

Since esp-idf/examples/protocols/http_server/file_serving at master · espressif/esp-idf · GitHub did not exist in the 3.2 release (was added in the 3.3 branch) it won’t work with PlatformIO right now. As seen on The latest stable version of ESP-IDF is v3.2., The latest stable version of ESP-IDF is v3.2., and PIO does not support beta-versions of ESP-IDF.

2 Likes

Thank You!
It’s work.