Set the AP name with the short name plus the 4 first digits of the ESP mac (#1331)
so as to don't disclose the password used for WM. Also change the wm password from MAc to be the last 8 digits, as these will change more than the first 8 ones. Also make consistent the ifndef qnd the parsing between WM_PWD_FROM_MAC and USE_MAC_AS_GATEWAY_NAME
This commit is contained in:
1 parent
3e9fbb21ff
commit
c98511ba36
3 files changed
+18
-21
No files matched your search
+4
-6
@@ -50,7 +50,7 @@
|
|||||||
*/
|
*/
|
||||||
/*-------------DEFINE GATEWAY NAME BELOW IT CAN ALSO BE DEFINED IN platformio.ini----------------*/
|
/*-------------DEFINE GATEWAY NAME BELOW IT CAN ALSO BE DEFINED IN platformio.ini----------------*/
|
||||||
|
|
||||||
// Uncomment to use the MAC address in the format of 112233445566 as the gateway name
|
// Uncomment to use the MAC address first 4 digits in the format of 5566 as the gateway name
|
||||||
// Any definition of Gateway_Name will be ignored. The Gateway_Short_name _ MAC will be used as the access point name.
|
// Any definition of Gateway_Name will be ignored. The Gateway_Short_name _ MAC will be used as the access point name.
|
||||||
//#define USE_MAC_AS_GATEWAY_NAME
|
//#define USE_MAC_AS_GATEWAY_NAME
|
||||||
#ifndef Gateway_Name
|
#ifndef Gateway_Name
|
||||||
@@ -114,11 +114,9 @@ const byte mac[] = {0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95}; //W5100 ethernet shield
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#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
|
//#define WM_PWD_FROM_MAC true // 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
|
||||||
# ifndef WifiManager_password
|
# define WifiManager_password "your_password" //this is going to be the WPA2-PSK password for the initial setup access point
|
||||||
# define WifiManager_password "your_password" //this is going to be the WPA2-PSK password for the initial setup access point
|
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
#ifndef WifiManager_ssid
|
#ifndef WifiManager_ssid
|
||||||
# define WifiManager_ssid Gateway_Name //this is the network name of the initial setup access point
|
# define WifiManager_ssid Gateway_Name //this is the network name of the initial setup access point
|
||||||
|
|||||||
+13
-14
@@ -182,6 +182,10 @@ char gateway_name[parameters_size + 1] = Gateway_Name;
|
|||||||
char WifiManager_ssid[MAC_NAME_MAX_LEN];
|
char WifiManager_ssid[MAC_NAME_MAX_LEN];
|
||||||
char ota_hostname[MAC_NAME_MAX_LEN];
|
char ota_hostname[MAC_NAME_MAX_LEN];
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef WM_PWD_FROM_MAC
|
||||||
|
# undef WifiManager_password;
|
||||||
|
char WifiManager_password[9];
|
||||||
|
#endif
|
||||||
bool connectedOnce = false; //indicate if we have been connected once to MQTT
|
bool connectedOnce = false; //indicate if we have been connected once to MQTT
|
||||||
bool connected = false; //indicate whether we are currently connected. Used to detected re-connection
|
bool connected = false; //indicate whether we are currently connected. Used to detected re-connection
|
||||||
int failure_number_ntwk = 0; // number of failure connecting to network
|
int failure_number_ntwk = 0; // number of failure connecting to network
|
||||||
@@ -658,14 +662,18 @@ void setup() {
|
|||||||
Log.notice(F("OpenMQTTGateway Version: " OMG_VERSION CR));
|
Log.notice(F("OpenMQTTGateway Version: " OMG_VERSION CR));
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# ifdef USE_MAC_AS_GATEWAY_NAME
|
|
||||||
String s = WiFi.macAddress();
|
String s = WiFi.macAddress();
|
||||||
|
# ifdef USE_MAC_AS_GATEWAY_NAME
|
||||||
sprintf(gateway_name, "%.2s%.2s%.2s%.2s%.2s%.2s",
|
sprintf(gateway_name, "%.2s%.2s%.2s%.2s%.2s%.2s",
|
||||||
s.c_str(), s.c_str() + 3, s.c_str() + 6, s.c_str() + 9, s.c_str() + 12, s.c_str() + 15);
|
s.c_str(), s.c_str() + 3, s.c_str() + 6, s.c_str() + 9, s.c_str() + 12, s.c_str() + 15);
|
||||||
snprintf(WifiManager_ssid, MAC_NAME_MAX_LEN, "%s_%s", Gateway_Short_Name, gateway_name);
|
snprintf(WifiManager_ssid, MAC_NAME_MAX_LEN, "%s_%.2s%.2s", Gateway_Short_Name, s.c_str(), s.c_str() + 3);
|
||||||
strcpy(ota_hostname, WifiManager_ssid);
|
strcpy(ota_hostname, WifiManager_ssid);
|
||||||
Log.notice(F("OTA Hostname: %s.local" CR), ota_hostname);
|
Log.notice(F("OTA Hostname: %s.local" CR), ota_hostname);
|
||||||
# endif
|
# endif
|
||||||
|
# ifdef WM_PWD_FROM_MAC // From ESP Mac Address, last 8 digits as the password
|
||||||
|
sprintf(WifiManager_password, "%.2s%.2s%.2s%.2s",
|
||||||
|
s.c_str() + 6, s.c_str() + 9, s.c_str() + 12, s.c_str() + 15);
|
||||||
|
# endif
|
||||||
|
|
||||||
# ifdef ESP32_ETHERNET
|
# ifdef ESP32_ETHERNET
|
||||||
setup_ethernet_esp32();
|
setup_ethernet_esp32();
|
||||||
@@ -1232,18 +1240,9 @@ void setup_wifimanager(bool reset_settings) {
|
|||||||
|
|
||||||
if (!wifi_reconnect_bypass()) // if we didn't connect with saved credential we start Wifimanager web portal
|
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
|
# ifdef ESP32
|
||||||
if (lowpowermode < 2) {
|
if (lowpowermode < 2) {
|
||||||
displayPrint("Connect your phone to WIFI AP:", WifiManager_ssid, const_cast<char*>(wm_password.c_str()));
|
displayPrint("Connect your phone to WIFI AP:", WifiManager_ssid, WifiManager_password);
|
||||||
} 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)
|
} 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
|
# ifdef ZgatewayBT
|
||||||
lowPowerESP32();
|
lowPowerESP32();
|
||||||
@@ -1253,11 +1252,11 @@ void setup_wifimanager(bool reset_settings) {
|
|||||||
|
|
||||||
ErrorIndicatorON();
|
ErrorIndicatorON();
|
||||||
InfoIndicatorON();
|
InfoIndicatorON();
|
||||||
Log.notice(F("Connect your phone to WIFI AP: %s with PWD: %s" CR), WifiManager_ssid, wm_password.c_str());
|
Log.notice(F("Connect your phone to WIFI AP: %s with PWD: %s" CR), WifiManager_ssid, WifiManager_password);
|
||||||
//fetches ssid and pass and tries to connect
|
//fetches ssid and pass and tries to connect
|
||||||
//if it does not connect it starts an access point with the specified name
|
//if it does not connect it starts an access point with the specified name
|
||||||
//and goes into a blocking loop awaiting configuration
|
//and goes into a blocking loop awaiting configuration
|
||||||
if (!wifiManager.autoConnect(WifiManager_ssid, wm_password.c_str())) {
|
if (!wifiManager.autoConnect(WifiManager_ssid, WifiManager_password)) {
|
||||||
Log.warning(F("failed to connect and hit timeout" CR));
|
Log.warning(F("failed to connect and hit timeout" CR));
|
||||||
delay(3000);
|
delay(3000);
|
||||||
//reset and try again
|
//reset and try again
|
||||||
|
|||||||
+1
-1
@@ -292,7 +292,7 @@ build_flags =
|
|||||||
'-DZgatewayWeatherStation="WeatherStation"'
|
'-DZgatewayWeatherStation="WeatherStation"'
|
||||||
'-DsimplePublishing=true'
|
'-DsimplePublishing=true'
|
||||||
'-DWM_PWD_FROM_MAC=true'
|
'-DWM_PWD_FROM_MAC=true'
|
||||||
'-DGateway_Name="OpenMQTTGateway_ESP32_ALL"'
|
'-DUSE_MAC_AS_GATEWAY_NAME=true'
|
||||||
|
|
||||||
[env:esp32dev-rf]
|
[env:esp32dev-rf]
|
||||||
platform = ${com.esp32_platform}
|
platform = ${com.esp32_platform}
|
||||||
|
|||||||
Reference in new issue
Block a user