1
1
/*
2
- Udp NTP Client
2
+ Udp NTP Client
3
3
4
- Get the time from a Network Time Protocol (NTP) time server
5
- Demonstrates use of UDP sendPacket and ReceivePacket
6
- For more on NTP time servers and the messages needed to communicate with them,
7
- see http://en.wikipedia.org/wiki/Network_Time_Protocol
4
+ Get the time from a Network Time Protocol (NTP) time server
5
+ Demonstrates use of UDP sendPacket and ReceivePacket
6
+ For more on NTP time servers and the messages needed to communicate with them,
7
+ see http://en.wikipedia.org/wiki/Network_Time_Protocol
8
8
9
- created 4 Sep 2010
10
- by Michael Margolis
11
- modified 9 Apr 2012
12
- by Tom Igoe
9
+ Circuit:
10
+ - SparkFun Qwiic WiFi Shield - DA16200 attached
13
11
14
- This code is in the public domain.
12
+ created 4 Sep 2010
13
+ by Michael Margolis
14
+ modified 9 Apr 2012
15
+ by Tom Igoe
16
+ modified 15 October 2021
17
+ by Sandeep Mistry to port to DA16200
15
18
16
- */
19
+ This code is in the public domain.
17
20
18
- #include < SPI.h>
19
- #include < WiFiNINA.h>
21
+ */
22
+
23
+ #include < DA16200_WiFi.h>
20
24
#include < WiFiUdp.h>
21
25
22
- int status = WL_IDLE_STATUS;
23
- #include " arduino_secrets.h"
24
26
// /////please enter your sensitive data in the Secret tab/arduino_secrets.h
27
+ #include " arduino_secrets.h"
28
+
29
+ int status = WL_IDLE_STATUS;
30
+
25
31
char ssid[] = SECRET_SSID; // your network SSID (name)
26
32
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
27
33
int keyIndex = 0 ; // your network key index number (needed only for WEP)
@@ -62,9 +68,6 @@ void setup() {
62
68
Serial.println (ssid);
63
69
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
64
70
status = WiFi.begin (ssid, pass);
65
-
66
- // wait 10 seconds for connection:
67
- delay (10000 );
68
71
}
69
72
70
73
Serial.println (" Connected to WiFi" );
@@ -126,12 +129,10 @@ void loop() {
126
129
127
130
// send an NTP request to the time server at the given address
128
131
unsigned long sendNTPpacket (IPAddress& address) {
129
- // Serial.println("1");
130
132
// set all bytes in the buffer to 0
131
133
memset (packetBuffer, 0 , NTP_PACKET_SIZE);
132
134
// Initialize values needed to form NTP request
133
135
// (see URL above for details on the packets)
134
- // Serial.println("2");
135
136
packetBuffer[0 ] = 0b11100011 ; // LI, Version, Mode
136
137
packetBuffer[1 ] = 0 ; // Stratum, or type of clock
137
138
packetBuffer[2 ] = 6 ; // Polling Interval
@@ -142,16 +143,11 @@ unsigned long sendNTPpacket(IPAddress& address) {
142
143
packetBuffer[14 ] = 49 ;
143
144
packetBuffer[15 ] = 52 ;
144
145
145
- // Serial.println("3");
146
-
147
146
// all NTP fields have been given values, now
148
147
// you can send a packet requesting a timestamp:
149
148
Udp.beginPacket (address, 123 ); // NTP requests are to port 123
150
- // Serial.println("4");
151
149
Udp.write (packetBuffer, NTP_PACKET_SIZE);
152
- // Serial.println("5");
153
150
Udp.endPacket ();
154
- // Serial.println("6");
155
151
}
156
152
157
153
0 commit comments