Skip to content

Commit 8efa1d4

Browse files
Links2004igrr
authored andcommitted
allow setting the host name of AP interface
1 parent 811a373 commit 8efa1d4

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/ESP8266WiFi.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,25 @@ int ESP8266WiFiClass::hostByName(const char* aHostname, IPAddress& aResult)
582582
return (aResult != 0) ? 1 : 0;
583583
}
584584

585+
String ESP8266WiFiClass::hostname(void) {
586+
return String(wifi_station_get_hostname());
587+
}
588+
589+
bool ESP8266WiFiClass::hostname(char* aHostname) {
590+
if(strlen(aHostname) > 32) {
591+
return false;
592+
}
593+
return wifi_station_set_hostname(aHostname);
594+
}
595+
596+
bool ESP8266WiFiClass::hostname(const char* aHostname) {
597+
return hostname((char*) aHostname);
598+
}
599+
600+
bool ESP8266WiFiClass::hostname(String aHostname) {
601+
return hostname((char*) aHostname.c_str());
602+
}
603+
585604
void ESP8266WiFiClass::beginSmartConfig()
586605
{
587606
if (_smartConfigStarted)

hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/ESP8266WiFi.h

+13
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,19 @@ class ESP8266WiFiClass
300300
*/
301301
int hostByName(const char* aHostname, IPAddress& aResult);
302302

303+
/*
304+
* Get ESP8266 station DHCP hostname
305+
*/
306+
String hostname(void);
307+
308+
/*
309+
* Set ESP8266 station DHCP hostname
310+
* hostname, max length:32
311+
*/
312+
bool hostname(char* aHostname);
313+
bool hostname(const char* aHostname);
314+
bool hostname(String aHostname);
315+
303316
/*
304317
* Output WiFi settings to an object derived from Print interface (like Serial).
305318
*

0 commit comments

Comments
 (0)