Get System Time
응답
15. 7. 17 오후 12:41
Hello,
is it possible to get the current time?
I already tried some variations, but I always get the following error:

c:/xdk-workbench/armgcc/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/armv7-m\libc.a(lib_a-gettimeofdayr.o): In function `_gettimeofday_r':
gettimeofdayr.c:(.text._gettimeofday_r+0xe): undefined reference to `_gettimeofday'

Thank You!

0 (0 투표)
Get System Time
응답
15. 7. 17 오후 2:19 as a reply to Miguel Silveira.
Hi miguelsilveira,

this question was aked before in the following thread:
https://xdk.bosch-connectivity.com/xdk-community/category/linking-libc/28121-t/28120#id28120

Regards,
Manuel
0 (0 투표)
RE: Get System Time
응답
16. 6. 15 오전 6:48 as a reply to Manuel Cerny.

Hi,

I stumbled upon a similar problem when trying to run the XDK-Monitor Demo but unfortunately the link you posted doesn't lead to any thread. The statement I try to ouput is:

printf("{[MONITOR]%s(%llu):l=%d%s}\n\r",
		"MAX44009",
		OS_timeGetSystemTimeMs(),
		(unsigned int) milliLuxData,
		"milliLux");

When compiling, the IDE says that the function to get the system time can't be found. Is there a header file I need to include?

Felix

 

0 (0 투표)
RE: Get System Time
응답
16. 6. 15 오전 11:36 as a reply to Felix Gandha Salentin.

Hello Felix,

unfortunately the user guide isn't updated to the latest workbench version. But we are working on it.
This code snippet should work:

printf("{[MONITOR]%s(%ld):l=%ud%s} \n\r",
    "MAX44009",
    xTaskGetTickCount(),
    (unsigned int) milliLuxData,
    "milliLux");

Due to the latest workbench version 1.5.2 OS_timeGetSystemTimeMs() is deprecated now, xTaskGetTickCount() is the new function to acquire the system time.
Please keep in mind, that the string format parameters like ld or ud have to match the of the streamed sensordata.

Kind regards,
Franjo

0 (0 투표)
RE: Get System Time
응답
16. 8. 3 오후 1:11 as a reply to Franjo Stjepandic.

Hi,

I have a similar issue but I'm not looking for the system time. I'm looking for the current time. Is that possible? Has XDK any real time clock?

Thanks

 

0 (0 투표)
RE: Get System Time
응답
16. 8. 3 오후 2:15 as a reply to Lidia Cerqueira.

Hello Lidia,

it seems that the link that I posted in here has changed.

In short, real time on a microcontroller needs this to be supported by the hardware. The XDK does not support a real time clock (RTC).
This is common on most of the microcontrollers. They have a built-in timekeeper that tracks the current system time.
This time is set to 0, when turning on the microcontroller. 

If it is required to have the current time, you need to make use of the network time protocol (NTP) and read the current time from a NTP service.

Kind regards,
Manuel

+1 (1 투표)
RE: Get System Time
응답
16. 8. 3 오후 2:43 as a reply to Manuel Cerny.

Thanks for your help Manuel.

Is there anything implemented for xdk or I would have to start from scratch?

Thanks

 

0 (0 투표)
RE: Get System Time
응답
16. 8. 3 오후 3:14 as a reply to Lidia Cerqueira.

Hello Lidia,

currently there is no NTP example. NPT is based on UDP though and there is an example available for UDP. You can find it under SendDataOverUdp on the welcome screen of the workbench.

What you have to do is implement the NTP from scratch and call the UDP functions from there. You can find further information by looking into NTP for Arduino. Arduino has no RTC either but there are many NTP client implementation examples available. These should be adaptable for the XDK.

I hope this was helpful.

Kind regards,
Manuel

+1 (1 투표)
RE: Get System Time
응답
16. 8. 3 오후 3:19 as a reply to Manuel Cerny.

It was, Thanks a lot!

Kind regards,

Lídia

0 (0 투표)
RE: Get System Time
응답
16. 8. 31 오전 8:34 as a reply to Lidia Cerqueira.

Hi Manuel,

I have a doubt that I would like you to clarify. 

Imagine that I get the current time from the NTP server at a given moment (instant A). Later, I would like to know what time it is (instant B). I was thinking about applying the following algorithm:

1) Get the current time from NTP server at instant A

2) Get the system time at instant A with OS_timeGetSystemTimeMs() X

3) Get the system time at instant B with OS_timeGetSystemTimeMs() Y

4) Current time at instant B = Current time at instant A + (Y-X)

Is there any simpler way to do this? 

Also, in which header file can I find OS_timeGetSystemTimeMs()? 

Thanks in advance

0 (0 투표)
RE: Get System Time
응답
16. 9. 1 오후 12:53 as a reply to Lidia Cerqueira.

Hello Lidia,

an algorithm like this is possible, of course. Its advantages are clear. You have the current time available at any moment you like and are not dependent of the request time of the NTP server.

But I would recommend to synchronize the time with the NTP server from time to time to avoid short inconsistencies.

The function OS_timeGetSystemTimeMs() was renamed to xTaskGetTickCount() in the workbench release 1.5.2. You can find the function xTaskGetTickCount() in the interface task.h.

Kind reagards,
Manuel

0 (0 투표)
RE: Get System Time
응답
16. 9. 1 오후 12:41 as a reply to Manuel Cerny.

Thanks Manuel for your feedback regarding the algorithm and for your advise.

 

0 (0 투표)
RE: Get System Time
응답
16. 9. 2 오후 12:48 as a reply to Lidia Cerqueira.

Lidia,

Great to heat that I could help you.
Please don’t hesitate to ask if you have further questions.

Kind reagards,
Manuel

0 (0 투표)