File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ Various examples for DOIT ESP32 DEVKIT V1 using Arduino IDE and TinyGo.
1818- [ Web API Request] ( examples/Web%20API%20Request/README.md )
1919- [ 8-Channel Transistor Array] ( examples/8-Channel%20Transistor%20Array/README.md )
2020- [ SSR Relay] ( examples/SSR%20Relay/README.md )
21+ - [ NTP Client] ( examples/NTP%20Client/README.md )
2122
2223## TinyGo examples
2324
Original file line number Diff line number Diff line change 1+ # NTP Client
2+
3+ This exampple shows how to get current date and time from NTP server.
4+
5+ TODO code
6+
7+ ## Sources
8+
9+ [ ESP32 NTP Client-Server: Get Date and Time (Arduino IDE)] ( https://randomnerdtutorials.com/esp32-date-time-ntp-client-server-arduino/ )
Original file line number Diff line number Diff line change 1+ #include < WiFi.h>
2+ #include " time.h"
3+
4+ const char * ssid = " YOUR_SSID" ;
5+ const char * password = " YOUR_PASSWORD" ;
6+ const long gmtOffset_sec = 3600 ;
7+ const int daylightOffset_sec = 3600 ;
8+ const char * ntp_server = " pool.ntp.org" ;
9+
10+ void setup () {
11+ Serial.begin (9600 );
12+ WiFi.begin (ssid, password);
13+ while (WiFi.status () != WL_CONNECTED ) {
14+ delay (500 );
15+ Serial.print (" ." );
16+ }
17+ configTime (gmtOffset_sec, daylightOffset_sec, ntp_server);
18+ }
19+
20+ void loop () {
21+ struct tm timeinfo;
22+ if (getLocalTime (&timeinfo)) {
23+ Serial.println (&timeinfo, " %A, %B %d %Y %H:%M:%S" );
24+ }
25+ delay (1000 );
26+ }
You can’t perform that action at this time.
0 commit comments