arduino_secrets.h: No such file or directory

Hello, I am breaking in my MKR1000 board that I got for Christmas by testing it using the using the WiFiRTC tutorial, found here: https://www.arduino.cc/en/Tutorial/WiFiRTC. Because I’m not familiar with the WiFi101 library I found that needing to include an arduino_secrets.h header file difficult to use since I don’t know how to use it. Can someone help me get my desktop IDE to find the file that I made?

I have the header file defined like so:

#define SSIDVariable "SSID"
#define PASSWRDVariable "PASSWORD"

I have the file located in three places on my computer:
$ ~/Arduino
$ ~/Arduino/libraries
$ ~/Downloads/arduinoIDE/libraries

Error code:

Arduino: 1.8.8 (Linux), Board: "Arduino/Genuino MKR1000"

error: arduino_secrets.h: No such file or directory
 #include <arduino_secrets.h>

Hello!
The last time I looked into including a custom header into the Sketch idea, which was a long time before this family of boards was released.

The idea is that when a header was declared using “< >” those things, it meant that the header was part of the code based used by the IDE to translate your sketch into a machine runnable binary.

It can’t find yours because it is not included as part of the collection when setup that way. Instead enclose it using the method " " instead. so that it would look like “header name” where header name is your custom job. Oh and remember to include the particulars of your WiFi enabled network in the header.

Strange, I took away the <> and added the " " but the problem persists:

Arduino: 1.8.8 (Linux), Board: "Arduino/Genuino MKR1000"

useRTCviaWiFi:7:29: error: arduino_secrets.h: No such file or directory
 #include "arduino_secrets.h"
                             ^
compilation terminated.
exit status 1
arduino_secrets.h: No such file or directory

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

The intention is that the file would be in the sketch folder. Additional files are shown as tabs in the Arduino IDE:

  • Click the downwards pointing triangle button near the top right of the Arduino IDE window.
  • Click “New Tab”.
  • Give the new file the name arduino_secrets.h
  • Click “OK”.
  • Add your code to the arduino_secrets.h tab.

You should use the double quotes syntax in your #include directive for this file.

I recommend deleting all the extra arduino_secrets.h files you scattered through your hard drive, as these are likely to cause confusion in the future.

It is possible to install this file as a library, as you were attempting to do. That is not the standard way to implement a secret tab. The downside is that you will not be able to easily edit the file using the Arduino IDE. The benefit would be that it allows you to share the same secret definitions between multiple sketches and that it makes it easy to share the sketch without accidentally revealing your secret information. The way you would use the arduino_secrets.h file as a library is:

  • Create the folder {sketchbook folder}/libraries/arduino_secrets. {sketchbook folder} location is set at File > Preferences > Sketchbook location
  • Create the file {sketchbook folder}/libraries/arduino_secrets/arduino_secrets.h with the definitions of your secret information.

You missed the crucial step of creating a folder for the library. You can’t just dump files straight into the libraries folder.

doctorwho8:
The idea is that when a header was declared using “< >” those things, it meant that the header was part of the code based used by the IDE to translate your sketch into a machine runnable binary.

The #include <foo.h> syntax causes the libraries folders to be searched for the file. The #include “foo.h” syntax causes the current folder (in this case the sketch folder) to be searched for the file, then the libraries folders. That’s all there is to it. Always use the double quotes syntax for local files. Always use the angle brackets syntax for external libraries.

pert:
The intention is that the file would be in the sketch folder. Additional files are shown as tabs in the Arduino IDE:

  • Click the downwards pointing triangle button near the top right of the Arduino IDE window.
  • Click “New Tab”.
  • Give the new file the name arduino_secrets.h
  • Click “OK”.
  • Add your code to the arduino_secrets.h tab.

You should use the double quotes syntax in your #include directive for this file.

I recommend deleting all the extra arduino_secrets.h files you scattered through your hard drive, as these are likely to cause confusion in the future.

It is possible to install this file as a library, as you were attempting to do. That is not the standard way to implement a secret tab. The downside is that you will not be able to easily edit the file using the Arduino IDE. The benefit would be that it allows you to share the same secret definitions between multiple sketches and that it makes it easy to share the sketch without accidentally revealing your secret information. The way you would use the arduino_secrets.h file as a library is:

  • Create the folder {sketchbook folder}/libraries/arduino_secrets. {sketchbook folder} location is set at File > Preferences > Sketchbook location
  • Create the file {sketchbook folder}/libraries/arduino_secrets/arduino_secrets.h with the definitions of your secret information.

You missed the crucial step of creating a folder for the library. You can’t just dump files straight into the libraries folder.
The #include <foo.h> syntax causes the libraries folders to be searched for the file. The #include “foo.h” syntax causes the current folder (in this case the sketch folder) to be searched for the file, then the libraries folders. That’s all there is to it. Always use the double quotes syntax for local files. Always use the angle brackets syntax for external libraries.

Hello!
My Arduino programming is rusty, in fact it was last used on a Galileo board, whereas it didn’t work out, that is the idea there, but the programming almost worked on a MKR1000 board, (without headers) and as it happens that was what I used. Thank you by the way for helping me out here by adding fuel to the idea and as to how to help our friend further.

The intention is that the file would be in the sketch folder. Additional files are shown as tabs in the Arduino IDE:

Click the downwards pointing triangle button near the top right of the Arduino IDE window.
Click "New Tab".
Give the new file the name arduino_secrets.h
Click "OK".
Add your code to the arduino_secrets.h tab.

That worked, thanks Pert!

1 Like

You're welcome. I'm glad if I was able to be of assistance. Enjoy!
Per

In the web editor if you use the keyword then the tab is generated for you…

I have one more question Pert. How do I fix an unqualified-id error? The compiler did not seem to understand what I had to say when it came to my arduino_secrets.h file.

Here are the sanitized contents:

#define SSID "NetworkName"
#define PASSWD "Password"

And the error:

In file included from /home/USERNAME/Arduino/useRTCviaWiFi/useRTCviaWiFi.ino:7:0:
/home/USERNAME/Arduino/useRTCviaWiFi/useRTCviaWiFi.ino: In function 'void printWiFiStatus()':
arduino_secrets.h:1:14: error: expected unqualified-id before string constant
 #define SSID "NetworkName"
              ^
/home/USERNAME/Arduino/useRTCviaWiFi/useRTCviaWiFi.ino:85:21: note: in expansion of macro 'SSID'
   Serial.print(WiFi.SSID());
                     ^
exit status 1
expected unqualified-id before string constant

The C++ preprocessor does a text replace of all macros. So after preprocessing, this code:

Serial.print(WiFi.SSID());

ends up looking like this:

Serial.print(WiFi."NetworkName"());

which is clearly not valid code. The solution is to use a different macro name, which doesn't conflict with the WiFi.SSID() function name.

My advice is to avoid using the preprocessor unless there is no other alternative. The preprocessor can cause bugs that are very difficult to debug. In this case, the error message actually ended up being pretty easy to decipher but that is not always so. This alternative works just as well (actually doesn't work in this case due to the name conflict):

const char SSID[]="NetworkName";

I think it's unfortunate that Arduino decided to force the use of macros with this strange implementation of the secret tab feature of the Arduino Web Editor. I think the concept is very good but the dialog form is too "hand hold-y". It's not as if Arduino users don't know how to write code (or if they don't, they're going to need to learn anyway).

I ended up changing the header value from #define SSID "literalValue" to #define netName "literalValue" and that seemed to do the job.

pert:
The C++ preprocessor does a text replace of all macros. So after preprocessing, this code:

Serial.print(WiFi.SSID());

ends up looking like this:

Serial.print(WiFi."NetworkName"());

which is clearly not valid code. The solution is to use a different macro name, which doesn't conflict with the WiFi.SSID() function name.

My advice is to avoid using the preprocessor unless there is no other alternative.

I'm not a programming expert but I'll try to parse out what you said. Are you saying that because I named the variable in the arduino_secrets.h file SSID the preprocessor replaced the WiFi.SSID() method with my literal value? Even though WiFi.SSID() method is from a completely different header file?

I'm hesitant to use the method you describe later in your post because I don't 100% understand how the internet works. My understanding is that the code I posted would send my networking name and password out onto the internet to talk to the RTC. When I first read this project I didn't know what the arduino_secrets.h file was and did a little research into it. It seems like it is a way to protect against sending sensitive information around on the internet, such as if I reposted the code to github or gave it to a friend. I like the idea of not hard coding my sensitive information in my sketches if it can be avoided.

Again thank you for your help Pert!

bornstellarmakeseternallastin:
Are you saying that because I named the variable in the arduino_secrets.h file SSID the preprocessor replaced the WiFi.SSID() method with my literal value? Even though WiFi.SSID() method is from a completely different header file?

No. I'm saying it replaced your call to WiFi.SSID() at line 7 of your sketch file useRTCviaWiFi.ino with the literal value. The reason this happened is because you have an #include directive for arduino_secrets.h in your sketch. The definition of WiFi.SSID() is in a separate translation unit and so it won't be affected by the SSID macro. If you did define the SSID macro in the translation unit where WiFi.SSID() was defined, it would indeed cause the problem you suspected.

bornstellarmakeseternallastin:
I'm hesitant to use the method you describe later in your post because I don't 100% understand how the internet works. My understanding is that the code I posted would send my networking name and password out onto the internet to talk to the RTC.

If your sketch makes your Arduino send private information out over the Internet (I doubt yours does), that information is just as vulnerable whether you use a secret tab or no, a macro or a variable. The secret tab is only intended to make it easy to avoid accidentally sharing private information when you share the sketch code itself. It has absolutely no impact on the security of the running application.

bornstellarmakeseternallastin:
When I first read this project I didn't know what the arduino_secrets.h file was and did a little research into it. It seems like it is a way to protect against sending sensitive information around on the internet, such as if I reposted the code to github or gave it to a friend. I like the idea of not hard coding my sensitive information in my sketches if it can be avoided.

That is correct. The basic idea behind the secret tab is that you put all your private information in that file and then you can easily share your sketch with others without exposing that information simply by not sharing the secret tab file. People have done things like this for years on their own but when the Arduino Web Editor was created they decided to add a feature that somewhat automates the system. This may have been considered especially necessary with the Arduino Web Editor so that people could still use the share URL for sketches with private information.