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.
Yes I am using nrf52840dk, thanks for the solution I will do some study
Hello Jay_Lin,
If there is no additional hardware involved then you can not have real world date&time
With the nrf52840dk you can only have "systems tics counter"
You need a modem + sim-card
For example:
https://www.conrad.nl/nl/p/sos-electronic-arduino-mc60gsm-gps-1925472.html?utm_source=google&utm_medium=surfaces&utm_campaign=shopping-feed&utm_content=free-google-shopping-clicks&utm_term=1925472&adcampaign=gshop&tid=14579472676_122103879770_pla-304375124321_pla-1925472&gclid=CjwKCAjwo_KXBhAaEiwA2RZ8hL9boviQGXVCdF7HGNy9fEt0hANdcVzmH7xv0gVGdmEnsR13i1ODPRoC29EQAvD_BwE
Can you please mark my answer as solution, thanks! ;-)
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
iam using nrf52833dk..can i sync the data and time while connecting with bluetooth.
while connecting with central,it should sync the time and date of central.can we do this?