<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nRF Connect SDK: How to get the system timestamp(epoch time) on nRf52840dk</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/67906/nrf-connect-sdk-how-to-get-the-system-timestamp-epoch-time-on-nrf52840dk</link><description>Hi nRF support team, 
 In my application, I need to show system date and time, so I am trying to get the system epoch time by using the nRF Connect SDK on nRF52840 dev kit. 
 Can you please let me know, what needs to configure to get the system epoch</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 04 Jan 2025 22:39:46 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/67906/nrf-connect-sdk-how-to-get-the-system-timestamp-epoch-time-on-nrf52840dk" /><item><title>RE: nRF Connect SDK: How to get the system timestamp(epoch time) on nRf52840dk</title><link>https://devzone.nordicsemi.com/thread/516873?ContentTypeID=1</link><pubDate>Sat, 04 Jan 2025 22:39:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:693c274c-2598-48f5-a951-c4fed79dfd22</guid><dc:creator>maxx44</dc:creator><description>&lt;p&gt;&lt;span&gt;Wow!&amp;nbsp; This was a&amp;nbsp;&lt;/span&gt;&lt;b&gt;LONG&lt;/b&gt;&lt;span&gt;&amp;nbsp;time ago and done for some contract work under NDA.&amp;nbsp; So I can&amp;#39;t give a full working example of the&amp;nbsp;nRF52 code.&amp;nbsp; This was for a custom board with a nRF52832 module with a&amp;nbsp;lot of code you&amp;nbsp;wouldn&amp;#39;t want to wallow through.&amp;nbsp; I can&amp;#39;t say I even recall all the details to provide helpful hints.&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;The code examples at the Nordic Playground aren&amp;#39;t enough?&amp;nbsp; All I did was integrate that code into my project (I used SES) as described in this post.&amp;nbsp; The project involved setting the date and time in the nRF52832 RTC, then reading it and providing a timestamp on sensor data written into an external EEPROM.&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;According to my notes, what I did was based on the SDK Blinky example into&amp;nbsp;which&amp;nbsp;I merged NRF_CLI and NRF_CLI_BLE_UART as well&amp;nbsp;as the Nordic Playground calendar routines.&amp;nbsp; This gave a path to connect to an external internet connected device and send a command to set date and time.&amp;nbsp; Initial debugging of the CLI was done with a hardwired serial to USB cable to send the date and time from a PC.&amp;nbsp; TeraTerm on the PC could then connect to the serial port and set date and time as well as read it.&amp;nbsp; TeraTerm had a macro language which allowed you to read time from the system which then could be transmitted to the nRF52832 with a CLI command to set the time and date.&amp;nbsp; I vaguely&amp;nbsp;recall using an app on a tablet called Serial BLE Terminal to test the CLI command over BLE.&amp;nbsp; I think I just entered the command manually&amp;nbsp;with some date and time data.&amp;nbsp; Eventually&amp;nbsp;an app would be written&amp;nbsp;to use this interface with the internet time.&amp;nbsp; This was somebody else&amp;#39;s&amp;nbsp;responsibility.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;I&amp;#39;m not sure this is the sort of interface you&amp;#39;re looking for.&amp;nbsp; I could probably dredge&amp;nbsp;up copies of the CLI commands to set and read time.&amp;nbsp; I&amp;#39;m not sure this will tell&amp;nbsp;you much more than outlined above.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Regards,&lt;/div&gt;
&lt;div&gt;Max&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF Connect SDK: How to get the system timestamp(epoch time) on nRf52840dk</title><link>https://devzone.nordicsemi.com/thread/516775?ContentTypeID=1</link><pubDate>Fri, 03 Jan 2025 10:34:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a03733f0-0b16-4d94-a7e6-48ea491d5035</guid><dc:creator>lara</dc:creator><description>&lt;p&gt;can you share the working sample sir?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF Connect SDK: How to get the system timestamp(epoch time) on nRf52840dk</title><link>https://devzone.nordicsemi.com/thread/281175?ContentTypeID=1</link><pubDate>Fri, 20 Nov 2020 17:56:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fae65446-46d8-4855-b2e4-9b48e4c74e29</guid><dc:creator>Kalyan Agepati</dc:creator><description>&lt;p&gt;Hi Max,&lt;/p&gt;
&lt;p&gt;Thanks for the response.&lt;/p&gt;
&lt;p&gt;I have tried Zephyr kernel timers (based on the 32k RTC) and it is working as expected and I am receiving timer event handler and able to set the RTC timer or counter. &lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Kalyan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF Connect SDK: How to get the system timestamp(epoch time) on nRf52840dk</title><link>https://devzone.nordicsemi.com/thread/280480?ContentTypeID=1</link><pubDate>Tue, 17 Nov 2020 23:49:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1e0427cb-9158-4627-b231-f95564ba3e53</guid><dc:creator>maxx44</dc:creator><description>&lt;p&gt;Kalyan,&lt;/p&gt;
&lt;p&gt;It&amp;#39;s been a while since I worked with this, and it was with the nRF5 SDK environment.&amp;nbsp; I basically followed the example from NordicPlayground/nrf5-calendar-example.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/NordicPlayground/nrf5-calendar-example"&gt;https://github.com/NordicPlayground/nrf5-calendar-example&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I added the nrf_calendar.c and associated nrf_calendar.h to a SDK ble_peripheral example based project.&amp;nbsp; The NordicPlayground has a good example of how to set up the RTC and set and get time.&amp;nbsp; If you have a tm structure with the epoch time, it should be easy enough to set the RTC following the nrf_calendar example.&amp;nbsp; I didn&amp;#39;t do much else than use the functions detailed in the NordicPlayground code.&lt;/p&gt;
&lt;p&gt;I was then able to use the RTC maintained time for timestamps data-logging sensor data.&lt;/p&gt;
&lt;p&gt;Max&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF Connect SDK: How to get the system timestamp(epoch time) on nRf52840dk</title><link>https://devzone.nordicsemi.com/thread/279999?ContentTypeID=1</link><pubDate>Sat, 14 Nov 2020 09:07:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8840766b-2987-4ac4-816e-352896a0bca7</guid><dc:creator>Kalyan Agepati</dc:creator><description>&lt;p&gt;Hi Max,&lt;br /&gt;&lt;br /&gt;Thanks for the quick response.&lt;br /&gt;As you suggested, I can get the epoch time from the BLE GATT attribute externally set by mobile app.&lt;br /&gt;&lt;br /&gt;As you know nrf52840 did not have RTC hardware, once I obtain the epoch time from the mobile app I have to set this value in RTC timer.&amp;nbsp; RTC timer or API&amp;#39;s I did not found in the Zephyr or nRF connect SDK. Can you please share is there any sample code or reference links which can direct me to set the epoch time in RTC timer or counter?&lt;br /&gt;&lt;br /&gt;FYI, only gmtime() functions are avilable in zephyr timer.h.&lt;br /&gt;/*&lt;br /&gt;&amp;nbsp;* Conversion between civil time and UNIX time.&amp;nbsp; The companion&lt;br /&gt;&amp;nbsp;* localtime() and inverse mktime() are not provided here since they&lt;br /&gt;&amp;nbsp;* require access to time zone information.&lt;br /&gt;&amp;nbsp;*/&lt;br /&gt;struct tm *gmtime(const time_t *timep);&lt;br /&gt;struct tm *gmtime_r(const time_t *_MLIBC_RESTRICT timep,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct tm *_MLIBC_RESTRICT result);&lt;br /&gt;&lt;br /&gt;Thanks in advance.&lt;br /&gt;Regards,&lt;br /&gt;Kalyan&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF Connect SDK: How to get the system timestamp(epoch time) on nRf52840dk</title><link>https://devzone.nordicsemi.com/thread/279996?ContentTypeID=1</link><pubDate>Sat, 14 Nov 2020 03:22:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d8c285df-4e20-4e8a-8d94-9aee796d5fea</guid><dc:creator>maxx44</dc:creator><description>&lt;p&gt;Kalyan,&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;It seems you didn&amp;#39;t understand our responses.&amp;nbsp; The epoch time does NOT come from Zephyr or the nRF modules, nor is it available there without setting it from an external connection.&amp;nbsp; You need to obtain epoch time from an external device connected to and synced to the internet time servers. Methods to do that are via a custom download or using BLE Current Time Service.&amp;nbsp; The nRF52 SDK has an example of CTS&amp;nbsp; at &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/ble_sdk_app_cts_c.html?cp=7_1_4_2_2_7"&gt;https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/ble_sdk_app_cts_c.html?cp=7_1_4_2_2_7&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Once you obtain the epoch time, you can set an RTC to maintain epoch time and use it in your application with the standard C/C++ time.h library.&lt;br /&gt;&lt;br /&gt;Hope this helps.&amp;nbsp; Sorry, no plug and play solution.&lt;br /&gt;&lt;br /&gt;Regards,&amp;nbsp; Max&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF Connect SDK: How to get the system timestamp(epoch time) on nRf52840dk</title><link>https://devzone.nordicsemi.com/thread/279981?ContentTypeID=1</link><pubDate>Fri, 13 Nov 2020 21:12:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7c60af11-ee97-462c-a930-0c1deb84493b</guid><dc:creator>Kalyan Agepati</dc:creator><description>&lt;p&gt;Hi Edvin, Maxx44,&lt;/p&gt;
&lt;p&gt;Thanks for the clarification.&lt;/p&gt;
&lt;p&gt;Can you please share the working sample code to get system epoch time from Zephyr or nRF connect sdk.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Kalyan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF Connect SDK: How to get the system timestamp(epoch time) on nRf52840dk</title><link>https://devzone.nordicsemi.com/thread/278284?ContentTypeID=1</link><pubDate>Tue, 03 Nov 2020 13:47:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:46b59cde-27bb-48e6-a339-0c0591a10bfd</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;I agree with &lt;a href="https://devzone.nordicsemi.com/members/maxx44"&gt;maxx44&lt;/a&gt; on this one. You can use something like the RTS (Real time service) to fetch the current time, and then use the RTC (real time counter), which is not the same as a Real Time Clock. Whenever the nRF is not running, it does not keep track of time. That would require that the RTC is running, which it is not when it is powered off. Basically, whenever the application is starting from scratch, the nRF has no way of knowing what time it is before checking with a device that either is connected to the internet, or that has an &lt;a href="https://en.wikipedia.org/wiki/Real-time_clock"&gt;RTC&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF Connect SDK: How to get the system timestamp(epoch time) on nRf52840dk</title><link>https://devzone.nordicsemi.com/thread/278176?ContentTypeID=1</link><pubDate>Tue, 03 Nov 2020 02:18:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:562bd8b5-51c8-413a-ba0c-10d3b9b8b5c9</guid><dc:creator>maxx44</dc:creator><description>&lt;p&gt;Kalyan,&lt;/p&gt;
&lt;p&gt;You might want to look at&amp;nbsp;&lt;a href="https://github.com/NordicPlayground/nrf5-calendar-example"&gt;https://github.com/NordicPlayground/nrf5-calendar-example&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To do this &amp;quot;right&amp;quot; you need to get the time from an internet connected device that accesses the time server(s) and sets the RTC.&amp;nbsp; I&amp;#39;ve downloaded the time from a USB connected terminal (TeraTerm) which has the capability of sending the system time to the UART connection via running a simple macro.&amp;nbsp; Not sure something like this works for you, but once you set the time the RTC will maintain it fairly effectively (as long as power is on).&amp;nbsp; I&amp;#39;ve also downloaded system time from a BLE connected Android tablet, but that used a custom BLE service to send time from the tablet.&lt;/p&gt;
&lt;p&gt;Note there&amp;#39;s a transmission delay setting the time this way, so it will be slightly off but not by much.&lt;/p&gt;
&lt;p&gt;Max (online user, not a Nordic support person)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>