diff --git a/main/User_config.h b/main/User_config.h index 2c16e38257..711b318f4b 100644 --- a/main/User_config.h +++ b/main/User_config.h @@ -114,8 +114,11 @@ const byte mac[] = {0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95}; //W5100 ethernet shield # endif #endif -#ifndef WifiManager_password -# define WifiManager_password "your_password" //this is going to be the WPA2-PSK password for the initial setup access point +#define WM_PWD_FROM_MAC false // enable to set the password from the 8 first digit of the ESP mac address for enhanced security, enabling this option requires to have access to the MAC address, either through a sticker or with serial monitoring +#if !WM_PWD_FROM_MAC +# ifndef WifiManager_password +# define WifiManager_password "your_password" //this is going to be the WPA2-PSK password for the initial setup access point +# endif #endif #ifndef WifiManager_ssid # define WifiManager_ssid Gateway_Name //this is the network name of the initial setup access point diff --git a/main/main.ino b/main/main.ino index a45e54ded2..4d561f9a95 100644 --- a/main/main.ino +++ b/main/main.ino @@ -1233,9 +1233,18 @@ void setup_wifimanager(bool reset_settings) { if (!wifi_reconnect_bypass()) // if we didn't connect with saved credential we start Wifimanager web portal { + // Wifi Manager password + String wm_password; +# if WM_PWD_FROM_MAC // From ESP Mac Address + wm_password = WiFi.macAddress(); + wm_password.replace(":", ""); + wm_password.substring(0, 8); +# else + wm_password = WifiManager_password; // From macro definition +# endif # ifdef ESP32 if (lowpowermode < 2) { - displayPrint("Connect your phone to WIFI AP:", WifiManager_ssid, WifiManager_password); + displayPrint("Connect your phone to WIFI AP:", WifiManager_ssid, const_cast(wm_password.c_str())); } else { // in case of low power mode we put the ESP to sleep again if we didn't get connected (typical in case the wifi is down) # ifdef ZgatewayBT lowPowerESP32(); @@ -1245,11 +1254,11 @@ void setup_wifimanager(bool reset_settings) { ErrorIndicatorON(); InfoIndicatorON(); - Log.notice(F("Connect your phone to WIFI AP: %s with PWD: %s" CR), WifiManager_ssid, WifiManager_password); + Log.notice(F("Connect your phone to WIFI AP: %s with PWD: %s" CR), WifiManager_ssid, wm_password.c_str()); //fetches ssid and pass and tries to connect //if it does not connect it starts an access point with the specified name //and goes into a blocking loop awaiting configuration - if (!wifiManager.autoConnect(WifiManager_ssid, WifiManager_password)) { + if (!wifiManager.autoConnect(WifiManager_ssid, wm_password.c_str())) { Log.warning(F("failed to connect and hit timeout" CR)); delay(3000); //reset and try again diff --git a/platformio.ini b/platformio.ini index 1aea2e44b5..47f56cd541 100644 --- a/platformio.ini +++ b/platformio.ini @@ -291,6 +291,7 @@ build_flags = '-DZsensorGPIOKeyCode="GPIOKeyCode"' '-DZgatewayWeatherStation="WeatherStation"' '-DsimplePublishing=true' + '-DWM_PWD_FROM_MAC=true' '-DGateway_Name="OpenMQTTGateway_ESP32_ALL"' [env:esp32dev-rf]