Page 1 of 1

Timestamp

Posted: Mon May 26, 2014 8:32 am
by jsclownfish
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

Re: Timestamp

Posted: Tue May 27, 2014 2:56 am
by tanked_kiwi
I have been looking for something like this also, to track when the last time certain ports were on.

Re: Timestamp

Posted: Tue May 27, 2014 7:09 am
by jsclownfish
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

Re: Timestamp

Posted: Tue May 27, 2014 8:02 am
by rimai
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);