ENTS-tock
Environmental NeTworked Sensor firmware on Tock OS
Loading...
Searching...
No Matches
example_ntp.cpp
Go to the documentation of this file.
1
11
#include <Arduino.h>
12
#include <NTPClient.h>
13
#include <WiFi.h>
14
16
#define SERIAL_BAUD 115200
17
18
const
char
ssid
[] =
"Enter-Your-SSID"
;
19
const
char
pass
[] =
"Enter-Your-Password"
;
20
21
WiFiUDP
ntpUDP
;
22
NTPClient
timeClient
(
ntpUDP
);
23
24
String
currentTime
;
25
26
void
setup
() {
27
// Start serial interface
28
Serial.begin(115200);
29
// Wait for serial connection
30
while
(!Serial) {
31
delay(100);
32
}
33
34
Serial.print(
"SSID: "
);
35
Serial.println(
ssid
);
36
Serial.print(
"Password: "
);
37
Serial.println(
pass
);
38
Serial.print(
"Connecting"
);
39
40
// Connect to WiFi network
41
WiFi.begin(
ssid
,
pass
);
42
43
// Wait for WiFi to connect
44
while
(WiFi.status() != WL_CONNECTED) {
45
delay(500);
46
Serial.print(
"."
);
47
}
48
Serial.println(
""
);
49
Serial.println(
"Connected!"
);
50
Serial.println(WiFi.localIP());
51
52
timeClient
.begin();
53
// Set time offset in seconds
54
// GMT = 0
55
// California: PST (GMT -7 hours) = -25200
56
// Georgia: EST (GMT -4 hours) = -14400
57
// Illinois: CDT (GMT -5 hours) = -18000
58
timeClient
.setTimeOffset(-28800);
59
}
60
61
void
loop
() {
62
// Prints time in HH:MM:SS format
63
while
(!
timeClient
.update()) {
64
timeClient
.forceUpdate();
65
}
66
currentTime
=
timeClient
.getFormattedTime();
67
Serial.print(
"The time is: "
);
68
Serial.println(
currentTime
);
69
70
// Wait 1 second
71
delay(1000);
72
}
ntpUDP
WiFiUDP ntpUDP
Definition
example_ntp.cpp:21
ssid
const char ssid[]
Definition
example_ntp.cpp:18
setup
void setup()
Definition
example_ntp.cpp:26
pass
const char pass[]
Definition
example_ntp.cpp:19
currentTime
String currentTime
Definition
example_ntp.cpp:24
timeClient
NTPClient timeClient(ntpUDP)
loop
void loop()
Definition
example_ntp.cpp:61
embedded
esp32
src
examples
example_ntp.cpp
Generated by
1.9.8