diff --git a/code/espurna/config/defaults.h b/code/espurna/config/defaults.h index 8e82543b..86e25993 100644 --- a/code/espurna/config/defaults.h +++ b/code/espurna/config/defaults.h @@ -399,6 +399,11 @@ // General // ----------------------------------------------------------------------------- +// Default hostname will be ESPURNA_XXXXXX, where XXXXXX is last 3 octets of chipID +#ifndef HOSTNAME +#define HOSTNAME "" +#endif + // Needed for ESP8285 boards under Windows using PlatformIO (?) #ifndef BUTTON_PUSHBUTTON #define BUTTON_PUSHBUTTON 0 diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index 8c23ad62..6f6c8435 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -50,7 +50,7 @@ void setup() { // Hostname & board name initialization if (getSetting("hostname").length() == 0) { - setSetting("hostname", getIdentifier()); + setDefaultHostname(); } setBoardName(); diff --git a/code/espurna/utils.ino b/code/espurna/utils.ino index 4c01cf12..7398b802 100644 --- a/code/espurna/utils.ino +++ b/code/espurna/utils.ino @@ -15,6 +15,14 @@ String getIdentifier() { return String(buffer); } +void setDefaultHostname() { + if (strlen(HOSTNAME) > 0) { + setSetting("hostname", HOSTNAME); + } else { + setSetting("hostname", getIdentifier()); + } +} + void setBoardName() { #ifndef ESPURNA_CORE setSetting("boardName", DEVICE_NAME);