losungepaper/wifi.ino

28 lines
934 B
Arduino
Raw Normal View History

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
void connectWiFi() { // connect to the wifi with the above defined credentials
if(WiFi.status() == WL_CONNECTED) { return; } // return if not connected
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) {
Serial.println("[WiFi] Failed to connect to WiFi. Reason: WL_NO_SSID_AVAIL");
return;
} else if(WiFi.status() == WL_CONNECT_FAILED) {
Serial.println("[WiFi] Failed to connect to WiFi. Reason: WL_CONNECT_FAILED");
return;
}
}
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-21 17:21:56 +00:00
Serial.println("[NTP] Getting time...");
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer.c_str());
Serial.println("[NTP] Got time.");
2022-08-21 15:28:52 +00:00
return;
}