feat(wifi): add compile time configurtation (#2889)

* feat(wifi): add compile time configurtation

Add `WLED_AP_SSID` and `WLED_AP_PASS` defines to allow configuring the
SoftAP SSID and Password at compile time. Default to existing values.

Add `WLED_AP_SSID_UNIQUE` flag to append the device portion of the mac
address to `WLED_AP_SSID`.

Exampleof all flags (note the quoting to preserve
"stringification"):

```
build_flags =
    -D WLED_AP_SSID='"MyAP"'
    -D WLED_AP_PASS='"MyPassword"'
    -D WLED_AP_SSID_UNIQUE
```

* Removed two error defines

Co-authored-by: Christian Schwinne <cschwinne@gmail.com>
This commit is contained in:
Jason Kölker 2022-11-20 08:55:38 -06:00 committed by GitHub
parent caef289b9b
commit e409bd298a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 8 deletions

View File

@ -9,6 +9,7 @@
//Defaults //Defaults
#define DEFAULT_CLIENT_SSID "Your_Network" #define DEFAULT_CLIENT_SSID "Your_Network"
#define DEFAULT_AP_SSID "WLED-AP"
#define DEFAULT_AP_PASS "wled1234" #define DEFAULT_AP_PASS "wled1234"
#define DEFAULT_OTA_PASS "wledota" #define DEFAULT_OTA_PASS "wledota"

View File

@ -366,7 +366,13 @@ void WLED::setup()
#endif #endif
updateFSInfo(); updateFSInfo();
strcpy_P(apSSID, PSTR("WLED-AP")); // otherwise it is empty on first boot until config is saved // generate module IDs must be done before AP setup
escapedMac = WiFi.macAddress();
escapedMac.replace(":", "");
escapedMac.toLowerCase();
WLED_SET_AP_SSID(); // otherwise it is empty on first boot until config is saved
DEBUG_PRINTLN(F("Reading config")); DEBUG_PRINTLN(F("Reading config"));
deserializeConfigFromFS(); deserializeConfigFromFS();
@ -400,10 +406,6 @@ void WLED::setup()
} }
#endif #endif
// generate module IDs
escapedMac = WiFi.macAddress();
escapedMac.replace(":", "");
escapedMac.toLowerCase();
// fill in unique mdns default // fill in unique mdns default
if (strcmp(cmDNS, "x") == 0) sprintf_P(cmDNS, PSTR("wled-%*s"), 6, escapedMac.c_str() + 6); if (strcmp(cmDNS, "x") == 0) sprintf_P(cmDNS, PSTR("wled-%*s"), 6, escapedMac.c_str() + 6);
if (mqttDeviceTopic[0] == 0) sprintf_P(mqttDeviceTopic, PSTR("wled/%*s"), 6, escapedMac.c_str() + 6); if (mqttDeviceTopic[0] == 0) sprintf_P(mqttDeviceTopic, PSTR("wled/%*s"), 6, escapedMac.c_str() + 6);
@ -480,8 +482,8 @@ void WLED::initAP(bool resetAP)
return; return;
if (resetAP) { if (resetAP) {
strcpy_P(apSSID, PSTR("WLED-AP")); WLED_SET_AP_SSID();
strcpy_P(apPass, PSTR(DEFAULT_AP_PASS)); strcpy_P(apPass, PSTR(WLED_AP_PASS));
} }
DEBUG_PRINT(F("Opening access point ")); DEBUG_PRINT(F("Opening access point "));
DEBUG_PRINTLN(apSSID); DEBUG_PRINTLN(apSSID);

View File

@ -175,6 +175,19 @@ using PSRAMDynamicJsonDocument = BasicJsonDocument<PSRAM_Allocator>;
#define CLIENT_PASS "" #define CLIENT_PASS ""
#endif #endif
#if defined(WLED_AP_PASS) && !defined(WLED_AP_SSID)
#error WLED_AP_PASS is defined but WLED_AP_SSID is still the default. \
Please change WLED_AP_SSID to something unique.
#endif
#ifndef WLED_AP_SSID
#define WLED_AP_SSID DEFAULT_AP_SSID
#endif
#ifndef WLED_AP_PASS
#define WLED_AP_PASS DEFAULT_AP_PASS
#endif
#ifndef SPIFFS_EDITOR_AIRCOOOKIE #ifndef SPIFFS_EDITOR_AIRCOOOKIE
#error You are not using the Aircoookie fork of the ESPAsyncWebserver library.\ #error You are not using the Aircoookie fork of the ESPAsyncWebserver library.\
Using upstream puts your WiFi password at risk of being served by the filesystem.\ Using upstream puts your WiFi password at risk of being served by the filesystem.\
@ -229,7 +242,7 @@ WLED_GLOBAL char versionString[] _INIT(TOSTRING(WLED_VERSION));
#define WLED_CODENAME "Hoshi" #define WLED_CODENAME "Hoshi"
// AP and OTA default passwords (for maximum security change them!) // AP and OTA default passwords (for maximum security change them!)
WLED_GLOBAL char apPass[65] _INIT(DEFAULT_AP_PASS); WLED_GLOBAL char apPass[65] _INIT(WLED_AP_PASS);
WLED_GLOBAL char otaPass[33] _INIT(DEFAULT_OTA_PASS); WLED_GLOBAL char otaPass[33] _INIT(DEFAULT_OTA_PASS);
// Hardware and pin config // Hardware and pin config
@ -727,6 +740,23 @@ WLED_GLOBAL volatile uint8_t jsonBufferLock _INIT(0);
#define WLED_WIFI_CONFIGURED (strlen(clientSSID) >= 1 && strcmp(clientSSID, DEFAULT_CLIENT_SSID) != 0) #define WLED_WIFI_CONFIGURED (strlen(clientSSID) >= 1 && strcmp(clientSSID, DEFAULT_CLIENT_SSID) != 0)
#define WLED_MQTT_CONNECTED (mqtt != nullptr && mqtt->connected()) #define WLED_MQTT_CONNECTED (mqtt != nullptr && mqtt->connected())
#ifndef WLED_AP_SSID_UNIQUE
#define WLED_SET_AP_SSID() do { \
strcpy_P(apSSID, PSTR(WLED_AP_SSID)); \
} while(0)
#else
#define WLED_SET_AP_SSID() do { \
strcpy_P(apSSID, PSTR(WLED_AP_SSID)); \
snprintf_P(\
apSSID+strlen(WLED_AP_SSID), \
sizeof(apSSID)-strlen(WLED_AP_SSID), \
PSTR("-%*s"), \
6, \
escapedMac.c_str() + 6\
); \
} while(0)
#endif
//macro to convert F to const //macro to convert F to const
#define SET_F(x) (const char*)F(x) #define SET_F(x) (const char*)F(x)