mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 09:17:46 +01:00
Fix ESP8266 core has a broken settimeofday implementation (#1231)
This commit is contained in:
parent
61bfd347ea
commit
29cfcfaf0f
1 changed files with 12 additions and 1 deletions
|
@ -4,6 +4,7 @@
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
#include "sys/time.h"
|
#include "sys/time.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include "errno.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace time {
|
namespace time {
|
||||||
|
@ -20,8 +21,18 @@ void RealTimeClock::synchronize_epoch_(uint32_t epoch) {
|
||||||
struct timeval timev {
|
struct timeval timev {
|
||||||
.tv_sec = static_cast<time_t>(epoch), .tv_usec = 0,
|
.tv_sec = static_cast<time_t>(epoch), .tv_usec = 0,
|
||||||
};
|
};
|
||||||
|
ESP_LOGVV(TAG, "Got epoch %u", epoch);
|
||||||
timezone tz = {0, 0};
|
timezone tz = {0, 0};
|
||||||
settimeofday(&timev, &tz);
|
int ret = settimeofday(&timev, &tz);
|
||||||
|
if (ret == EINVAL) {
|
||||||
|
// Some ESP8266 frameworks abort when timezone parameter is not NULL
|
||||||
|
// while ESP32 expects it not to be NULL
|
||||||
|
ret = settimeofday(&timev, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret != 0) {
|
||||||
|
ESP_LOGW(TAG, "setimeofday() failed with code %d", ret);
|
||||||
|
}
|
||||||
|
|
||||||
auto time = this->now();
|
auto time = this->now();
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
Loading…
Reference in a new issue