How to extract the current time from the calendar_example, i am not clear with the procedure
How to extract the current time from the calendar_example, i am not clear with the procedure
Hi
You would use the nrf_cal_get_time(void) function for this.
It returns a pointer to a tm struct which contains the current time in seconds, minutes, hours and so on.
You can also use the nrf_cal_get_time_string(bool calibrated) function if you just want a string representation of the current time.
Best regards
Torbjørn
Hi,
nrf_log module doesnt work now.. I am working on it, mean while can you please check this out..
this was the output when i used int datatype
EDIT : I am getting the same result using the character array pointer as well
below is the code i used for character array
char k[16]; for(int i = 0; i < sizeof(nrf_cal_get_time_string(true)); i++) { k[i] = nrf_cal_get_time_string(true)[i]; } err_code = ble_nus_data_send(&m_nus, k, &lendt, m_conn_handle);
Hi
Good to hear you got it working
codebreaker176 said:I had another question, so does this time change real time? or does it remain constant?
The time is supposed to be updated every second, yes.
Is this not happening for you?
In the example I sent you can try to request several updates, and you should see the time increase.
Best regards
Torbjørn
Hi,
Yess it works, thanks a lot, Grateful for your help!!
That's good to hear, glad I could help
Hello again,
I proabably misread the output,
but now i checked, the time does not get updated at all , it remains constant, can you please help
Hi
You have to call nrf_cal_init() to initialize the calendar library.
Otherwise it won't work.
Best regards
Torbjørn
Hi
You have to call nrf_cal_init() to initialize the calendar library.
Otherwise it won't work.
Best regards
Torbjørn
Yes works now, I missed that part
Thanks a lot for your support!
Hi Tobjorn,
Is it possible to reproduce your code to use it for the nrf9160 device. I need a close application to this but with nrf9160 and could not find any examples for this calendar mode type application. Any help for this would be great .
Hi Adeel
Anything is possible, but I am not sure how much sense it makes to adapt the calendar example when the date_time library is available in NCS/Zephyr.
I modified the example I shared earlier to set up a standard Zephyr timer, and use that to update the timestamp in a fashion similar to the calendar example.
The difference is that it uses the date_time library to get the time initially, and then defaults to using a timer afterwards to reduce the need of calling date_time repeatedly.
Please have a look at the updated example and see if it gets you closer to what you need:
https://github.com/too1/mqtt_w_date_time
Best regards
Torbjørn
Hi Tobjorn,
Thanks, this is a perfect example to work on now.
I just had to ask a question which was related to time synchronization.
I see that the real time differs by 2 hrs : 14:13 to 16:13 . Just wanted to know if this could be fixed by tinkering with the values. This would be the perfect time stamp for my usage :).
Regards,
Adeel.
sorry , I meant 16:12 to 18:12. I see a gap of 2 hrs. Just needed a heads up on how to calibrate it :).