From f02bb3172fb9911daaa9228d82d985381eff3536 Mon Sep 17 00:00:00 2001 From: No-Signal Date: Sun, 8 Dec 2024 11:30:10 +0000 Subject: [PATCH] Moving secrets from USER_SETTINGS to USER_SECRETS.ini --- .gitignore | 3 +++ Software/USER_SETTINGS.cpp | 20 ++++++++++---------- Software/USER_SETTINGS.h | 1 - USER_SECRETS_TEMPLATE.ini | 9 +++++++++ platformio.ini | 15 ++++++++++++++- user_secrets_copy.py | 5 +++++ 6 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 USER_SECRETS_TEMPLATE.ini create mode 100644 user_secrets_copy.py diff --git a/.gitignore b/.gitignore index f4dd4582..6eef5407 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ compile.bat # Ignore binary files *.bin + +# Ignore secret file +USER_SECRETS.ini \ No newline at end of file diff --git a/Software/USER_SETTINGS.cpp b/Software/USER_SETTINGS.cpp index 7e916e68..b0030cd9 100644 --- a/Software/USER_SETTINGS.cpp +++ b/Software/USER_SETTINGS.cpp @@ -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 @@ -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" diff --git a/Software/USER_SETTINGS.h b/Software/USER_SETTINGS.h index c846aa09..698b0ffe 100644 --- a/Software/USER_SETTINGS.h +++ b/Software/USER_SETTINGS.h @@ -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 \ diff --git a/USER_SECRETS_TEMPLATE.ini b/USER_SECRETS_TEMPLATE.ini new file mode 100644 index 00000000..7e11655b --- /dev/null +++ b/USER_SECRETS_TEMPLATE.ini @@ -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 \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index f7cca324..08bec11c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,6 +10,9 @@ [platformio] src_dir = ./Software +extra_configs = + USER_SECRETS_TEMPLATE.ini + USER_SECRETS.ini [env:esp32dev] platform = espressif32 @@ -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 = diff --git a/user_secrets_copy.py b/user_secrets_copy.py new file mode 100644 index 00000000..6c689237 --- /dev/null +++ b/user_secrets_copy.py @@ -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') \ No newline at end of file