How to view header file?

In most IDE’s I have used there is a way to open a header file mentioned in the code.
Say you have this in your ino file:

#include <ESP8266WiFi.h>
#include <FS.h>
#include <EEPROM.h>
#include "espconfig.h"

In other IDE’s I can right click the file name and then from the pop-up I can select a command that opens the file in an editor for viewing or editing. It could be “go to file”, “go to definition”, “open file at cursor” etc

But I cannot find the same in Arduino…

Now I really need to check the content of one h file in a library to see how an identifier is declared but I cannot find the file anywhere myself. It is clear that Arduino knows where it is located but I can for the life of me not find it…
Is there an Arduino way to find the path to the header file?

In my current case I want to know how the ESP8266WiFi.h file defines the identifiers WIFI_AP, WIFI_STA, WIFI_AP_STA, WIFI_OFF. The reason? Well, I need to store the value in a configuration struct but I don’t know the range of the values so I cannot define a container…
But this only brings up a deficiency in my understanding of Arduino so in a broader sense I would like to know how this is done in Arduino.
I am using a Windows 7 Pro X64 computer and I have installed Arduino into a non-default location (C:\Programs\Arduino\arduino-1.8.2). All of my working files should be in the data drive D:, but I have seen that Arduino has created a folder inside “My Documents”, a location that I never ever willfully use…

I use Eclipse with Arduino plugin called Sloeber

Can Eclipse find the declaration of for example WIFI_AP_STA?
Or open a header file from the #include entry?
I only have used Eclipse briefly 5 years ago when starting Android app programming until Android Studio was released. Then ditched Eclipse.

Turn on verbose compilation to see where it came from.

In Eclipse it works like you want it. F3 is ‘Open declaration’. It opens the file of the declaration in editor and selects the file in Project Explorer tree. Additionally F3 opens definition from declaration and declaration from definition.

And Eclipse has autocomplete, proper syntax coloring, shows errors and warnings in editor …

In Arduino Eclipse plugin every project has it’s own board and port setting and you have control on libraries used by the project …

Just use grep to search directories for files with specified content :wink: I use it all the time, and not only for source code.

I tried grep already in all locations I could think of:

C:\Programs\Arduino>grep -d+ WIFI_AP_STA *.h *.cpp
<empty result>

C:\Users\*user*\Documents\Arduino>grep -d+ WIFI_AP_STA *.h *.cpp
File libraries\WiFiManager\WiFiManager.cpp:
  WiFi.mode(WIFI_AP_STA);

D:\Engineering\Projects\Subversion\HW\WiFiModule>grep -d+ WIFI_AP_STA *.h *.cpp
File CodeExamples\TCP-UART_Bridge\espconfig.h:
  byte mode; //WIFI_AP, WIFI_STA, WIFI_AP_STA or WIFI_OFF

The only hits as you can see were the WiFiManager.cpp where the identifier is used but not declared and in my own espconfig.h file as a comment on the struct definition line I want to set to the correct data type.
And nowhere could I find the ESP8266WiFi.h file…
It really MUST exist somewhere since it is included in the sketch and it does work.
Is Arduino storing installed libraries somewhere hidden?
Note that I am assuming that the WiFi mode identifiers are defined in the ESP8266WiFi.h file (or includes defined in it) since that is the only WiFi related header I am including, so it baffles me that my system seems not to have a trace of this file.
OTOH I cannot use Windows Search functions since I have a massive disk system on my PC. A 500GB system disk and a 2TB data disk both full to about 80%. Search on the root cannot handle this.

search in C:\Users*user*
the esp8266 package is under hidden AppData folder

C:\Users\Duro\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0

Thanks a lot!
I had no idea Arduino could hide something in AppData/Local!
All other times AppData has been used in other applications and I have had to look for something it was always in AppData/Roaming/..., which I also checked before (unsuccessfully) for an Arduino folder...
Anyway now I got this:

C:\Users\*user*\AppData\Local\Arduino15>grep -d+ WIFI_AP_STA *.h *.cpp
File packages\esp8266\hardware\esp8266\2.4.0\libraries\ESP8266WiFi\src\ESP8266WiFiType.h:
    WIFI_OFF = 0, WIFI_STA = 1, WIFI_AP = 2, WIFI_AP_STA = 3
File packages\esp8266\hardware\esp8266\2.4.0\libraries\ESP8266WiFiMesh\src\ESP8266WiFiMesh.cpp:
        WiFi.mode(WIFI_AP_STA);
                        WiFi.mode(WIFI_AP_STA);

And my search for the values is done! :slight_smile:
Also I learned a new item about the way Arduino stores stuff....
It would have been nice if the Arduino IDE at least could have a right-click menu item "Find declaration" when clicking on a known identifier (this is colored green so I assume the IDE knows about it)...

the coloring in Arduino IDE is a fake. it uses only the keywords.txt file in libraries.

in Eclipse a tooltip with the value of the define constant is shown on mouse-over.

BosseB:
I had no idea Arduino could hide something in AppData/Local!

Well, you would have if you had followed the suggestion in reply #3...

I agree that it would be very nice if the Arduino IDE allowed you to easily open header files. In addition to other benefits, that would be a very good learning tool. I think a lot of Arduino users treat libraries as black boxes, not even really knowing where on the computer they are stored. I think a natural part of the progression from beginner to amateur should be getting curious about what's going on under the hood and opening up some of these library source files to have a look. You can learn a lot doing that.

pert:
Well, you would have if you had followed the suggestion in reply #3...

Interesting, I have to look for that the next time I am having verify problems.
The panel where the messages are displayed is very hard to read, though...
Whoever could have invented using dark red against black background. Not really adapted to human vision...
Or maybe there is some configuration for this in the settings?

I agree that it would be very nice if the Arduino IDE allowed you to easily open header files.
In addition to other benefits, that would be a very good learning tool.
I think a lot of Arduino users treat libraries as black boxes, not even really knowing where on the computer they are stored.

Another drawback of stuffing away things in different hidden locations is that it makes it much harder to version the code development. If part of what is used in building a specific project reside in locations like these it is difficult to make a full working project using Subversion for example...
I looked at File/Preferences and found that there is something called "Sketchbook location", which has been set to "MyDocuments\Arduino", i.e. on the system drive rather than the data drive. What goes into this directory?
Right now it contains something called ConfigManager and WiFiManager, I recognize the names since I have had a look at code in GitHub with similar names.

BosseB:
The panel where the messages are displayed is very hard to read, though…
Whoever could have invented using dark red against black background. Not really adapted to human vision…
Or maybe there is some configuration for this in the settings?

Copy and paste into the text editor of your choice.

BosseB:
The panel where the messages are displayed is very hard to read, though...
Whoever could have invented using dark red against black background. Not really adapted to human vision...
Or maybe there is some configuration for this in the settings?

another reason why I use Eclipse :slight_smile:

BosseB:
Another drawback of stuffing away things in different hidden locations is that it makes it much harder to version the code development. If part of what is used in building a specific project reside in locations like these it is difficult to make a full working project using Subversion for example...

the libraries and core packages are versioned on GitHub

BosseB:
I looked at File/Preferences and found that there is something called "Sketchbook location", which has been set to "MyDocuments\Arduino", i.e. on the system drive rather than the data drive. What goes into this directory?
Right now it contains something called ConfigManager and WiFiManager, I recognize the names since I have had a look at code in GitHub with similar names.

MyDocuments\Arduino is default folder of Arduino IDE for saving sketches, downloaded libraries and tools (in subfolders called libraries and tools)

BosseB:
Interesting, I have to look for that the next time I am having verify problems.

Typically when there's just a compilation error you don't need to turn verbose compilation output because error messages are always shown even with verbose compilation output turned off. In fact I usually leave it off because it just clutters up the output a lot because it shows every command that it run during the compilation process, rather than just the output. But in certain cases it's very useful to see those commands. You can turn it on at File > Preferences > Show verbose output during: compilation.

What I do have always turned on is File > Preferences > Compiler warnings: All and File > Preferences > Show verbose output during: upload.

BosseB:
The panel where the messages are displayed is very hard to read, though...
Whoever could have invented using dark red against black background. Not really adapted to human vision...

They did recently switch to a brighter red... but yeah, I'm not a big fan of the black background thing. Some people swear by it but I suspect it of being mostly a fashion statement for computer nerds.

BosseB:
Or maybe there is some configuration for this in the settings?

There is. You can change most of the colors and fonts of the IDE if you like. I have attempted to make this easy with documentation and a test sketch here:

Specifically the properties you would want to change are console.color and console.error.color. Of course if you change console.color to white then the white non-error text won't show up so well anymore so you would also want to change console.output.color. You can find those properties in lib/theme/theme.txt under the Arduino IDE installation folder. After editing that file, you need to restart the IDE before the changes will take effect.

BosseB:
Another drawback of stuffing away things in different hidden locations is that it makes it much harder to version the code development.

In the case of a hardware package like ESP8266 core for Arduino, I'd probably just be satisfied with specifying the version you used in the documentation. If you really want to go down the path of having all dependencies in your repository they you'll need to have the full toolchain and the Arduino IDE in there and your repository will be huge and cluttered with binaries! It could be nice to have a complete snapshot of the entire development environment when the project is finished and that should be possible by setting the Arduino IDE to portable mode:

which will cause the ESP8266 core for Arduino to be installed to the portable subfolder of the IDE. Then you have everything in one place.

Juraj:
I use Eclipse with Arduino plugin called Sloeber

I'll take you up on this! I am getting more disturbed by having to use the Arduino IDE plus Notepad++ in order to program an application, which should be done in one and the same IDE...
I looked in my PC and found an old (from Oct 2012) Eclipse installation created when I was looking at working with Android development. But we later switched to Android Studio and after that I have not used it. So I deleted the installation directory. Also had to go around looking at places like AppData and the like to get rid of artifacts of Eclipse...
Then I downloaded and used the Eclipse Oxygen installer to get the IDE for C/C++ in place.

Oh, I also found this newsletter where the developer of an Arduino Eclipse plug-in describes the install process and usage thereafter. But it seems to be about another Arduino Plug-In than Sloeber...

After I have installed the Eclipse IDE for C/C++ and started it I opened the Eclipse Marketplace and searched for Arduino.
There were 3 suggestsions (even though it said it found 4 matches):

  • The Arduino Eclipse plugin named Sloeber V4
  • The Arduino Eclipse IDE named Sloeber (Product) V4
  • Eclipse C++ IDE for Arduino 3.0

Now I am confused since there seems to be two Sloebers here and the last one seems to be the one described in the newsletter I linked to. What is the difference?
Can all 3 be installed in parallel?
What do you recommend I should do?
Is one simpler than the other to get used to?
Which has the better documentation and usage guide?

(I guess this has become a bit off-topic, but it is anyway related to viewing header files...)

I found the site for the Eclipse Arduino plugin
And here are installation advice that tells me to download the product and not Eclipse itself or such.
So I am doing this now.

Juraj:
In Eclipse it works like you want it. F3 is ‘Open declaration’. It opens the file of the declaration in editor and selects the file in Project Explorer tree. Additionally F3 opens definition from declaration and declaration from definition.

I installed the “product” Sloeber, which included Eclipse and other stuff.
Then I opened the existing project “from file system”.
Now I get a proper project view with all files listed to the left and if I double click one of them it opens to the right, so far so good.
If I now rightclick the #include “espconfig.h” line and select “Open declaration” or hit F3, then it opens the file and jups to that tab. Fine.
But if I do the same on the line #include <ESP8266WiFi.h> then nothing at all happens, not even an error message is shown…
So maybe it is only able to deal with local project files?
When I put the cursor on the identifier WIFI_AP and hit F3 or right-click and select “Open declaration” nothing at all happens there too. And it does not show the identifier value when I hover the mouse over it either.

And if I put the cursor ins the ino file on a function call which is implemented in the espconfig.cpp file and hit F3, nothing happens instead of the expected jump to the function body or the declaration in the h file.

And Eclipse has autocomplete, proper syntax coloring, shows errors and warnings in editor …

I tried toi start writing a line to set one struct member value. But after writing ESPConf. nothing appeared while I expected an autocomplete list of struct members to show up.

In Arduino Eclipse plugin every project has it’s own board and port setting and you have control on libraries used by the project …

Where can I find these? I tried locating the stuff I used in the Arduino IDE like defining the flash and which board (generic ESP8266), but could not find that.

Maybe related:
Finally, hitting the Verify button does not start any expected activity at all and there is no message either.
It seems like something important is missing.

try first to create a new project of type Arduino sketch

Thanks!
I took your advice and it seems to work now, even verify could run to the end.
Have not tested the resulting binary yet though.

I created a new Arduino sketch project and copy/pasted the content of my original ino file into the empty ino created by the new project wizard.
I also needed my cpp and h file, but I could find no way to add existing files into the project. No function to add a file into the project anywhere I looked. I only found the upper left "New" button but it created a new blank file and overwrote the file I had copied into the new project folder!
So I could not copy in existing source files to the project dir and simply add them into the project, like I can for all other dev IDE's I have used. Must be there but I could not find it.
Anyway, now the F3 button works to find the identifier declarations and the other IDE stuff we discussed above!

Is there really no way to open an existing Arduino sketch project in Sloeber IDE?