RTClib error using unixtime() in calculation

Please help! I’m trying to use RTClib to time stamp then extract unixtime to make calculation for duration of time.

I’m getting errors below and new to class/objects. I’m using the same unixtime call in previous function to print timeStampIn and timeStampOut to Serial monitor and it works no problem. (Line 306 and 315)
Errors below
PhoneTimer:331:71: error: request for member ‘unixtime’ in ‘timeStampIn*’, which is of non-class type ‘uint32_t {aka long unsigned int}’
PhoneTimer:338:42: error: request for member ‘unixtime’ in 'timeStampOut’, which is of non-class type ‘uint32_t {aka long unsigned int}’
PhoneTimer:338:70: error: request for member ‘unixtime’ in 'timeStampIn’, which is of non-class type ‘uint32_t {aka long unsigned int}’
_PhoneTimer.ino (15 KB)*_

Welcome,

"now" is a DateTime object (an object of class DateTime), it has a member function unixtime() to convert from a DateTime to a uint32_t number representing the DateTime in seconds since 1970.

timeStampIn and timeStampOut are not arrays of DateTime objects, they are arrays of uint32_t, so it doesn't have a unixtime() member function, and you don't need it anyway since what you want to do is to store uint32_t timestamps in there, not DateTime.

So

DateTime timeStampIn[i] = RTC.now(); //record time phone placed in cradle

should be

timeStampIn[i] = RTC.now().unixtime(); //record time phone placed in cradle

Etc..

By the way, timeOn and timeOnRemove should be unsigned long as well, not unsigned ints :slight_smile:

THANK YOU SO MUCH!!

It compiled...yeah.

Just to clarify the variable type for timeOn and timeOnLast.

Since the value is reset to zero at beginning of every day the value will never be larger than 60. At least that is the plan. Since unsigned int is good to 65,535 I didn't think I would need the long type.

Thanks again

Oh, if you are sure it will never be greater than 60 and less than 0 then the correct data type is uint8_t :slight_smile: