28 lines
		
	
	
		
			934 B
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			934 B
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <WiFi.h>
 | 
						|
#include "time.h"
 | 
						|
 | 
						|
void connectWiFi() {  // connect to the wifi with the above defined credentials
 | 
						|
  if(WiFi.status() == WL_CONNECTED) { return; }  // return if not connected
 | 
						|
  
 | 
						|
  Serial.print("[WiFi] Connecting to WiFi...");
 | 
						|
 | 
						|
  WiFi.begin(wiFiSSID, wiFiPSK);
 | 
						|
  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);
 | 
						|
  Serial.println(WiFi.localIP());
 | 
						|
 | 
						|
  Serial.println("[NTP] Getting time...");
 | 
						|
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer.c_str());
 | 
						|
  Serial.println("[NTP] Got time.");
 | 
						|
 | 
						|
  return;
 | 
						|
} |