From 922096e9daec0a2fdf77a917299cecaa94a107ed Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Thu, 29 Mar 2018 00:31:27 +0300 Subject: [PATCH] Build-time default value for hostname --- code/espurna/config/defaults.h | 5 +++++ code/espurna/espurna.ino | 2 +- code/espurna/utils.ino | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) 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);