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
18const char ssid[] = "Enter-Your-SSID";
19const char pass[] = "Enter-Your-Password";
20
21WiFiUDP ntpUDP;
22NTPClient timeClient(ntpUDP);
23
25
26void 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
61void 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}
WiFiUDP ntpUDP
const char ssid[]
void setup()
const char pass[]
String currentTime
NTPClient timeClient(ntpUDP)
void loop()