Skip to content

Commit

Permalink
Add a macro to use the MAC address as the gateway name.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
h2zero committed Jul 10, 2021
1 parent 2ae8f0c commit 8e26c82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions main/User_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
* 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----------------*/

// 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
# define Gateway_Name "OpenMQTTGateway"
#endif
Expand Down
12 changes: 11 additions & 1 deletion main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ char mqtt_server[parameters_size] = MQTT_SERVER;
char mqtt_port[6] = MQTT_PORT;
char mqtt_topic[mqtt_topic_max_size] = Base_Topic;
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
int failure_number_ntwk = 0; // number of failure connecting to network
int failure_number_mqtt = 0; // number of failure connecting to MQTT
Expand Down Expand Up @@ -588,6 +591,13 @@ void setup() {
Log.notice(F("OpenMQTTGateway Version: " OMG_VERSION CR));
# 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
setup_ethernet_esp32();
# else // WIFI ESP
Expand Down

0 comments on commit 8e26c82

Please sign in to comment.