22#include < NtpClientDemo.h>
33#include < ZonedClock.h>
44#include < tzdata.h>
5+ #include < WVector.h>
56
67// If you want, you can define WiFi settings globally in Eclipse Environment Variables
78#ifndef WIFI_SSID
@@ -15,10 +16,13 @@ namespace
1516
1617SimpleTimer printTimer;
1718
18- ZonedClock london = TZ::Europe::London();
19- ZonedClock berlin = TZ::Europe::Berlin();
20- ZonedClock moscow = TZ::Europe::Moscow();
21- ZonedClock sydney = TZ::Australia::Sydney();
19+ DEFINE_FSTR_LOCAL (zoneNames, " Europe/London\0 "
20+ " Europe/Berlin\0 "
21+ " Europe/Moscow\0 "
22+ " Australia/Sydney\0 "
23+ " Asia/Qatar\0 " )
24+
25+ Vector<ZonedClock> clocks;
2226
2327// Option 1
2428// Use this option if you want to have full control of NtpTime client
@@ -69,12 +73,12 @@ void onPrintSystemTime()
6973 " \033 [H" // Home
7074 " \033 [0r" // Set scrolling region
7175 );
72- printClock (london);
73- printClock (berlin );
74- printClock (moscow);
75- printClock (sydney) ;
76- Serial << _F (" \033 [6r " // Set scrolling region
77- " \033 8" // Restore cursor position
76+ for ( auto & clock : clocks) {
77+ printClock (clock );
78+ }
79+ Serial << _F ( " UTC: " ) << ZonedTime (SystemClock. now (eTZ_UTC)). toString () << endl ;
80+ Serial << _F (" \033 [10r " // Set scrolling region
81+ " \033 8" // Restore cursor position
7882 );
7983}
8084
@@ -129,35 +133,21 @@ void init()
129133 Serial.begin (SERIAL_BAUD_RATE);
130134 Serial.systemDebugOutput (true ); // Allow debug print to serial
131135
132- if (0 ) {
133- DateTime dt1;
134-
135- auto printChange = [&]() {
136- auto change = london.getTimezone ().getNextChange (dt1);
137- Serial << dt1.toFullDateTimeString () << " -> " << change.toString () << endl;
138- };
139-
140- dt1.setTime (1774746000 - 1 );
141- printChange ();
142-
143- dt1.setTime (0 , 0 , 0 , 31 , dtDecember, 2025 );
144- printChange ();
145- dt1.setTime (0 , 0 , 0 , 1 , dtJanuary, 2026 );
146- printChange ();
147- dt1.setTime (0 , 0 , 1 , 29 , dtMarch, 2026 );
148- printChange ();
149- dt1.setTime (0 , 0 , 1 , 25 , dtOctober, 2026 );
150- printChange ();
151-
152- abort ();
153- }
154-
155- Serial << _F (" \033 [H" // Home
156- " \033 [0J" // Erase screen
157- " \033 [5B" // Down 5 lines
136+ Serial << _F (" \033 [H" // Home
137+ " \033 [0J" // Erase screen
138+ " \033 [10B" // Down 10 lines
158139 )
159140 << _F (" Sming. Let's do smart things!" ) << endl;
160141
142+ for (auto name : CStringArray (zoneNames)) {
143+ auto zone = TZ::findZone (name);
144+ if (!zone) {
145+ Serial << " Error! Zone '" << name << " ' not found" << endl;
146+ continue ;
147+ }
148+ clocks.add (*zone);
149+ }
150+
161151 // Station - WiFi client
162152 WifiStation.enable (true );
163153 WifiStation.config (WIFI_SSID, WIFI_PWD); // Put your SSID and password here
0 commit comments