Commit b1475814 authored by Eric Duminil's avatar Eric Duminil
Browse files

wifi::connected

parent 6c4ef5bf
Pipeline #5744 canceled with stage
...@@ -88,10 +88,7 @@ void setup() { ...@@ -88,10 +88,7 @@ void setup() {
#ifdef AMPEL_WIFI #ifdef AMPEL_WIFI
wifi::connect(ampel.sensorId); wifi::connect(ampel.sensorId);
Serial.print(F("WiFi - Status: ")); if (wifi::connected()) {
Serial.println(WiFi.status());
if (WiFi.status() == WL_CONNECTED) {
# ifdef AMPEL_HTTP # ifdef AMPEL_HTTP
web_server::initialize(); web_server::initialize();
# endif # endif
...@@ -203,7 +200,7 @@ void checkFlashButton() { ...@@ -203,7 +200,7 @@ void checkFlashButton() {
void keepServicesAlive() { void keepServicesAlive() {
#ifdef AMPEL_WIFI #ifdef AMPEL_WIFI
if (WiFi.status() == WL_CONNECTED) { if (wifi::connected()) {
# if defined(ESP8266) # if defined(ESP8266)
//NOTE: Sadly, there seems to be a bug in the current MDNS implementation. //NOTE: Sadly, there seems to be a bug in the current MDNS implementation.
// It stops working after 2 minutes. And forcing a restart leads to a memory leak. // It stops working after 2 minutes. And forcing a restart leads to a memory leak.
......
...@@ -51,6 +51,10 @@ namespace wifi { ...@@ -51,6 +51,10 @@ namespace wifi {
Serial.println(WIFI_SSID); Serial.println(WIFI_SSID);
} }
bool connected() {
return WiFi.status() == WL_CONNECTED;
}
// Initialize Wi-Fi // Initialize Wi-Fi
void connect(const char *hostname) { void connect(const char *hostname) {
...@@ -75,7 +79,7 @@ namespace wifi { ...@@ -75,7 +79,7 @@ namespace wifi {
led_effects::showRainbowWheel(); led_effects::showRainbowWheel();
Serial.print("."); Serial.print(".");
} }
if (WiFi.status() == WL_CONNECTED) { if (connected()) {
led_effects::showKITTWheel(color::green); led_effects::showKITTWheel(color::green);
Serial.println(); Serial.println();
Serial.print(F("WiFi - Connected! IP address: ")); Serial.print(F("WiFi - Connected! IP address: "));
...@@ -85,7 +89,8 @@ namespace wifi { ...@@ -85,7 +89,8 @@ namespace wifi {
} else { } else {
//TODO: Allow sensor to work as an Access Point, in order to define SSID & password? //TODO: Allow sensor to work as an Access Point, in order to define SSID & password?
led_effects::showKITTWheel(color::red); led_effects::showKITTWheel(color::red);
Serial.println(F("Connection to WiFi failed")); Serial.print(F("Connection to WiFi failed! Status : "));
Serial.println(WiFi.status());
} }
} }
} }
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
namespace wifi { namespace wifi {
extern char local_ip[]; extern char local_ip[];
void connect(const char *hostname); void connect(const char *hostname);
bool connected();
} }
#endif #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment