@@ -133,21 +133,57 @@ int _gettimeofday_r(struct _reent* unused, struct timeval *tp, void *tzp)
133
133
134
134
void configTime (int timezone_sec, int daylightOffset_sec, const char * server1, const char * server2, const char * server3)
135
135
{
136
- char tzstr [64 ];
137
-
138
136
// There is no way to tell when DST starts or stop with this API
139
137
// So DST is always integrated in TZ
140
138
// The other API should be preferred
141
139
140
+ /* ** portable version using posix API
141
+ (calls sprintf here, then sscanf internally)
142
+
142
143
int tzs = daylightOffset_sec + timezone_sec;
143
144
int tzh = tzs / 3600;
144
145
tzs -= tzh * 3600;
145
146
int tzm = tzs / 60;
146
147
tzs -= tzm * 60;
147
148
148
149
// man tzset:
150
+ char tzstr [64];
149
151
snprintf(tzstr, sizeof tzstr, "ESPUSER<%+d:%02d:%02d>", tzh, tzm, tzs);
150
152
return configTime(tzstr, server1, server2, server3);
153
+
154
+ Replaced by light code found from
155
+ newlib inspection and internal structure hacking
156
+ (no sprintf, no sscanf, -7584 flash bytes):
157
+
158
+ ***/
159
+
160
+ static char gmt[] = " GMT" ;
161
+
162
+ _timezone = timezone_sec + daylightOffset_sec;
163
+ _daylight = 0 ;
164
+ _tzname[0 ] = gmt;
165
+ _tzname[1 ] = gmt;
166
+ auto tz = __gettzinfo ();
167
+ tz->__tznorth = 1 ;
168
+ tz->__tzyear = 0 ;
169
+ for (int i = 0 ; i < 2 ; i++)
170
+ {
171
+ auto tzr = &tz->__tzrule [i];
172
+ tzr->ch = 74 ;
173
+ tzr->m = 0 ;
174
+ tzr->n = 0 ;
175
+ tzr->d = 0 ;
176
+ tzr->s = 0 ;
177
+ tzr->change = 0 ;
178
+ tzr->offset = _timezone;
179
+ }
180
+
181
+ // sntp servers
182
+ setServer (0 , server1);
183
+ setServer (1 , server2);
184
+ setServer (2 , server3);
185
+
186
+ /* ** end of posix replacement ***/
151
187
}
152
188
153
189
void configTime (const char * tz, const char * server1, const char * server2, const char * server3)
0 commit comments