Add a macro to use the MAC address as the gateway name. (#1013)
Adds the macro USE_MAC_AS_GATEWAY_NAME, when defined the gateway name will default to OMG_XXXXXXXXXXXX, where the X's are the mac address characters. This can still be changed in WiFiManager.
This commit is contained in:
1 parent
83b8d88c0f
commit
e92e468ca6
2 files changed
+15
-1
No files matched your search
@@ -49,6 +49,10 @@
|
|||||||
* to the access point with your password (SSID: WifiManager_ssid, password: WifiManager_password)
|
* to the access point with your password (SSID: WifiManager_ssid, password: WifiManager_password)
|
||||||
*/
|
*/
|
||||||
/*-------------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
|
||||||
|
// 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
|
||||||
#ifndef Gateway_Name
|
#ifndef Gateway_Name
|
||||||
# define Gateway_Name "OpenMQTTGateway"
|
# define Gateway_Name "OpenMQTTGateway"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+11
-1
@@ -166,7 +166,10 @@ char mqtt_server[parameters_size] = MQTT_SERVER;
|
|||||||
char mqtt_port[6] = MQTT_PORT;
|
char mqtt_port[6] = MQTT_PORT;
|
||||||
char mqtt_topic[mqtt_topic_max_size] = Base_Topic;
|
char mqtt_topic[mqtt_topic_max_size] = Base_Topic;
|
||||||
char gateway_name[parameters_size * 2] = Gateway_Name;
|
char gateway_name[parameters_size * 2] = Gateway_Name;
|
||||||
|
#ifdef USE_MAC_AS_GATEWAY_NAME
|
||||||
|
# undef WifiManager_ssid
|
||||||
|
char WifiManager_ssid[20];
|
||||||
|
#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
|
||||||
int failure_number_ntwk = 0; // number of failure connecting to network
|
int failure_number_ntwk = 0; // number of failure connecting to network
|
||||||
int failure_number_mqtt = 0; // number of failure connecting to MQTT
|
int failure_number_mqtt = 0; // number of failure connecting to MQTT
|
||||||
@@ -588,6 +591,13 @@ 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();
|
||||||
|
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);
|
||||||
|
sprintf(WifiManager_ssid, "%s_%s", Gateway_Short_Name, gateway_name);
|
||||||
|
# endif
|
||||||
|
|
||||||
# ifdef ESP32_ETHERNET
|
# ifdef ESP32_ETHERNET
|
||||||
setup_ethernet_esp32();
|
setup_ethernet_esp32();
|
||||||
# else // WIFI ESP
|
# else // WIFI ESP
|
||||||
|
|||||||
Reference in new issue
Block a user