Timestamp

Do you have a question on how to do something.
Ask in here.
User avatar
Posts: 378
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis
PostPosted: Mon May 26, 2014 8:32 am
Hi all,

Occassionally, my RA resets and I have been tryign to track how often it happens and when. I'd like to add something in the setup to timestamp everytime it happens. I think I can use a counter varible to show how many times it has reset ina memory location, but I'd also like to make a timestamp and put it in memory as well. Is there a way to record now() or millis() and deconvulute it to date/time? Or should I store each piece in a different memory location (day, month, year, hour, minute, second)? Seems like there must be a common way to do this.

Thanks,
Jon

Posts: 37
Joined: Thu May 22, 2014 3:25 am
PostPosted: Tue May 27, 2014 2:56 am
I have been looking for something like this also, to track when the last time certain ports were on.
User avatar
Posts: 378
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis
PostPosted: Tue May 27, 2014 7:09 am
I think it can be done by saving all the pieces in seperate memory locations like this.....

Code: Select all
void Timestamp()  //function to play sound and delay before it plays again.
{
  time_t t=now();
  InternalMemory.write(110, day(t));
  InternalMemory.write(111, month(t));
  InternalMemory.write(112, year(t));
  InternalMemory.write(113, hour(t));
  InternalMemory.write(114, minute(t));
  InternalMemory.write(115, second(t));
  //counter
  resets=InternalMemory.read(116);   //last number
  resets++;                                          //add one
  InternalMemory.write(116,resets);   //store new number
  //elapsed time
  InternalMemory.write(117,((now())-(InternalMemory.read(117))));    //elapsed time since a change(not sure if this would work)
}



But I was hoping there was an easier way.
-Jon

Posts: 12507
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Tue May 27, 2014 8:02 am
now() is a unsigned long variable.
I never used it, but you can use like this:
Code: Select all
InternalMemory.write_dword(110,now());

And read like this:
Code: Select all
InternalMemory.read_dword(110);
Roberto.

Return to How do I code ...

Who is online

Users browsing this forum: No registered users and 1 guest

cron