From 0c10ef4ba99ab104f980ff0999aec379b7318289 Mon Sep 17 00:00:00 2001 From: "hem@hdk" Date: Wed, 23 Sep 2020 13:10:11 +0200 Subject: [PATCH] Fix custom hostname (#2) - Changed HOSTNAME to constant macro definition so it is properly evaluated via #ifdef directive. - Increased max. hostname length to 24 characters. --- esp8266-geigercounter.ino | 6 +++--- settings.h.example | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/esp8266-geigercounter.ino b/esp8266-geigercounter.ino index aadc6f9..8d3aef5 100644 --- a/esp8266-geigercounter.ino +++ b/esp8266-geigercounter.ino @@ -30,7 +30,7 @@ char serialInputHelper[RECV_LINE_SIZE]; int lastCPM = 0, currentCPM = 0; float lastuSv = 0, currentuSv = 0; -char hostname[16]; +char hostname[24]; void setup() { delay(3000); @@ -55,9 +55,9 @@ void setup() { #ifdef HOSTNAME - hostname = HOSTNAME; + strncpy(hostname, HOSTNAME, sizeof(hostname)); #else - snprintf(hostname, 24, "GEIGERCTR-%X", chipid); + snprintf(hostname, sizeof(hostname), "GEIGERCTR-%X", chipid); #endif #ifdef USE_HA_AUTODISCOVERY diff --git a/settings.h.example b/settings.h.example index 4c70919..b1aa845 100644 --- a/settings.h.example +++ b/settings.h.example @@ -15,7 +15,7 @@ #define BAUD_GEIGERCOUNTER 9600 -//const char* HOSTNAME = "ESP-GeigerCounter"; //Optional +//#define HOSTNAME "ESP-GeigerCounter" //Optional const char* OTA_PASSWORD = "foobar";