2022-08-21 15:28:52 +00:00
|
|
|
#include <WiFi.h>
|
2022-08-21 17:21:56 +00:00
|
|
|
#include "time.h"
|
2022-08-21 15:28:52 +00:00
|
|
|
|
2022-08-22 07:28:21 +00:00
|
|
|
void blinkLED(int pin) {
|
|
|
|
pinMode(pin, OUTPUT);
|
|
|
|
delay(500);
|
|
|
|
digitalWrite(pin,HIGH);
|
|
|
|
delay(500);
|
|
|
|
digitalWrite(pin,LOW);
|
|
|
|
delay(500);
|
|
|
|
digitalWrite(pin,HIGH);
|
|
|
|
delay(500);
|
|
|
|
digitalWrite(pin,LOW);
|
|
|
|
}
|
|
|
|
|
2022-08-22 07:20:39 +00:00
|
|
|
bool connectWiFi() { // connect to the wifi with the above defined credentials
|
|
|
|
if(WiFi.status() == WL_CONNECTED) { return true; } // return if not connected
|
2022-08-21 15:28:52 +00:00
|
|
|
|
2022-08-21 19:12:34 +00:00
|
|
|
Serial.print("[WiFi] Connecting to WiFi...");
|
2022-08-21 15:28:52 +00:00
|
|
|
|
|
|
|
WiFi.begin(wiFiSSID, wiFiPSK);
|
2022-08-21 19:12:34 +00:00
|
|
|
while(WiFi.status() != WL_CONNECTED) {
|
|
|
|
delay(2000); Serial.printf(".");
|
|
|
|
if(WiFi.status() == WL_NO_SSID_AVAIL) {
|
2023-05-29 15:53:46 +00:00
|
|
|
Serial.printf("\n[WiFi] Failed to connect to WiFi \"%s\". Reason: WL_NO_SSID_AVAIL\n", wiFiSSID);
|
2022-08-22 07:28:21 +00:00
|
|
|
blinkLED(LED_ON_WIFI_ERROR);
|
2022-08-22 07:20:39 +00:00
|
|
|
return false;
|
2022-08-21 19:12:34 +00:00
|
|
|
} else if(WiFi.status() == WL_CONNECT_FAILED) {
|
2023-05-29 15:53:46 +00:00
|
|
|
Serial.printf("\n[WiFi] Failed to connect to WiFi \"%s\". Reason: WL_CONNECT_FAILED\n", wiFiSSID);
|
2022-08-22 07:28:21 +00:00
|
|
|
blinkLED(LED_ON_WIFI_ERROR);
|
2022-08-22 07:20:39 +00:00
|
|
|
return false;
|
2022-08-21 19:12:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Serial.printf("\n[WiFi] Connected to WiFi \"%s\", got IP-Adress ", wiFiSSID);
|
2022-08-21 15:28:52 +00:00
|
|
|
Serial.println(WiFi.localIP());
|
|
|
|
|
2022-08-22 07:20:39 +00:00
|
|
|
return true;
|
2022-08-21 15:28:52 +00:00
|
|
|
}
|