Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 4 months ago.
how to store the exact time with the sensor value
Hi
i am reading values from some sensors for my project. what i want to do is to store the sensor value with the time (system time) it is received?
like for example
i get a value of 1 at p6 at 4:00 p.m. etc
is there any way to do that?? in other words how can access my system time or any other time based utility to get the time?
1 Answer
11 years, 4 months ago.
just use time_t sec = time(NULL); char timestr[32]; sec = time(NULL);
strftime(timestr, 32, "%Y/%m/%d-%H:%M:%S", localtime(&sec));
Thank you for your help
But using this approach it gives me the date way back of 1970(the 0 time as they call it ) ? i think i should have to set the time first using the mktime function ?? is it ?
is there no other way in which i do not have to set the time initially ??
posted by 30 Aug 2013If you don't do anything special with it, it will indeed start at zero.
Options: Manually set the time everytime (see also: http://mbed.org/handbook/Time?action=view&revision=11592).
Set the time once and make sure the RTC is always powered.
Use an internet time server or a radio time receiver to set the time automatically.
Use the buildtime to set the time, see: http://mbed.org/questions/1428/__TIME__-not-always-changing-with-a-new-/, downside of course is that it isn't exactly accurate, especially once resetted after a while.
posted by 30 Aug 2013