Set RTC with epoch time

Everything about programming the platform and using the Waspmote API
Post Reply
predivine1
Posts: 13
Joined: Sat Jul 11, 2015 5:11 pm

Set RTC with epoch time

Post by predivine1 » Sun Jul 26, 2015 6:52 pm

Hi,

I was wondering if there is a way to set the time of the RTC using an epoch timestamp, e.g, something like

Code: Select all

 
long epoch = 1437928549;
RTC.setTime(epoch);

predivine1
Posts: 13
Joined: Sat Jul 11, 2015 5:11 pm

Re: Set RTC with epoch time

Post by predivine1 » Sun Jul 26, 2015 7:45 pm

Never mind, I found the way to do it, apparently I overlooked some methods in the newest API, for anyone interested here it is:

Code: Select all

unsigned long epoch = 1437928487;
timestamp_t time;
RTC.breakTimeAbsolute(epoch, &time);
RTC.setTime(time.year, time.month, time.date,time.day, time.hour, time.minute,time.second);
The only problem I have found with this solution is that it uses UTC, which brings me to tmy next question, looking at the API there is a method RTC.setGMT() but this _gmt is not used anywhere in the code to correct the time, at least from what I can see. Will this functionality be enabled sometime soon?

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Set RTC with epoch time

Post by libelium-dev » Mon Jul 27, 2015 9:38 am

Hello,

take a look to this example, you will see how to use the functions related to the management of Time and Date as Unix/Epoch time.
http://www.libelium.com/development/was ... poch-time/

Regarding the GMT functions, all of them are implemented in the API so you can use them, but there is not an example about it.

Regards.

predivine1
Posts: 13
Joined: Sat Jul 11, 2015 5:11 pm

Re: Set RTC with epoch time

Post by predivine1 » Mon Aug 17, 2015 12:59 pm

Maybe I should have explained better, the epoch is given for GMT, I want a way in which I can set the time with the epoch e.g:

Code: Select all

unsigned long epoch = 1437928487; /*Sun, 26 Jul 2015 16:34:47 GMT*/
timestamp_t time;
RTC.breakTimeAbsolute(epoch, &time);
RTC.setTime(time.year, time.month, time.date,time.day, time.hour, time.minute,time.second);
But I also want to set the GMT variable such that if GMT is 0 the time will be 16:34:47 but if GMT is +2 then the time is 18:34:47 and if it is -3 the time will be 13:34:47. Is this the functionality that you where talking about? if it is please provide me with the place where those methods are implemented as I dont see them in the code nor the documentation.

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Set RTC with epoch time

Post by libelium-dev » Tue Aug 18, 2015 8:53 am

Hello,

this functionality is not implemented, we will have it in mind for future improvements. Anyway you have RTC registers, if you save _gmt register you can calculate it.

Regards.

eric_poc
Posts: 10
Joined: Wed Jul 19, 2017 5:07 pm
Company: Ericsson Canada

Re: Set RTC with epoch time

Post by eric_poc » Tue Sep 19, 2017 5:56 pm

Does the setGMT() work now? Thanks

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Set RTC with epoch time

Post by libelium-dev » Wed Sep 20, 2017 9:10 am

Hi,

We are sorry but GMT isn't used. You can set GMT with setGMT(gmt) function and you can read it with getGMT() but GMT isn't used in any other part of the library.

Regards

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest