20 lines
743 B
C++
Executable File
20 lines
743 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.println("[WiFi] Connecting to WiFi...");
|
|
|
|
WiFi.begin(wiFiSSID, wiFiPSK);
|
|
delay(10000); // pause the program 5 secs to give time for connection
|
|
if(WiFi.status() != WL_CONNECTED) { Serial.printf("[WiFi] Failed connecting to WiFi \"%s\".", wiFiSSID); return; }
|
|
Serial.printf("[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;
|
|
} |