So, I am working on nrf52840 with nrf connect sdk and I want to get date and time in my project, I found a library in nrf connect sdk ->libraries->other libraries->date-time, I tried to add the configuration in my prj.conf, but an error occur.
So, I am working on nrf52840 with nrf connect sdk and I want to get date and time in my project, I found a library in nrf connect sdk ->libraries->other libraries->date-time, I tried to add the configuration in my prj.conf, but an error occur.
Hi,
To use the DATE_TIME library with other nRF devices than nRF9160, you need to specify these configurations:
CONFIG_DATE_TIME=y CONFIG_DATE_TIME_MODEM=n CONFIG_DATE_TIME_NTP=n
And then supply the time manually. Here's a small snippet on how to do that:
/* * Copyright (c) 2012-2014 Wind River Systems, Inc. * * SPDX-License-Identifier: Apache-2.0 */ #include <zephyr.h> #include <date_time.h> #include <sys/printk.h> void main(void) { // Set time to 8th of June, 2022, 16:00 // unix timestamp: 1654704000000 struct tm time = { .tm_sec = 00, .tm_min = 00, .tm_hour = 16, .tm_mday = 8, .tm_mon = 6-1, .tm_year = 2022-1900, .tm_wday = 3, }; int err = date_time_set(&time); /* your err handling here */ printk("Hello World! %s\n", CONFIG_BOARD); int64_t unix_timestamp = 0; // Wait 10 seconds to see that the timestamp increments 10 seconds k_sleep(K_SECONDS(10)); err = date_time_now(&unix_timestamp); /* your err handling here */ // Use https://www.epochconverter.com/ to convert to human readable printk("unix timestamp: %lld", unix_timestamp); }
Kind regards,
Håkon
Hi,
To use the DATE_TIME library with other nRF devices than nRF9160, you need to specify these configurations:
CONFIG_DATE_TIME=y CONFIG_DATE_TIME_MODEM=n CONFIG_DATE_TIME_NTP=n
And then supply the time manually. Here's a small snippet on how to do that:
/* * Copyright (c) 2012-2014 Wind River Systems, Inc. * * SPDX-License-Identifier: Apache-2.0 */ #include <zephyr.h> #include <date_time.h> #include <sys/printk.h> void main(void) { // Set time to 8th of June, 2022, 16:00 // unix timestamp: 1654704000000 struct tm time = { .tm_sec = 00, .tm_min = 00, .tm_hour = 16, .tm_mday = 8, .tm_mon = 6-1, .tm_year = 2022-1900, .tm_wday = 3, }; int err = date_time_set(&time); /* your err handling here */ printk("Hello World! %s\n", CONFIG_BOARD); int64_t unix_timestamp = 0; // Wait 10 seconds to see that the timestamp increments 10 seconds k_sleep(K_SECONDS(10)); err = date_time_now(&unix_timestamp); /* your err handling here */ // Use https://www.epochconverter.com/ to convert to human readable printk("unix timestamp: %lld", unix_timestamp); }
Kind regards,
Håkon
Thanks for the reply I am using nrf52840 which can't use Date-time, thanks alot though