#include "wifi_util.h" namespace config { // WiFi config. See 'config.h' if you want to modify those values. const char *wifi_ssid = WIFI_SSID; const char *wifi_password = WIFI_PASSWORD; #ifdef WIFI_TIMEOUT const uint8_t wifi_timeout = WIFI_TIMEOUT; // [s] Will try to connect during wifi_timeout seconds before failing. #else const uint8_t wifi_timeout = 60; // [s] Will try to connect during wifi_timeout seconds before failing. #endif } // Initialize Wi-Fi void WiFiConnect(const String &hostname) { //NOTE: WiFi Multi could allow multiple SSID and passwords. WiFi.persistent(false); // Don't write user & password to Flash. WiFi.mode(WIFI_STA); // Set ESP8266 to be a WiFi-client only #if defined(ESP8266) WiFi.hostname(hostname); #elif defined(ESP32) WiFi.setHostname(hostname.c_str()); #endif Serial.print("\nConnecting to "); Serial.println(config::wifi_ssid); WiFi.begin(config::wifi_ssid, config::wifi_password); // Wait for connection, at most wifi_timeout seconds for (int i = 0; i <= config::wifi_timeout && (WiFi.status() != WL_CONNECTED); i++) { LedEffects::showRainbowWheel(); Serial.print("."); } if (WiFi.status() == WL_CONNECTED) { LedEffects::showKITTWheel(color::green); Serial.println(); Serial.print("\nWiFi connected, IP address: "); Serial.println(WiFi.localIP()); } else { LedEffects::showKITTWheel(color::red); Serial.println("\nConnection to WiFi failed"); } }