39
39
#include < WiFi.h>
40
40
#endif
41
41
#include < time.h>
42
- // #include <credentials.h>
42
+ #include < credentials.h>
43
43
44
44
/*
45
45
The credentials.h file at least has to contain:
@@ -76,7 +76,7 @@ void setup() {
76
76
int counter = 0 ;
77
77
while (WiFi.status () != WL_CONNECTED) {
78
78
delay (200 );
79
- if (++counter > 10 ) ESP.restart ();
79
+ if (++counter > 100 ) ESP.restart ();
80
80
Serial.print ( " ." );
81
81
}
82
82
Serial.println (" \n\n WiFi connected\n\n " );
@@ -90,7 +90,7 @@ void setup() {
90
90
Serial.println (" Time not set" );
91
91
ESP.restart ();
92
92
}
93
- showTime (& timeinfo);
93
+ showTime (timeinfo);
94
94
lastNTPtime = time (&now);
95
95
lastEntryTime = millis ();
96
96
}
@@ -99,7 +99,7 @@ void setup() {
99
99
void loop () {
100
100
// getTimeReducedTraffic(3600);
101
101
getNTPtime (10 );
102
- showTime (& timeinfo);
102
+ showTime (timeinfo);
103
103
delay (1000 );
104
104
}
105
105
@@ -115,7 +115,7 @@ bool getNTPtime(int sec) {
115
115
} while (((millis () - start) <= (1000 * sec)) && (timeinfo.tm_year < (2016 - 1900 )));
116
116
if (timeinfo.tm_year <= (2016 - 1900 )) return false ; // the NTP call was not successful
117
117
Serial.print (" now " ); Serial.println (now);
118
- char time_output[30 ];
118
+ char time_output[30 ];
119
119
strftime (time_output, 30 , " %a %d-%m-%y %T" , localtime (&now));
120
120
Serial.println (time_output);
121
121
Serial.println ();
@@ -124,11 +124,11 @@ bool getNTPtime(int sec) {
124
124
}
125
125
126
126
127
- // This function is obsolete because the time() function only calls the NTP server every hour. So you can always use getNTPtime()
127
+ // This function is obsolete because the time() function only calls the NTP server every hour. So you can always use getNTPtime()
128
128
// It can be deleted and only stays here for the video
129
129
130
130
/*
131
- void getTimeReducedTraffic(int sec) {
131
+ void getTimeReducedTraffic(int sec) {
132
132
tm *ptm;
133
133
if ((millis() - lastEntryTime) < (1000 * sec)) {
134
134
now = lastNTPtime + (int)(millis() - lastEntryTime) / 1000;
@@ -140,22 +140,41 @@ void getTimeReducedTraffic(int sec) {
140
140
}
141
141
ptm = localtime(&now);
142
142
timeinfo = *ptm;
143
- }
143
+ }
144
144
*/
145
145
146
- void showTime (tm * localTime) {
147
- Serial.print (localTime-> tm_mday );
146
+ void showTime (tm localTime) {
147
+ Serial.print (localTime. tm_mday );
148
148
Serial.print (' /' );
149
- Serial.print (localTime-> tm_mon + 1 );
149
+ Serial.print (localTime. tm_mon + 1 );
150
150
Serial.print (' /' );
151
- Serial.print (localTime-> tm_year - 100 );
151
+ Serial.print (localTime. tm_year - 100 );
152
152
Serial.print (' -' );
153
- Serial.print (localTime-> tm_hour );
153
+ Serial.print (localTime. tm_hour );
154
154
Serial.print (' :' );
155
- Serial.print (localTime-> tm_min );
155
+ Serial.print (localTime. tm_min );
156
156
Serial.print (' :' );
157
- Serial.print (localTime-> tm_sec );
157
+ Serial.print (localTime. tm_sec );
158
158
Serial.print (" Day of Week " );
159
- if (localTime-> tm_mday = 0 ) localTime-> tm_mday = 7 ;
160
- Serial.println (localTime-> tm_wday );
159
+ if (localTime. tm_wday == 0 ) Serial. println ( 7 ) ;
160
+ else Serial.println (localTime. tm_wday );
161
161
}
162
+
163
+
164
+ /*
165
+ // Shorter way of displaying the time
166
+ void showTime(tm localTime) {
167
+ Serial.printf(
168
+ "%04d-%02d-%02d %02d:%02d:%02d, day %d, %s time\n",
169
+ localTime.tm_year + 1900,
170
+ localTime.tm_mon + 1,
171
+ localTime.tm_mday,
172
+ localTime.tm_hour,
173
+ localTime.tm_min,
174
+ localTime.tm_sec,
175
+ (localTime.tm_wday > 0 ? localTime.tm_wday : 7 ),
176
+ (localTime.tm_isdst == 1 ? "summer" : "standard")
177
+ );
178
+ }
179
+
180
+ */
0 commit comments