-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.pio | ||
.vscode/.browse.c_cpp.db* | ||
.vscode/c_cpp_properties.json | ||
.vscode/launch.json | ||
.vscode/ipch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
// See http://go.microsoft.com/fwlink/?LinkId=827846 | ||
// for the documentation about the extensions.json format | ||
"recommendations": [ | ||
"platformio.platformio-ide" | ||
], | ||
"unwantedRecommendations": [ | ||
"ms-vscode.cpptools-extension-pack" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
; PlatformIO Project Configuration File | ||
; | ||
; Build options: build flags, source filter | ||
; Upload options: custom upload port, speed and extra flags | ||
; Library options: dependencies, extra library storages | ||
; Advanced options: extra scripting | ||
; | ||
; Please visit documentation for the other options and examples | ||
; https://docs.platformio.org/page/projectconf.html | ||
; | ||
|
||
[platformio] | ||
default_envs = esp32dev | ||
src_dir = src | ||
|
||
[env:esp32dev] | ||
framework = arduino | ||
platform = [email protected] ; https://registry.platformio.org/platforms/platformio/espressif32/versions | ||
board = esp32dev | ||
build_flags = -DCORE_DEBUG_LEVEL=0 | ||
monitor_speed = 115200 | ||
lib_deps = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
Rui Santos | ||
Complete project details at https://RandomNerdTutorials.com/esp32-date-time-ntp-client-server-arduino/ | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files. | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
*/ | ||
|
||
#include "time.h" | ||
#include <WiFi.h> | ||
|
||
const char* ssid = "REPLACE_WITH_YOUR_SSID"; | ||
const char* password = "REPLACE_WITH_YOUR_PASSWORD"; | ||
|
||
const char* ntpServer = "pool.ntp.org"; | ||
const long gmtOffset_sec = -3600 * 5; | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
|
||
// Connect to Wi-Fi | ||
Serial.print("Connecting to "); | ||
Serial.println(ssid); | ||
WiFi.begin("Brown-Guest"); | ||
while (WiFi.status() != WL_CONNECTED) { | ||
delay(500); | ||
Serial.print("."); | ||
} | ||
Serial.println(""); | ||
Serial.println("WiFi connected."); | ||
|
||
// Init and get the time | ||
configTime(gmtOffset_sec, 3600, ntpServer); | ||
} | ||
|
||
void loop() | ||
{ | ||
delay(1000); | ||
struct tm timeinfo; | ||
|
||
if (!getLocalTime(&timeinfo)) { | ||
Serial.println("Failed to obtain time"); | ||
return; | ||
} | ||
time_t now; | ||
time(&now); | ||
Serial.println(now); | ||
printLocalTime(); | ||
} | ||
|
||
void printLocalTime() | ||
{ | ||
struct tm timeinfo; | ||
if (!getLocalTime(&timeinfo)) { | ||
Serial.println("Failed to obtain time"); | ||
return; | ||
} | ||
time_t now; | ||
|
||
time(&now); | ||
Serial.println(now); | ||
|
||
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S"); | ||
Serial.print("Day of week: "); | ||
Serial.println(&timeinfo, "%A"); | ||
Serial.print("Month: "); | ||
Serial.println(&timeinfo, "%B"); | ||
Serial.print("Day of Month: "); | ||
Serial.println(&timeinfo, "%d"); | ||
Serial.print("Year: "); | ||
Serial.println(&timeinfo, "%Y"); | ||
Serial.print("Hour: "); | ||
Serial.println(&timeinfo, "%H"); | ||
Serial.print("Hour (12 hour format): "); | ||
Serial.println(&timeinfo, "%I"); | ||
Serial.print("Minute: "); | ||
Serial.println(&timeinfo, "%M"); | ||
Serial.print("Second: "); | ||
Serial.println(&timeinfo, "%S"); | ||
|
||
Serial.println("Time variables"); | ||
char timeHour[3]; | ||
strftime(timeHour, 3, "%H", &timeinfo); | ||
Serial.println(timeHour); | ||
char timeWeekDay[10]; | ||
strftime(timeWeekDay, 10, "%A", &timeinfo); | ||
Serial.println(timeWeekDay); | ||
Serial.println(); | ||
} |