21 #include "../../include/esp3d_config.h"
22 #ifdef TIMESTAMP_FEATURE
25 #include "../../core/settings_esp3d.h"
26 #include "../../core/esp3doutput.h"
27 #if defined (WIFI_FEATURE)
28 #include "../wifi/wificonfig.h"
30 #if defined (BLUETOOTH_FEATURE)
31 #include "../bluetooth/BT_service.h"
32 #endif //BLUETOOTH_FEATURE
33 #if defined (ETH_FEATURE)
34 #include "../ethernet/ethconfig.h"
42 _is_internet_time =
false;
51 if (readfromsettings) {
54 return _is_internet_time;
64 #if defined (WIFI_FEATURE)
66 if (WiFi.getMode() == WIFI_AP) {
70 #if defined (BLUETOOTH_FEATURE)
75 #endif //BLUETOOTH_FEATURE
77 #if defined (ETH_FEATURE)
79 #if defined (WIFI_FEATURE)
81 if (WiFi.getMode() == WIFI_OFF) {
98 configTime (3600 * (t1), d1 * 3600, s1.c_str(), s2.c_str(), s3.c_str() );
99 time_t now = time(
nullptr);
101 while ((now < (8 * 3600 * 2)) && (nb < 20)) {
107 if (now < (8 * 3600 * 2)) {
126 localtime_r(&now, &tmstruct);
135 localtime_r(&t, &tmstruct);
137 stmp = String((tmstruct.tm_year)+1900) +
"-";
138 if (((tmstruct.tm_mon)+1) < 10) {
141 stmp += String(( tmstruct.tm_mon)+1) +
"-";
142 if (tmstruct.tm_mday < 10) {
145 stmp += String(tmstruct.tm_mday) +
" ";
146 if (tmstruct.tm_hour < 10) {
149 stmp += String(tmstruct.tm_hour) +
":";
150 if (tmstruct.tm_min < 10) {
153 stmp += String(tmstruct.tm_min) +
":";
154 if (tmstruct.tm_sec < 10) {
157 stmp += String(tmstruct.tm_sec);
166 struct timeval time_val = {0, 0};
169 stmp.replace(
"#",
"-");
170 stmp.replace(
":",
"-");
172 int pos = stmp.indexOf(
"-");
176 substmp = stmp.substring(0,pos);
177 if (substmp.length()!=4) {
181 tmstruct.tm_year = substmp.toInt() - 1900;
183 pos = stmp.indexOf(
"-",pos2+1);
187 substmp = stmp.substring(pos2+1,pos);
188 if ((substmp.toInt() > 11) || (substmp.toInt() <0 )) {
192 tmstruct.tm_mon = substmp.toInt() - 1;
194 pos = stmp.indexOf(
"-",pos2+1);
198 substmp = stmp.substring(pos2+1,pos);
199 if ((substmp.toInt() > 31) || (substmp.toInt() <1 )) {
203 tmstruct.tm_mday = substmp.toInt();
206 pos = stmp.indexOf(
"-", pos2+1);
210 substmp = stmp.substring(pos2+1,pos);
211 if ((substmp.toInt() > 23) || (substmp.toInt() <0 )) {
216 tmstruct.tm_hour = substmp.toInt();
219 pos = stmp.indexOf(
"-", pos2+1);
223 substmp = stmp.substring(pos2+1,pos);
224 if ((substmp.toInt() > 59) || (substmp.toInt() < 0 )) {
227 tmstruct.tm_min = substmp.toInt();
229 substmp = stmp.substring(pos+1);
230 if ((substmp.toInt() > 59) || (substmp.toInt() < 0 )) {
233 tmstruct.tm_isdst = 0;
235 configTime (0, 0,
"",
"",
"");
236 tmstruct.tm_sec = substmp.toInt();
237 time_val.tv_sec = mktime (&tmstruct);
238 if(settimeofday(&time_val,0) == -1) {
253 _is_internet_time =
false;
263 #endif //TimeServer_DEVICE