feat: test ntp
This commit is contained in:
parent
6e2da886fc
commit
2c138a3225
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <NTPClient.h>
|
||||||
|
#include <WiFiUdp.h>
|
||||||
|
|
||||||
#include "DiscordAPI.h"
|
#include "DiscordAPI.h"
|
||||||
|
|
||||||
@ -21,6 +23,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
DiscordAPI* discord;
|
DiscordAPI* discord;
|
||||||
|
WiFiUDP* ntpUDP;
|
||||||
|
NTPClient* timeClient;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -52,6 +52,7 @@ upload_speed = 921600
|
|||||||
lib_deps =
|
lib_deps =
|
||||||
; example:
|
; example:
|
||||||
; erropix/ESP32 AnalogWrite@0.2
|
; erropix/ESP32 AnalogWrite@0.2
|
||||||
|
arduino-libraries/NTPClient@^3.2.1
|
||||||
|
|
||||||
; Checker settings
|
; Checker settings
|
||||||
check_tool = clangtidy, cppcheck
|
check_tool = clangtidy, cppcheck
|
||||||
|
@ -21,12 +21,33 @@ Program::Program() {
|
|||||||
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer
|
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer
|
||||||
|
|
||||||
|
|
||||||
|
//init obj
|
||||||
this->discord = new DiscordAPI(DISCORD_HOOK);
|
this->discord = new DiscordAPI(DISCORD_HOOK);
|
||||||
delay(1000);
|
this->ntpUDP = new WiFiUDP();
|
||||||
Serial.println(this->discord->sendHeure("10h", "18h"));
|
this->timeClient = new NTPClient(*this->ntpUDP, "pool.ntp.org", 3600*2);//*2 = gnt+2
|
||||||
|
|
||||||
|
//Serial.println(this->discord->sendHeure("10h", "18h"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Program::loop() {
|
void Program::loop() {
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
|
@ -9,3 +9,5 @@ void setup() {
|
|||||||
void loop() {
|
void loop() {
|
||||||
program->loop();
|
program->loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user