sqfmi / Watchy

Watchy - An Open Source E-Ink Smartwatch
http://www.sqfmi.com
MIT License
1.83k stars 319 forks source link

Getting the Unix Timestamp / Epoch? #236

Closed edent closed 1 year ago

edent commented 1 year ago

My Watchy has synced with NTP and is displaying the correct time. Is there any way I can retrieve the Unix Timestamp from the device?

I've tried:

struct timeval tv;
time_t curtime;
gettimeofday(&tv, NULL); 
curtime=tv.tv_sec;
display.println(curtime);

But that just displays 1 - and thereafter the seconds since the watch rebooted.

Someone on Discord suggested using RTC.rtc_ds.get() but that just displays 0.

I can't see anything useful in currentTime.

Is it possible to get the current Unix timestamp?

edent commented 1 year ago

For those looking for the answer:

RTC.read(currentTime);
time_t epoch = makeTime(currentTime);

That gets you the number of seconds since the Unix Epoch.