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

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 platformio.ni 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.
delete%20me

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ā€¦
image

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

image

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

[env:heltec_wifi_kit_32]
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

[env:heltec_wifi_kit_32]

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 Heltec WiFi Kit 32 ā€” PlatformIO latest documentation 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.

3 Likes

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
#ifndef
#define LED_BUILTIN 2
#endif

void setup()
{
  // initialize LED digital pin as an output.
  pinMode(LED_BUILTIN, 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.
*/
#define BLINK_GPIO CONFIG_BLINK_GPIO

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
       functions.)
    */
    gpio_pad_select_gpio(BLINK_GPIO);
    /* 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

https://docs.platformio.org/en/latest/projectconf/section_platformio.html#default-envs

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