changes to ntp update handling
This commit is contained in:
parent
0a0284e616
commit
29bf14e630
|
@ -3,6 +3,7 @@
|
|||
#include "Adafruit_MQTT_Client.h"
|
||||
#include <NTPClient.h>
|
||||
#include <WiFiUdp.h>
|
||||
//#include "time.h"
|
||||
|
||||
/************************* WiFi Settings *********************************/
|
||||
|
||||
|
@ -20,9 +21,9 @@
|
|||
/***********************NTP settings*********************************/
|
||||
|
||||
//UTC offset in seconds, 3600 for UTC+1
|
||||
#define UTC_OFFSET_S 3600
|
||||
#define UTC_OFFSET_S 3600
|
||||
//NTP server to use, pool is recommended
|
||||
#define NTP_SERVER "europe.pool.ntp.org"
|
||||
#define NTP_SERVER "europe.pool.ntp.org"
|
||||
|
||||
/************************* MQTT Setup ************************************/
|
||||
|
||||
|
@ -93,36 +94,38 @@ void loop() {
|
|||
}
|
||||
}
|
||||
|
||||
i = 0;
|
||||
i = 0;
|
||||
|
||||
if(commRecvd == true){
|
||||
if(strcmp("?ntp", incoming) == 0){ //if request for time update received, process time update
|
||||
while(!timeClient.update()){ //update from ntp server
|
||||
delay(10); //time sync is critical, wait for succesful update
|
||||
};
|
||||
Serial.print(">"); //indicate time data
|
||||
Serial.print(timeClient.getYear());
|
||||
Serial.print(",");
|
||||
Serial.print(timeClient.getMonth());
|
||||
Serial.print(",");
|
||||
Serial.print(timeClient.getDate());
|
||||
Serial.print(",");
|
||||
Serial.print(timeClient.getHours());
|
||||
Serial.print(",");
|
||||
Serial.print(timeClient.getMinutes());
|
||||
Serial.print(",");
|
||||
Serial.print(timeClient.getSeconds());
|
||||
Serial.print('\n');
|
||||
delay(1000); //give time to process comm
|
||||
} else {
|
||||
Serial.print("esp: recvd: ");
|
||||
Serial.println(incoming);
|
||||
test.publish(incoming);
|
||||
Serial.println("esp: sent data");
|
||||
if(commRecvd == true){
|
||||
if(strcmp("?ntp", incoming) == 0){ //if request for time update received, process time update
|
||||
while(!timeClient.update()){ //update from ntp server
|
||||
delay(10); //time sync is critical, wait for succesful update
|
||||
Serial.print("\\");
|
||||
};
|
||||
commRecvd = false;
|
||||
}
|
||||
delay(100);;
|
||||
Serial.print(">"); //indicate time data
|
||||
delay(50);
|
||||
Serial.print(timeClient.getYear());
|
||||
Serial.print("/");
|
||||
Serial.print(timeClient.getMonth());
|
||||
Serial.print("/");
|
||||
Serial.print(timeClient.getDate());
|
||||
Serial.print("/");
|
||||
Serial.print(timeClient.getHours());
|
||||
Serial.print("/");
|
||||
Serial.print(timeClient.getMinutes());
|
||||
Serial.print("/");
|
||||
Serial.print(timeClient.getSeconds());
|
||||
Serial.print('\n');
|
||||
delay(1000); //give time to process comm
|
||||
} else {
|
||||
Serial.print("esp: recvd: ");
|
||||
Serial.println(incoming);
|
||||
test.publish(incoming);
|
||||
Serial.println("esp: sent data");
|
||||
};
|
||||
commRecvd = false;
|
||||
}
|
||||
delay(100);;
|
||||
}
|
||||
|
||||
// Function to connect and reconnect as necessary to the MQTT server.
|
||||
|
|
Loading…
Reference in New Issue