Closed ettom closed 3 years ago
Hi, this is a feature request to allow setting a hostname. Good arguments for hostnames are OTA updates and general clarity when multiple devices are on the same network.
I've implemented this for ESP8266 and it's working well so far.
diff --git a/src/BlynkSimpleEsp8266.h b/src/BlynkSimpleEsp8266.h index a61552d..6c1eb9c 100644 --- a/src/BlynkSimpleEsp8266.h +++ b/src/BlynkSimpleEsp8266.h @@ -35,8 +35,12 @@ public: : Base(transp) {} - void connectWiFi(const char* ssid, const char* pass) + void connectWiFi(const char* ssid, const char* pass, const char* hostname) { + if (hostname != NULL) { + WiFi.hostname(hostname); + BLYNK_LOG2(BLYNK_F("Set hostname to "), hostname); + } BLYNK_LOG2(BLYNK_F("Connecting to "), ssid); WiFi.mode(WIFI_STA); if (WiFi.status() != WL_CONNECTED) { @@ -75,9 +79,10 @@ public: const char* ssid, const char* pass, const char* domain = BLYNK_DEFAULT_DOMAIN, - uint16_t port = BLYNK_DEFAULT_PORT) + uint16_t port = BLYNK_DEFAULT_PORT, + const char* hostname = NULL) { - connectWiFi(ssid, pass); + connectWiFi(ssid, pass, hostname); config(auth, domain, port); while(this->connect() != true) {} } @@ -86,9 +91,10 @@ public: const char* ssid, const char* pass, IPAddress ip, - uint16_t port = BLYNK_DEFAULT_PORT) + uint16_t port = BLYNK_DEFAULT_PORT, + const char* hostname = NULL) { - connectWiFi(ssid, pass); + connectWiFi(ssid, pass, hostname); config(auth, ip, port); while(this->connect() != true) {} }
You can do this manually in your sketch. Sorry, I see no reason why this should be part of Blynk library.
Hi, this is a feature request to allow setting a hostname. Good arguments for hostnames are OTA updates and general clarity when multiple devices are on the same network.
I've implemented this for ESP8266 and it's working well so far.