Merge pull request #1 from lutzky/master
Add customizable DHCP hostname
This commit is contained in:
commit
9c5804dc9f
|
@ -22,6 +22,8 @@
|
||||||
#define WIFI_SSID ""
|
#define WIFI_SSID ""
|
||||||
// Wi-Fi password (required)
|
// Wi-Fi password (required)
|
||||||
#define WIFI_PASSWORD ""
|
#define WIFI_PASSWORD ""
|
||||||
|
// Wi-Fi hostname (for DHCP, uncomment if non-default desired)
|
||||||
|
// #define WIFI_HOSTNAME "my_host_name"
|
||||||
// Wi-Fi static IPv4 address enabled or disabled (disable for DHCPv4)
|
// Wi-Fi static IPv4 address enabled or disabled (disable for DHCPv4)
|
||||||
#define WIFI_IPV4_STATIC false
|
#define WIFI_IPV4_STATIC false
|
||||||
// Wi-Fi static IPv4 address
|
// Wi-Fi static IPv4 address
|
||||||
|
|
13
src/src.ino
13
src/src.ino
|
@ -44,6 +44,7 @@ void setup_dht_sensor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_wifi() {
|
void setup_wifi() {
|
||||||
|
WiFi.mode(WIFI_STA);
|
||||||
char message[128];
|
char message[128];
|
||||||
snprintf(message, 128, "Wi-Fi SSID: %s", WIFI_SSID);
|
snprintf(message, 128, "Wi-Fi SSID: %s", WIFI_SSID);
|
||||||
log(message);
|
log(message);
|
||||||
|
@ -70,6 +71,18 @@ void setup_wifi() {
|
||||||
}
|
}
|
||||||
|
|
||||||
log("Wi-Fi connecting ...");
|
log("Wi-Fi connecting ...");
|
||||||
|
#ifdef WIFI_HOSTNAME
|
||||||
|
snprintf(message, 128, "Initial hostname: %s", WiFi.hostname().c_str());
|
||||||
|
log(message);
|
||||||
|
log("Requesting hostname " WIFI_HOSTNAME);
|
||||||
|
if (!WiFi.hostname(WIFI_HOSTNAME)) {
|
||||||
|
log("Hostname request failed");
|
||||||
|
} else {
|
||||||
|
log("Hostname request succeeded");
|
||||||
|
}
|
||||||
|
snprintf(message, 128, "New hostname: %s", WiFi.hostname().c_str());
|
||||||
|
log(message);
|
||||||
|
#endif
|
||||||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
log("Wi-Fi waiting ...", LogLevel::DEBUG);
|
log("Wi-Fi waiting ...", LogLevel::DEBUG);
|
||||||
|
|
Loading…
Reference in New Issue