Skip to content

Commit

Permalink
Simplfy event handling in example
Browse files Browse the repository at this point in the history
  • Loading branch information
gmag11 committed Nov 27, 2020
1 parent c623a67 commit 3736b3e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 47 deletions.
30 changes: 1 addition & 29 deletions examples/advancedExample/advancedExample.ino
Original file line number Diff line number Diff line change
Expand Up @@ -78,35 +78,7 @@ void onWifiEvent (WiFiEvent_t event) {
}

void processSyncEvent (NTPEvent_t ntpEvent) {
Serial.print ("[NTP-event] ");
if (ntpEvent.event < 0) {
Serial.printf ("Time Sync error %d: ", ntpEvent.event);
if (ntpEvent.event == noResponse) {
Serial.printf ("NTP server not reachable: %s",
ntpEvent.info.serverAddress.toString ().c_str ());
} else if (ntpEvent.event == invalidAddress) {
Serial.printf ("Invalid NTP server address: %s",
ntpEvent.info.serverAddress.toString ().c_str ());
}
} else {
if (!ntpEvent.event) {
Serial.printf ("Got NTP time: %s from %s:%u. Offset: %0.3f ms. Delay: %0.3f ms",
NTP.getTimeDateString (NTP.getLastNTPSyncUs ()),
ntpEvent.info.serverAddress.toString ().c_str (),
ntpEvent.info.port,
ntpEvent.info.offset * 1000,
ntpEvent.info.delay * 1000);
} else if (ntpEvent.event == requestSent) {
Serial.printf ("NTP request Sent to %s:%u",
ntpEvent.info.serverAddress.toString ().c_str (),
ntpEvent.info.port);
} else if (ntpEvent.event == partlySync) {
Serial.printf ("Partial sync %s Offset %0.3f",
NTP.getTimeDateString (NTP.getLastNTPSyncUs ()),
ntpEvent.info.offset * 1000);
}
}
Serial.println ();
Serial.printf ("[NTP-event] %s\n", NTP.ntpEvent2str (ntpEvent));
}


Expand Down
6 changes: 1 addition & 5 deletions examples/basicExample/basicExample.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@

#define SHOW_TIME_PERIOD 1000

const PROGMEM char* ntpServer = "pool.ntp.org";

boolean syncEventTriggered = false; // True if a time even has been triggered

void setup() {
Serial.begin (115200);
Serial.println ();
WiFi.begin (YOUR_WIFI_SSID, YOUR_WIFI_PASSWD);
NTP.setTimeZone (TZ_Etc_UTC);
NTP.begin (ntpServer);
NTP.begin ();
}

void loop() {
Expand Down
14 changes: 1 addition & 13 deletions examples/ledFlasher/ledFlasher.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,7 @@ boolean syncEventTriggered = false; // True if a time even has been triggered
NTPEvent_t ntpEvent; // Last triggered event

void processSyncEvent (NTPEvent_t ntpEvent) {
//Serial.printf ("[NTP-event] %d\n", ntpEvent.event);
if (ntpEvent.event == timeSyncd) {
Serial.printf ("[NTP-event] Got NTP time: %s from %s:%u. Offset: %0.3f ms. Delay: %0.3f ms\n",
NTP.getTimeDateStringUs (),
ntpEvent.info.serverAddress.toString ().c_str (),
ntpEvent.info.port,
ntpEvent.info.offset * 1000,
ntpEvent.info.delay * 1000);
} /*else if (ntpEvent.event == partlySync) {
Serial.printf ("[NTP-event] Partial sync %s Offset %0.3f\n",
NTP.getTimeDateStringUs (),
ntpEvent.info.offset * 1000);
}*/
Serial.printf ("[NTP-event] %s\n", NTP.ntpEvent2str(ntpEvent));
}


Expand Down

0 comments on commit 3736b3e

Please sign in to comment.