I need to store various secrets (same for all my sketches), and having to build a secrets file for each sketch is fairly inconvenient (let alone reliable).
Is there a way I can have a "shared secrets" file, that I can reuse for all my various sketches?
e.g. info I'd want to store:
WIFI credentials
Home assistant IP
MQTT credentials
Hi @noegros. You can create a custom library to share this data between your sketches.
Since many libraries are very complex, this might sound like a daunting task, but it is actually possible to make libraries that are as minimal as a single header file. I'll provide instructions:
Select File > Preferences from the Arduino IDE menus.
The "Preferences" dialog will open.
Take note of the path shown in the "Sketchbook location" field of the "Preferences" dialog.
Click the "CANCEL" button.
Create a new folder under the libraries subfolder of the path from the "Sketchbook location" preference. The folder name should not contain any spaces or other special characters.
Create a file with the .h file extension under the new folder you created. The filename should not contain any spaces or other special characters.
Open the .h file you created in any text editor.
Add the code to define the shared secret values, just as you would do with a secrets file in a sketch.
Save the file.
Add #include directives for the .h file you created to the sketches that need access to the shared secret values.
Here is an example of how the library installation structure might look: