Skip to content

Commit e92e468

Browse files
authored
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.
1 parent 83b8d88 commit e92e468

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

main/User_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
* to the access point with your password (SSID: WifiManager_ssid, password: WifiManager_password)
5050
*/
5151
/*-------------DEFINE GATEWAY NAME BELOW IT CAN ALSO BE DEFINED IN platformio.ini----------------*/
52+
53+
// Uncomment to use the mac address in the format of 112233445566 as the gateway name
54+
// Any definition of Gateway_Name will be ignored. The Gateway_Short_name _ MAC will be used as the access point name.
55+
//#define USE_MAC_AS_GATEWAY_NAME
5256
#ifndef Gateway_Name
5357
# define Gateway_Name "OpenMQTTGateway"
5458
#endif

main/main.ino

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ char mqtt_server[parameters_size] = MQTT_SERVER;
166166
char mqtt_port[6] = MQTT_PORT;
167167
char mqtt_topic[mqtt_topic_max_size] = Base_Topic;
168168
char gateway_name[parameters_size * 2] = Gateway_Name;
169-
169+
#ifdef USE_MAC_AS_GATEWAY_NAME
170+
# undef WifiManager_ssid
171+
char WifiManager_ssid[20];
172+
#endif
170173
bool connectedOnce = false; //indicate if we have been connected once to MQTT
171174
int failure_number_ntwk = 0; // number of failure connecting to network
172175
int failure_number_mqtt = 0; // number of failure connecting to MQTT
@@ -588,6 +591,13 @@ void setup() {
588591
Log.notice(F("OpenMQTTGateway Version: " OMG_VERSION CR));
589592
# endif
590593

594+
# ifdef USE_MAC_AS_GATEWAY_NAME
595+
String s = WiFi.macAddress();
596+
sprintf(gateway_name, "%.2s%.2s%.2s%.2s%.2s%.2s",
597+
s.c_str(), s.c_str() + 3, s.c_str() + 6, s.c_str() + 9, s.c_str() + 12, s.c_str() + 15);
598+
sprintf(WifiManager_ssid, "%s_%s", Gateway_Short_Name, gateway_name);
599+
# endif
600+
591601
# ifdef ESP32_ETHERNET
592602
setup_ethernet_esp32();
593603
# else // WIFI ESP

0 commit comments

Comments
 (0)