54 lines
1.4 KiB
C++
54 lines
1.4 KiB
C++
#include "Program.h"
|
|
|
|
Program::Program() {
|
|
// Startup
|
|
Serial.begin(MONITOR_SPEED);
|
|
|
|
WiFi.begin(WSSID, PASS);
|
|
|
|
Serial.print("Connecting to ");
|
|
Serial.print(WSSID); Serial.println(" ...");
|
|
|
|
int i = 0;
|
|
while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
|
|
delay(1000);
|
|
Serial.print(++i); Serial.print(' ');
|
|
}
|
|
|
|
Serial.println('\n');
|
|
Serial.println("Connection established!");
|
|
Serial.print("IP address:\t");
|
|
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer
|
|
|
|
|
|
//init obj
|
|
this->discord = new DiscordAPI(DISCORD_HOOK);
|
|
this->ntpUDP = new WiFiUDP();
|
|
this->timeClient = new NTPClient(*this->ntpUDP, "pool.ntp.org", 3600*2);//*2 = gnt+2
|
|
|
|
//Serial.println(this->discord->sendHeure("10h", "18h"));
|
|
}
|
|
|
|
void Program::loop() {
|
|
// Loop
|
|
delay(1000);
|
|
|
|
this->timeClient->update();
|
|
|
|
int currentHour = this->timeClient->getHours();
|
|
Serial.print("Hour: ");
|
|
Serial.println(currentHour);
|
|
|
|
int currentMinute = this->timeClient->getMinutes();
|
|
Serial.print("Minutes: ");
|
|
Serial.println(currentMinute);
|
|
|
|
int currentSecond = this->timeClient->getSeconds();
|
|
Serial.print("Seconds: ");
|
|
Serial.println(currentSecond);
|
|
|
|
int currentDayOfWeek = this->timeClient->getDay();
|
|
Serial.print("Day of week: ");
|
|
Serial.println(currentDayOfWeek);
|
|
}
|