Skip to content

Use the RTC clock if available #2

@randomekek

Description

@randomekek

Not sure how much battery this would actually save, but booting would be a little faster. Something like

void setupTime() {
    auto dt = M5.Rtc.getDateTime();
    if (dt.date.year > 2023) {
        struct tm tm = { dt.time.seconds, dt.time.minutes, dt.time.hours, dt.date.date, dt.date.month - 1, dt.date.year - 1900 };
        time_t t = mktime(&tm);
        struct timeval now = { .tv_sec = t };
        settimeofday(&now, NULL);
    } else {
        configTime(0, 0, "pool.ntp.org"); 
        struct tm tm;
        if (getLocalTime(&tm)) M5.Rtc.setDateTime(tm);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions