Skip to content

Commit

Permalink
Moving secrets from USER_SETTINGS to USER_SECRETS.ini
Browse files Browse the repository at this point in the history
  • Loading branch information
No-Signal committed Dec 8, 2024
1 parent 30507e7 commit f02bb31
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ compile.bat

# Ignore binary files
*.bin

# Ignore secret file
USER_SECRETS.ini
20 changes: 10 additions & 10 deletions Software/USER_SETTINGS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ volatile CAN_Configuration can_config = {

#ifdef WIFI

volatile uint8_t AccessPointEnabled = true; //Set to either true/false to enable direct wifi access point
std::string ssid = "REPLACE_WITH_YOUR_SSID"; // Maximum of 63 characters
std::string password = "REPLACE_WITH_YOUR_PASSWORD"; // Minimum of 8 characters
const char* ssidAP = "Battery Emulator"; // Maximum of 63 characters, also used for device name on web interface
const char* passwordAP = "123456789"; // Minimum of 8 characters; set to NULL if you want the access point to be open
const uint8_t wifi_channel = 0; // Set to 0 for automatic channel selection
volatile uint8_t AccessPointEnabled = true; //Set to either true/false to enable direct wifi access point
std::string ssid = WIFI_SSID; // Set in USER_SECRETS.ini
std::string password = WIFI_PASSWORD; // Set in USER_SECRETS.ini
const char* ssidAP = "Battery Emulator"; // Maximum of 63 characters, also used for device name on web interface
const char* passwordAP = AP_PASSWORD; // Set in USER_SECRETS.ini
const uint8_t wifi_channel = 0; // Set to 0 for automatic channel selection

#ifdef WIFICONFIG
// Set your Static IP address
Expand All @@ -37,14 +37,14 @@ IPAddress gateway(192, 168, 10, 1);
IPAddress subnet(255, 255, 255, 0);
#endif
#ifdef WEBSERVER
const char* http_username = "admin"; // username to webserver authentication;
const char* http_password = "admin"; // password to webserver authentication;
const char* http_username = HTTP_USERNAME; // Set in USER_SECRETS.ini
const char* http_password = HTTP_PASSWORD; // Set in USER_SECRETS.ini

#endif // WEBSERVER
// MQTT
#ifdef MQTT
const char* mqtt_user = "REDACTED"; // Set NULL for no username
const char* mqtt_password = "REDACTED"; // Set NULL for no password
const char* mqtt_user = MQTT_USER; // Set in USER_SECRETS.ini
const char* mqtt_password = MQTT_PASSWORD; // Set in USER_SECRETS.ini
#ifdef MQTT_MANUAL_TOPIC_OBJECT_NAME
const char* mqtt_topic_name =
"BE"; // Custom MQTT topic name. Previously, the name was automatically set to "battery-emulator_esp32-XXXXXX"
Expand Down
1 change: 0 additions & 1 deletion Software/USER_SETTINGS.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@

/* MQTT options */
// #define MQTT // Enable this line to enable MQTT
#define MQTT_SERVER "192.168.xxx.yyy"
#define MQTT_PORT 1883
#define MQTT_MANUAL_TOPIC_OBJECT_NAME // Enable this to use custom MQTT topic, object ID prefix, and device name. \
// WARNING: If this is not defined, the previous default naming format \
Expand Down
9 changes: 9 additions & 0 deletions USER_SECRETS_TEMPLATE.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[secret]
WIFI_SSID=REPLACE_WITH_YOUR_SSID ; Maximum of 63 characters
WIFI_PASSWORD=REPLACE_WITH_YOUR_PASSWORD ; Minimum of 8 characters
AP_PASSWORD=123456789 ; Minimum of 8 characters; set to blank if you want the access point to be open
HTTP_USERNAME=admin ; username to webserver authentication;
HTTP_PASSWORD=admin ; password to webserver authentication;
MQTT_SERVER=192.168.xxx.yyy ; mqtt server address
MQTT_USER= ; mqtt username, leave blank for no authentication
MQTT_PASSWORD= ; mqtt password, leave blank for no authentication
15 changes: 14 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

[platformio]
src_dir = ./Software
extra_configs =
USER_SECRETS_TEMPLATE.ini
USER_SECRETS.ini

[env:esp32dev]
platform = espressif32
Expand All @@ -20,5 +23,15 @@ board = esp32dev
monitor_speed = 115200
monitor_filters = default, time, log2file
framework = arduino
build_flags = -I include
extra_scripts = user_secrets_copy.py
build_flags =
-I include
'-D WIFI_SSID="${secret.WIFI_SSID}"'
'-D WIFI_PASSWORD="${secret.WIFI_PASSWORD}"'
'-D AP_PASSWORD="${secret.AP_PASSWORD}"'
'-D HTTP_USERNAME="${secret.HTTP_USERNAME}"'
'-D HTTP_PASSWORD="${secret.HTTP_PASSWORD}"'
'-D MQTT_SERVER="${secret.MQTT_SERVER}"'
'-D MQTT_USER="${secret.MQTT_USER}"'
'-D MQTT_PASSWORD="${secret.MQTT_PASSWORD}"'
lib_deps =
5 changes: 5 additions & 0 deletions user_secrets_copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import os
from shutil import copyfile

if not os.path.exists('USER_SECRETS.ini'):
copyfile('USER_SECRETS_TEMPLATE.ini', 'USER_SECRETS.ini')

0 comments on commit f02bb31

Please sign in to comment.