-
Notifications
You must be signed in to change notification settings - Fork 7.6k
secrets #8310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
secrets #8310
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fe2eef6
Basic draft for secrets
PilnyTomas 028d8c0
Added doc page
PilnyTomas fa61b22
Added header into secrets.rst
PilnyTomas 42089ec
Added constants to all examples; added array
PilnyTomas cb8d5ce
Extended doc
PilnyTomas 7cc9d21
Added line referencing to the documentation on web site once it gets …
PilnyTomas 5e47cd8
File secrets.h is now expected in sketch book and supported by platfo…
PilnyTomas bf9559a
Removed the secrets.h from .gitignore
PilnyTomas 805a038
Updated examples
PilnyTomas c12d191
Modified all remaining examples using WiFi (except eduroam)
PilnyTomas b3e4964
Merge branch 'esp-idf-v5.1-libs' into wifi_secrets
PilnyTomas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,6 @@ _build/ | |
debug.cfg | ||
debug.svd | ||
debug_custom.json | ||
|
||
# Ignore changes in secrets.h | ||
cores/esp32/secrets.h |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#define SECRETS_WIFI_SSID_1 "example-SSID1" | ||
#define SECRETS_WIFI_PASSWORD_1 "example-password-1" | ||
|
||
#define SECRETS_WIFI_SSID_2 "example-SSID2" | ||
#define SECRETS_WIFI_PASSWORD_2 "example-password-2" | ||
|
||
#define SECRETS_WIFI_ARRAY_MAX 3 // Number of entries in the array | ||
|
||
char SECRET_WIFI_SSID_ARRAY[SECRETS_WIFI_ARRAY_MAX][32] = { | ||
SECRETS_WIFI_SSID_1, | ||
SECRETS_WIFI_SSID_2, | ||
"example-SSID3" | ||
}; | ||
|
||
char SECRET_WIFI_PASSWORD_ARRAY[SECRETS_WIFI_ARRAY_MAX][32] = { | ||
SECRETS_WIFI_PASSWORD_1, | ||
SECRETS_WIFI_PASSWORD_2, | ||
"example-password-3" | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
####### | ||
Secrets | ||
####### | ||
|
||
Why? | ||
---- | ||
DRY (Don't Repeat Yourself) - having your passwords in one place is more manageable than changing them manually in each example, or new sketch. | ||
Secure - safely share the code without worrying about accidentally leaving WiFi credentials. | ||
|
||
How it works - your SSIDs and passwords are #defined as a plain text constants in a header file located in sketch folder (after you manually create it). This header file can be included in any sketch and the passwords used in there hidden with the constant name. | ||
|
||
|
||
Setup: | ||
------ | ||
1. Locate your sketch folder and create file secrets.h if it does not exist yet. | ||
2. Edit the secrets.h file and input the WiFi credential you are often using. | ||
3. For examples we are using constants `SECRETS_WIFI_SSID_1` and `SECRETS_WIFI_PASSWORD_1`. You can follow the numbering or create your own constant names, for example `WIFI_SSID_HOME` + `WIFI_PWD_HOME`. | ||
4. For multi Access Point usage you can use an array of credential you can expand - either add existing constants, or create a plain text. | ||
|
||
|
||
Example contents: | ||
----------------- | ||
|
||
.. code-block:: c++ | ||
|
||
#pragma once | ||
|
||
#define SECRETS_WIFI_SSID_1 "example-SSID1" | ||
#define SECRETS_WIFI_PASSWORD_1 "example-password-1" | ||
|
||
#define SECRETS_WIFI_SSID_2 "example-SSID2" | ||
#define SECRETS_WIFI_PASSWORD_2 "example-password-2" | ||
|
||
#define SECRETS_WIFI_ARRAY_MAX 3 // Number of entries in the array | ||
|
||
const char SECRET_WIFI_SSID_ARRAY[SECRETS_WIFI_ARRAY_MAX][32] = { | ||
SECRETS_WIFI_SSID_1, | ||
SECRETS_WIFI_SSID_2, | ||
"example-SSID3" | ||
}; | ||
|
||
const char SECRET_WIFI_PASSWORD_ARRAY[SECRETS_WIFI_ARRAY_MAX][32] = { | ||
SECRETS_WIFI_PASSWORD_1, | ||
SECRETS_WIFI_PASSWORD_2, | ||
"example-password-3" | ||
}; | ||
|
||
|
||
Example usage: | ||
-------------- | ||
|
||
.. code-block:: c++ | ||
|
||
#include <WiFi.h> | ||
#include "secrets.h" | ||
const char* ssid = SECRETS_WIFI_SSID_1; | ||
const char* password = SECRETS_WIFI_PASSWORD_1; | ||
WiFi.begin(ssid, password); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.