PlatformIO Community

N00B - cannot open source file "WiFi.h"

I imagine that it is an include path problem, but how to configure it?

Should I, for instance, have included some Arduino libraries, since I am trying to make an ESP32 project?

Or am I supposed to use FreeRTOS (I would prefer bare metal), as in the espidf-http-request example? It seems overly complex; not that I am afraid of raw sockets, but I just expected more abstraction, as is offered by WiFI.h

Sorry to ask such a bassic question, but I want to get away from the Arduino IDE.

Hmmm, the arduino-wifiscan demo does #include <WiFi.h> but I can’t see anything in any of its project files setting the -I include path for the compiler.

Is there a good tutorial to get me started with PlatfrormIO (VS Code) and the ESP32?

Lets go back to the start… what is the actual problem? :laughing: I’m guessing that you’re getting a warning in the problems tab of VSCode about not being able to see the include, and red squiggles under the #include line?

If you haven’t compiled any code yet, PlatformIO probably hasn’t finished downloading the required files, hence they don’t exist, meaning it’s technically a valid error. When you build your code, PlatformIO will download anything else it needs to do the build, and get on with it. If you’ve successfullly build your code, you may need to do the Rebuild IntelliSense Index project task (under the ProjectIO alien head icon in the activity bar/sidebar). Alternately, close the project, and open it again - that may be enough to make IntelliSense refresh.

You shouldn’t need to edit any include paths - platformio does that itself. If you do ever need to, you should do it through the build_flags parameter of your platformio.ini. I would link to the correct page on the documentation page, but the docs server is having a nap right now… :confused: … I have this link in my history, so hopefully it’s the right page about the parameter! :smiley:

1 Like

Lets go back to the start… what is the actual problem? :laughing: I’m guessing that you’re getting a warning in the problems tab of VSCode about not being able to see the include, and red squiggles under the #include line?

Yes, that is what it is. BUT, it is after I have tried to build.

When you build your code, PlatformIO will download anything else it needs to do the build, and get on with it.

This does not seem to be happening. Do I need to install any libraries?

I do see WiFi.h under c:\Users\me.platformio\packages\framework-arduinoespressif32\libraries\WiFi\src I guess I could just add a -I directive in my as you describe, but, since you said

You shouldn’t need to edit any include paths - platformio does that itself

I wonder why it is not doing so in this case …

Thanx a 1,000,000 for your help. I really want to get away from the Arduino IDE to something modern - with a debugger (I had been thinking of Eclipse, since we use that at work, but PlatformIO seems to have great support for ESP32)

So does the build fail? Or is it just the sqiggle and and the entry in Problems? As if it builds successfuly, the problem is obviously not missing files or even include paths (as the compiler can find stuff just fine), but the Microsoft C++ extension’s IntelliSense being screwy again

Perhaps you could show a copy of the log if it is failing… use triple backticks (```) before and after to format it as a code block.

1 Like

It is definitely a compiler error, not just IntelliSense:

	"resource": "/g:/_PlatformIo/Heltec_Wifi_Kit_with_OLED_server_demo/src/main.cpp",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (G:\\_PlatformIo\\Heltec_Wifi_Kit_with_OLED_server_demo\\src\\main.cpp).",
	"startLineNumber": 1,
	"startColumn": 1,
	"endLineNumber": 1,
	"endColumn": 18

	"resource": "/g:/_PlatformIo/Heltec_Wifi_Kit_with_OLED_server_demo/src/main.cpp",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "cannot open source file \"WiFi.h\"",
	"startLineNumber": 1,
	"startColumn": 1,
	"endLineNumber": 1,
	"endColumn": 18

When I was adding the #include, there was a drop-down with all known includes (presumably from the standrad include paths).

As you can see from the attached screen shot, WIfI.h was not in it.

Thank you once again for your help.

So when you build the code, it fails? As that is a compiler error.

i.e. This is not a compiler error:

This minor novels worth of errors isn’t either…

wth? Why are linux style include paths being generated on windows? Hm… perhaps that update to the C++ extension from July 22 (0.24.1) is playing up… revert back to 0.24.0…

restart vscode… delete .vscode folder and rebuild intellisense index… much bettter… just the normal two for this project!


Bleeding hell Microsoft… STOP BREAKING INTELLISENSE!

As you can see from

 cannot open source file \"WiFi.h\"

`it is 100% definitely a compiler error, and not just IntelliSense.

Just like Eclipse, if you use that, I always ignore the “problems” tab & look at the compiler output, because Eclipse version of IntelliSense doesn’t always parse correctly. But, the compiler does.

This is a compiler error; it can’t find WiFi.h; I could, per your suggestion, add a -I option to the build flags in platformio.ini, but since you think that PlatformIO itself should do that, I was hoping for another solution.

Any ideas? Thanks again

Can you answer the question that has been asked multiple times… Does the code build (as this is when it compiles, not before) successfully?

If it does, then your premise of

it is 100% definitely a compiler error, and not just IntelliSense

is 100% incorrect, and we need to found out what IS going on.

What operating system are you using? Windows/Mac/Linux/other?

Have you tried reverting the C/C++ extension to 0.24.0 as I pointed out in the last reply, which fixed the issue for me, as it was introduced by an update to that extension… which as you can see from the description, provides the IntelliSense functionality.

1 Like

Can you answer the question that has been asked multiple times… Does the code build (as this is when it compiles, not before) successfully?

I thought that I had answered it - multiple times :slight_smile: It is 100% a compiler error message; the software does not build (and I have zer0 interest in Interllisense).

What operating system are you using? Windows/Mac/Linux/other?
Windows 10

Have you tried reverting the C/C++ extension to 0.24.0 as I pointed out in the last reply

Not yet, but I can try this evening - IF it will help the very obvious include path problem. I don’t really care about Intellisense.

Thanks a 1,000,000 for your help and, above all, for your patience.

As I said before, I can probably fix this compiler error by adding the path to WiFi.h with a -I option to the build flags, but would prefer to have PlatformIO do its thing, as you have descried, and add it automagically.

Ok, sorry… I just wasn’t sure… as instead of including a build log when you said it was a compiler issue, you included the output from the ‘problems’ tab… which is stuff generated by IntelliSense…

So, on Windows 10, reverting to 0.24.0 may fix the issue… I was on Windows when it blew up on me the other day… When IntelliSense works… it’s great… it does all the auto-completion, suggestions, sometimes finds errors without having to compile… but when it doesn’t… boy is it a pain!

If that doesn’t work, next step is to look at the .vscode\c_cpp_properties.json to see how the includePath is being auto-generated… i.e. for some strange reason… it said it was a Linux configuration… even though I was on Windows at the time… and deleting the .vscode folder doing a rebuild intellisense index (which does more than just a rebuild, it also triggers other files to be re-written, such as c_cpp_properties.json, launch.json, etc) … it still wanted to do linux paths and configuration, until I rolled back the extension version. It could just be a coincidence, but it’s working for me now… so it’s worth a try. :slight_smile:

Just double checking… you do have at least

framework = arduino
platform = espressif32

specified for the environment/board you’re trying to build, don’t you?

Sorry, I have visiors from overseas & haven’t had time to get back to you, despite your htrying so hard to help me.

Things should be back to normal tomorrow (Monday), and I can reply in more detail then, but one thing does leap out at me.

Here’s my platformio.ini, and NO, I do not have

     framework = arduino

I read somewhere online that I should use

 platform = espressif32

is that not correct? I imagine that WiFI.h is an Arduino IDE library, but wound expect there to be a similar for Esprssif.

Why would I not use platform = espressif32, when my ESP32 is an Espressif device, not an Arduino? Sorry to sound dumb, but I am a n00b :slight_smile:

Thanks again for your help, and for your patience :slight_smile:

1 Like

No worries… there’s always something that gets in way… life, work, timezones, etc :wink:

Well, there’s the problem. :laughing:

Generally for any given project, you’ll want to specify which platform you’re using… e.g. espressif32, espressif8266, atmelavr, ststm32. At this point, PlatformIO knows which group of compilers, board definitions, toolchains it needs to use / download if missing. But it doesn’t know which specific framework you’re using… e.g. arduino, espidf, pumbaa, simba. Once you’ve specified that, everything will start falling into place.

PlatformIO will then be able to update include paths as needed to point to the correct version that platform’s framework. IntelliSense will be able to see the libraries from that framework, so can start doing the ‘realtime’ checks of your code, offering auto-complete choices, etc. And finally, since the include paths are correct, the compiler will find the libraries it needs… that’s the idea, anyway!

Basically you should have three lines to start with for any given ‘environment’ in your platformio.ini… what platform are you targeting, what framework of that platform are you using, and specifically, what board.

1 Like

Things become clearer …

Here’s my platformio.ini

platform = espressif32
board = heltec_wifi_kit_32
framework = espidf
monitor_port = COM3
monitor_speed = 74880
upload_port = COM3
upload_speed = 115200

Can you see anything wrong with it? I would have thought that the section name


would obviate the need for specifying the board (?)

Is there anything wrong with the platform & framework which I have specified? After all, the board is an Espressif ESP32, and not an Arduino.

I would imagine that Espressif and Arduino have different library structures t achieve the same ends.

The platformIO docs for the board at seem to indicate that I have choice of frameworks.

Is that true? If so, is either “better”, whether in terms of better for the board, or support - documentation, code samples, etc

I have been a professional embedded developer for an few decades now, but on larger projects such as satellites, and am just getting into Single Board Computers. I played around with Raspberry Pi, but don’t see the need for Linux, so looked at the ESP32. I have used FreeRTOS in the past, but again do not see the need for it.

What I am looking for are some “hello world” type code samples, into which I can shoehorn my own apps. I would prefer C, but could live with C++ or MircoPython if I can load pre-compiled, rather than interpreted Python. I am not afraid of raw sockets, but would expect wrapper libraries, such as WiFi.h

I am looking for examples for WiFi, BLE advertising (from tracking) and LoRa. Do you have any pointers?

Thanks again for the excellent help.

While you can use the ESP32 with either the Arduino or ESP-IDF framework, WiFi.h is part of the Arduino framework and therefore not available with the ESP-IDF framework.

So either change the framework to:

framework = arduino

or switch to ESP-IDFs code for Wi-Fi.


No, because that does not necessarilly have any connection to the board… I could have [env:TweetyBird] and [env:Sylvester] as my environments, and it would work just fine… that is just the name that is used to reference that environment, that configuration block.

From what you’re describing as your needs, you want the Arduino framework, not the ESP-IDF… at least for starters, anyway. It’s the difference between a blink program looking like

Using Arduino framework:

#include <Arduino.h>

// Set LED_BUILTIN if it is not defined by board variant
#define LED_BUILTIN 2

void setup()
  // initialize LED digital pin as an output.

void loop()
  digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
  delay(1000); // wait for a second
  digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
  delay(1000); // wait for a second

Using ESP-IDF framework:

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "sdkconfig.h"

/* Can run 'make menuconfig' to choose the GPIO to blink,
   or you can edit the following line and set a number here.

void blink_task(void *pvParameter)
    /* Configure the IOMUX register for pad BLINK_GPIO (some pads are
       muxed to GPIO on reset already, but some default to other
       functions and need to be switched to GPIO. Consult the
       Technical Reference for a list of pads and their default
    /* Set the GPIO as a push/pull output */
    gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
    while(1) {
        /* Blink off (output low) */
        gpio_set_level(BLINK_GPIO, 0);
        vTaskDelay(1000 / portTICK_PERIOD_MS);
        /* Blink on (output high) */
        gpio_set_level(BLINK_GPIO, 1);
        vTaskDelay(1000 / portTICK_PERIOD_MS);

void app_main()
    xTaskCreate(&blink_task, "blink_task", configMINIMAL_STACK_SIZE, NULL, 5, NULL);

As you can see… whilst they both do the same thing… the Arduino form is shorter, as more stuff is done for you in libraries… but with the ESP-IDF, you have more control… so there can sometimes be a trade off… simplicity and speed vs complexity and control.

1 Like

@ manuelbl and @ pfeerick Thank you both extremely much for such help!

Things are much clearer to me now, especially that I have a choice of frameworks. I will investigate them both, probably starting with the simpler Arduino.

pfeerick, with reverence to environments, how do I specify which one to use, if there are several in my platfrmio.ini ? Is there a link to the documentation?

There’s two ways… you can specify the default environment when you hit the ‘Build’ button in the status bar, or press the keyboard shortcut

The way I do it, because I don’t want to keep editing plaformio.ini when changing boards, as any changes to the file triggers a full recompile the next time you try to build, is to use the project tasks menu…

1 Like