From 8efa1d4d0eb92a5b08961163fd467707407f8f78 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Sat, 4 Jul 2015 10:00:27 +0200 Subject: [PATCH] allow setting the host name of AP interface --- .../libraries/ESP8266WiFi/src/ESP8266WiFi.cpp | 19 +++++++++++++++++++ .../libraries/ESP8266WiFi/src/ESP8266WiFi.h | 13 +++++++++++++ 2 files changed, 32 insertions(+) diff --git a/hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/ESP8266WiFi.cpp b/hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/ESP8266WiFi.cpp index 474f4f3014..6b20a0623d 100644 --- a/hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/ESP8266WiFi.cpp +++ b/hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/ESP8266WiFi.cpp @@ -582,6 +582,25 @@ int ESP8266WiFiClass::hostByName(const char* aHostname, IPAddress& aResult) return (aResult != 0) ? 1 : 0; } +String ESP8266WiFiClass::hostname(void) { + return String(wifi_station_get_hostname()); +} + +bool ESP8266WiFiClass::hostname(char* aHostname) { + if(strlen(aHostname) > 32) { + return false; + } + return wifi_station_set_hostname(aHostname); +} + +bool ESP8266WiFiClass::hostname(const char* aHostname) { + return hostname((char*) aHostname); +} + +bool ESP8266WiFiClass::hostname(String aHostname) { + return hostname((char*) aHostname.c_str()); +} + void ESP8266WiFiClass::beginSmartConfig() { if (_smartConfigStarted) diff --git a/hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/ESP8266WiFi.h b/hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/ESP8266WiFi.h index bd4502b209..0df2cdc6de 100644 --- a/hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/ESP8266WiFi.h +++ b/hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/ESP8266WiFi.h @@ -300,6 +300,19 @@ class ESP8266WiFiClass */ int hostByName(const char* aHostname, IPAddress& aResult); + /* + * Get ESP8266 station DHCP hostname + */ + String hostname(void); + + /* + * Set ESP8266 station DHCP hostname + * hostname, max length:32 + */ + bool hostname(char* aHostname); + bool hostname(const char* aHostname); + bool hostname(String aHostname); + /* * Output WiFi settings to an object derived from Print interface (like Serial). *