Skip to content

Commit d77d4da

Browse files
committed
Multi connections have been abolished
1 parent a3ab685 commit d77d4da

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

NTP_Client_ESP01/NTP_Client_ESP01.ino

+12-22
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,8 @@ HardwareSerial Serial1(PA10, PA9);
118118

119119
#define INTERVAL 10 // Interval of Packet Send(Second)
120120
#define NTP_SERVER "time.google.com" // NTP Server
121-
//#define NTP_SERVER "216.239.35.4" // NTP Server
122121
#define NTP_PORT 123 // NTP Port
123122
#define LOCAL_PORT 2390 // Local Port
124-
#define LINK_ID 3 // Link ID
125123
#define NTP_PACKET_SIZE 48 // NTP Packet Size
126124
#define TIME_ZONE 9 // Time Difference from GMT
127125
#define DNS_SERVER1 "8.8.8.8" // DNS SERVER1
@@ -179,17 +177,17 @@ void sendNTPpacket(char *ntpSrv, int ntpPort)
179177
// (see URL above for details on the packets)
180178

181179
packetBuffer[0] = 0b11100011; // LI, Version, Mode
182-
packetBuffer[1] = 0; // Stratum, or type of clock
183-
packetBuffer[2] = 6; // Polling Interval
184-
packetBuffer[3] = 0xEC; // Peer Clock Precision
180+
packetBuffer[1] = 0; // Stratum, or type of clock
181+
packetBuffer[2] = 6; // Polling Interval
182+
packetBuffer[3] = 0xEC; // Peer Clock Precision
185183
// 8 bytes of zero for Root Delay & Root Dispersion
186-
packetBuffer[12] = 49;
187-
packetBuffer[13] = 0x4E;
188-
packetBuffer[14] = 49;
189-
packetBuffer[15] = 52;
184+
packetBuffer[12] = 49;
185+
packetBuffer[13] = 0x4E;
186+
packetBuffer[14] = 49;
187+
packetBuffer[15] = 52;
190188

191189
//Send Data
192-
int ret = sendData(LINK_ID, packetBuffer, NTP_PACKET_SIZE, ntpSrv, ntpPort);
190+
int ret = sendData(-1, packetBuffer, NTP_PACKET_SIZE, ntpSrv, ntpPort);
193191
if (ret) {
194192
errorDisplay("sendData Fail");
195193
}
@@ -265,23 +263,15 @@ void setup(void)
265263
}
266264
clearBuffer();
267265

268-
//Enable multi connections
269-
sendCommand("AT+CIPMUX=1");
270-
if (!waitForString("OK", 2, 1000)) {
271-
errorDisplay("AT+CIPMUX Fail");
272-
}
273-
clearBuffer();
274-
275266
//Establish UDP Transmission
276-
//AT+CIPSTART=<link ID>,<type="UDP">,<remoteIP="0">,<remote port=0>,<UDP local port>,<UDP mode=2>
277-
sprintf(cmd,"AT+CIPSTART=%d,\"UDP\",\"0\",0,%u,2", LINK_ID, LOCAL_PORT);
278-
//sendCommand("AT+CIPSTART=3,\"UDP\",\"0\",0,2390,2");
267+
//AT+CIPSTART=<type="UDP">,<remoteIP="0">,<remote port=0>,<UDP local port>,<UDP mode=2>
268+
sprintf(cmd,"AT+CIPSTART=\"UDP\",\"0\",0,%u,2", LOCAL_PORT);
269+
//sendCommand("AT+CIPSTART=\"UDP\",\"0\",0,2390,2");
279270
sendCommand(cmd);
280271
if (!waitForString("OK", 2, 1000)) {
281272
errorDisplay("AT+CIPSTART Fail");
282273
}
283274
clearBuffer();
284-
285275
Serial.println("Start NTP Client [" + String(_MODEL_) + "] using " + String(NTP_SERVER));
286276

287277
// send an NTP packet to a time server
@@ -311,7 +301,7 @@ void loop(void) {
311301
}
312302

313303
// Read data from NTP server
314-
int readLen = readResponse(LINK_ID, packetBuffer, NTP_PACKET_SIZE, 1000);
304+
int readLen = readResponse(-1, packetBuffer, NTP_PACKET_SIZE, 1000);
315305
//Serial.print("packet received, length=");
316306
//Serial.println(readLen);
317307
if (readLen == NTP_PACKET_SIZE) {

0 commit comments

Comments
 (0)