49 lines
1.2 KiB
C++
49 lines
1.2 KiB
C++
|
#include "horlogerie.h"
|
||
|
#include "Arduino.h"
|
||
|
#include "hardware.h"
|
||
|
#include "secrets.h"
|
||
|
|
||
|
#include <WiFi.h>
|
||
|
#include <NTPClient.h>
|
||
|
#include <WiFiUdp.h>
|
||
|
|
||
|
|
||
|
void initwifintp() {
|
||
|
|
||
|
// Replace with your network credentials (see in 'arduino_secrets.h' file)
|
||
|
char ssid[] = SECRET_WIFI_SSID;
|
||
|
const char* password = SECRET_WIFI_PASS;
|
||
|
|
||
|
// Define NTP Client to get time
|
||
|
WiFiUDP ntpUDP;
|
||
|
NTPClient timeClient(ntpUDP);
|
||
|
|
||
|
// Variables to save date and time
|
||
|
String formattedDate;
|
||
|
String dayStamp;
|
||
|
String timeStamp;
|
||
|
|
||
|
// Initialize Serial Monitor
|
||
|
Serial.begin(115200);
|
||
|
Serial.print("Connecting to ");
|
||
|
Serial.println(ssid);
|
||
|
WiFi.begin(ssid, password);
|
||
|
while (WiFi.status() != WL_CONNECTED) {
|
||
|
delay(100);
|
||
|
Serial.print(".");
|
||
|
}
|
||
|
// Print local IP address and start web server
|
||
|
Serial.println("");
|
||
|
Serial.println("WiFi connected.");
|
||
|
Serial.println("IP address: ");
|
||
|
Serial.println(WiFi.localIP());
|
||
|
|
||
|
// Initialize a NTPClient to get time
|
||
|
timeClient.begin();
|
||
|
// Set offset time in seconds to adjust for your timezone, for example:
|
||
|
// GMT +1 = 3600
|
||
|
// GMT +8 = 28800
|
||
|
// GMT -1 = -3600
|
||
|
// GMT 0 = 0
|
||
|
timeClient.setTimeOffset(3600);
|
||
|
}
|