Timestamp

Do you have a question on how to do something.
Ask in here.
Post Reply
User avatar
jsclownfish
Posts: 378
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Timestamp

Post 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
tanked_kiwi
Posts: 37
Joined: Thu May 22, 2014 3:25 am

Re: Timestamp

Post by tanked_kiwi »

I have been looking for something like this also, to track when the last time certain ports were on.
User avatar
jsclownfish
Posts: 378
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Timestamp

Post 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
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Timestamp

Post 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);
Roberto.
Post Reply