32#include "../SensorBuildOpt.h"
33#if !SENSORLIB_EXCLUDE_RTC
41#if defined(ARDUINO_ARCH_ESP32) || defined(CONFIG_IDF_TARGET)
93 bool begin(TwoWire &wire,
int sda,
int scl)
126 memset(&tm_time, 0,
sizeof(
struct tm));
127 tm_time.tm_year = datetime.
getYear() - 1900;
128 tm_time.tm_mon = datetime.
getMonth() - 1;
129 tm_time.tm_mday = datetime.
getDay();
130 tm_time.tm_hour = datetime.
getHour();
134 time_t epoch_seconds = mktime(&tm_time);
135 if (epoch_seconds == (time_t) -1) {
139 ts.tv_sec = epoch_seconds;
141 if (clock_settime(CLOCK_REALTIME, &ts) == -1) {
156 time_t t = time(NULL);
157 struct tm *local_tm = localtime(&t);
158 return RTC_DateTime(local_tm->tm_year + 1900, local_tm->tm_mon + 1, local_tm->tm_mday,
159 local_tm->tm_hour, local_tm->tm_min, local_tm->tm_sec, local_tm->tm_wday);
#define SENSORLIB_LOG_E(...)
uint8_t getMinute() const
uint8_t getSecond() const
bool(*)(uint8_t addr, uint8_t reg, uint8_t *buf, size_t len, bool writeReg, bool isWrite) CustomCallback
virtual const char * getChipName()=0
Get the name of the RTC chip.
virtual void setDateTime(RTC_DateTime datetime)=0
Set the date and time of the RTC using an RTC_DateTime object.
virtual bool begin(SensorCommCustom::CustomCallback callback)=0
Initialize the RTC device using a custom callback.
virtual RTC_DateTime getDateTime()=0
Get the current date and time from the RTC.