Setup RTC time using unix timestamp

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I'm attempting to set the current time of my RTC by sending a Unix timestamp from a smartphone to the device. I am successfully able to get the timestamp from my smartphone to the ble device. 

   

If I try to just hardcode something to test like this: 

   

uint64_t out = 1475591308;
RTC_SetUnixTime(out);

   

My RTC clock goes to 1/11/2372 ??  Am I not implementing this right? The method signature in the RTC.h is: 

   

RTC_SetUnixTime(uint64 unixTime);

   

And the docs say: 

   
    

Sets the time in the Unix/Epoch time format - the number of seconds elapsed from January 1, 1970 UTC 00:00 hrs. 

   
   

===

   

Update: I've changed nothing and now when setting the unix time it freezes....story of my life. 

   

I'm trying to call RTC_SetUnixTime in my BleCallBack method if that helps at all. 

0 Likes
1 Solution
Anonymous
Not applicable

So I was able to fix this by adding in a couple of variables and updating the RTC from the main method instead of my BleCallBack method. So in my main now I have: 

   

if (!clockIsUpToDate) {
      RTC_SetUnixTime(newClockValue);
      clockIsUpToDate = 1;
}

   

I think my issue with this is not fully understanding the c run loop. 

View solution in original post

0 Likes
1 Reply
Anonymous
Not applicable

So I was able to fix this by adding in a couple of variables and updating the RTC from the main method instead of my BleCallBack method. So in my main now I have: 

   

if (!clockIsUpToDate) {
      RTC_SetUnixTime(newClockValue);
      clockIsUpToDate = 1;
}

   

I think my issue with this is not fully understanding the c run loop. 

0 Likes