Skip to content

Commit a6cca2c

Browse files
committed
import getLocalTime() from esp32/Arduino
follows esp8266#8407
1 parent f401f08 commit a6cca2c

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

Diff for: cores/esp8266/Arduino.h

+2
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ inline void configTzTime(const char* tz, const char* server1,
279279
configTime(tz, server1, server2, server3);
280280
}
281281

282+
bool getLocalTime(struct tm * info, uint32_t ms = 5000);
283+
282284
// Everything we expect to be implicitly loaded for the sketch
283285
#include <pgmspace.h>
284286

Diff for: cores/esp8266/timehelper.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
#include "Arduino.h"
3+
4+
// https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-time.c
5+
6+
bool getLocalTime(struct tm * info, uint32_t ms)
7+
{
8+
uint32_t start = millis();
9+
time_t now;
10+
while((millis()-start) <= ms) {
11+
time(&now);
12+
localtime_r(&now, info);
13+
if(info->tm_year > (2016 - 1900)){
14+
return true;
15+
}
16+
delay(10);
17+
}
18+
return false;
19+
}

Diff for: libraries/LittleFS/examples/LittleFS_Timestamp/LittleFS_Timestamp.ino

-23
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,6 @@ long timezone = 2;
1919
byte daysavetime = 1;
2020

2121

22-
bool getLocalTime(struct tm * info, uint32_t ms) {
23-
uint32_t count = ms / 10;
24-
time_t now;
25-
26-
time(&now);
27-
localtime_r(&now, info);
28-
29-
if (info->tm_year > (2016 - 1900)) {
30-
return true;
31-
}
32-
33-
while (count--) {
34-
delay(10);
35-
time(&now);
36-
localtime_r(&now, info);
37-
if (info->tm_year > (2016 - 1900)) {
38-
return true;
39-
}
40-
}
41-
return false;
42-
}
43-
44-
4522
void listDir(const char * dirname) {
4623
Serial.printf("Listing directory: %s\n", dirname);
4724

Diff for: tests/host/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ CORE_CPP_FILES := \
9797
HardwareSerial.cpp \
9898
crc32.cpp \
9999
Updater.cpp \
100+
timehelper.cpp \
100101
) \
101102
$(addprefix $(abspath $(LIBRARIES_PATH)/ESP8266SdFat/src)/, \
102103
FatLib/FatFile.cpp \

0 commit comments

Comments
 (0)