Skip to content

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
wants to merge 11 commits into from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ _build/
debug.cfg
debug.svd
debug_custom.json

# Ignore changes in secrets.h
cores/esp32/secrets.h
9 changes: 9 additions & 0 deletions cores/esp32/secrets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#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"

// TODO array
18 changes: 18 additions & 0 deletions docs/source/guides/secrets.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#######
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. This header file can be included in any sketch and the passwords used in there hidden with the constant name.

Setup:
------
1. Locate your installation folder and go to the file cores/esp32/secrets.h
2. Edit the secres.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. TODO array

8 changes: 6 additions & 2 deletions libraries/WiFi/examples/WiFiClient/WiFiClient.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
*/

#include <WiFi.h>
#include "secrets.h"

const char* ssid = "your-ssid"; // Change this to your WiFi SSID
const char* password = "your-password"; // Change this to your WiFi password
const char* ssid = SECRETS_WIFI_SSID_1;
const char* password = SECRETS_WIFI_PASSWORD_1;

//const char* ssid = "your-ssid"; // Change this to your WiFi SSID
//const char* password = "your-password"; // Change this to your WiFi password

const char* host = "api.thingspeak.com"; // This should not be changed
const int httpPort = 80; // This should not be changed
Expand Down