Time.h compile error in the Arduino 1.5.3 - Intel 1.0.4 IDE

Hello,

I'm new to Arduino and I used the forum before to got some great help and I'm turning to it again after doing strenuous searching on other forums and the internet.

My code below is just an empty skeleton which includes the Time.h and DS1307RTC.h files from their respective libraries; I get an error (also shown below) with regards to the Time.h file.

Now I am using a new Arduino IDE that is meant to be compatible for the Arduino-Edison breakout board, and I know this might the wrong place to ask but I have asked the Intel forums as well and I'm looking here since maybe there are others with more experience on the matter.

The error with regards to Time.h seem to be the result from the IDE thinking there are multiple declarations of functions; when from what I understand it's declarations of the specific function (hour() minute(), etc) then the same function being defined for another instance (hour(time_t t) [the hour at time specified]) ... or am I completely understanding this wrong?

Any insight or direction on how to fix the error that is shown below would be greatly appreciated :grinning:

#include<Time.h>
#include<DS1307RTC.h>

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly: 
  
}
In file included from C:\Arduino_Edison_IDE/hardware/tools/edison/sysroots/core2-32-poky-linux/usr/include/sys/types.h:132:0,
                from C:\Arduino_Edison_IDE/hardware/tools/edison/sysroots/core2-32-poky-linux/usr/include/stdlib.h:314,
                from C:\Arduino_Edison_IDE\hardware\arduino\edison\cores\arduino/WString.h:26,
                from C:\Arduino_Edison_IDE\hardware\arduino\edison\cores\arduino/Print.h:26,
                from C:\Arduino_Edison_IDE\hardware\arduino\edison\cores\arduino/Stream.h:26,
                from C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Wire/Wire.h:24,
                from Impulse_Counter_Clock.ino:1:
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:83:22: error: declaration of C function 'int hour(time_t)' conflicts with
int    hour(time_t t);    // the hour for the given time
                      ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:82:9: error: previous declaration 'int hour()' here
int    hour();            // the hour now
        ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:85:30: error: declaration of C function 'int hourFormat12(time_t)' conflicts with
int    hourFormat12(time_t t); // the hour for the given time in 12 hour format
                              ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:84:9: error: previous declaration 'int hourFormat12()' here
int    hourFormat12();    // the hour now in 12 hour format
        ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:87:22: error: declaration of C function 'uint8_t isAM(time_t)' conflicts with
uint8_t isAM(time_t t);    // returns true the given time is AM
                      ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:86:9: error: previous declaration 'uint8_t isAM()' here
uint8_t isAM();            // returns true if time now is AM
        ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:89:22: error: declaration of C function 'uint8_t isPM(time_t)' conflicts with
uint8_t isPM(time_t t);    // returns true the given time is PM
                      ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:88:9: error: previous declaration 'uint8_t isPM()' here
uint8_t isPM();            // returns true if time now is PM
        ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:91:24: error: declaration of C function 'int minute(time_t)' conflicts with
int    minute(time_t t);  // the minute for the given time
                        ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:90:9: error: previous declaration 'int minute()' here
int    minute();          // the minute now
        ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:93:24: error: declaration of C function 'int second(time_t)' conflicts with
int    second(time_t t);  // the second for the given time
                        ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:92:9: error: previous declaration 'int second()' here
int    second();          // the second now
        ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:95:21: error: declaration of C function 'int day(time_t)' conflicts with
int    day(time_t t);    // the day for the given time
                    ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:94:9: error: previous declaration 'int day()' here
int    day();            // the day now
        ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:97:25: error: declaration of C function 'int weekday(time_t)' conflicts with
int    weekday(time_t t); // the weekday for the given time
                        ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:96:9: error: previous declaration 'int weekday()' here
int    weekday();        // the weekday now (Sunday is day 1)
        ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:99:23: error: declaration of C function 'int month(time_t)' conflicts with
int    month(time_t t);  // the month for the given time
                      ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:98:9: error: previous declaration 'int month()' here
int    month();          // the month now  (Jan is month 1)
        ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:101:22: error: declaration of C function 'int year(time_t)' conflicts with
int    year(time_t t);    // the year for the given time
                      ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:100:9: error: previous declaration 'int year()' here
int    year();            // the full four digit year: (2009, 2010 etc)
        ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:105:66: error: declaration of C function 'void setTime(int, int, int, int, int, int)' conflicts with
void    setTime(int hr,int min,int sec,int day, int month, int yr);
                                                                  ^
C:\Arduino_Edison_IDE\hardware\arduino\edison\libraries\Time/time.h:104:9: error: previous declaration 'void setTime(time_t)' here
void    setTime(time_t t);

UPDATE:

If I change the default Time.h file (code below), the change being that I comment out the previous declarations of each function, I get rid of my error. But for some reason, now when I run the ReadTest example (code below) from DS1307RTC library, I get the error:

"DS1307 read error! Please check the circuitry." Which I think is happening due to me messing with Time.h, which DS1307.h is dependent on. But with Arduino IDE 1.0.6 all of this runs perfectly.

Again, any insight or direction would be greatly appreciated :smiley:

/*
  time.h - low level time and date functions
*/

/*
  July 3 2011 - fixed elapsedSecsThisWeek macro (thanks Vincent Valdy for this)
              - fixed  daysToTime_t macro (thanks maniacbug)
*/     

#ifndef _Time_h
#define _Time_h

#include <inttypes.h>

typedef unsigned long time_t;

typedef enum {timeNotSet, timeNeedsSync, timeSet
}  timeStatus_t ;

typedef enum {
    dowInvalid, dowSunday, dowMonday, dowTuesday, dowWednesday, dowThursday, dowFriday, dowSaturday
} timeDayOfWeek_t;

typedef enum {
    tmSecond, tmMinute, tmHour, tmWday, tmDay,tmMonth, tmYear, tmNbrFields
} tmByteFields;	   

typedef struct  { 
  uint8_t Second; 
  uint8_t Minute; 
  uint8_t Hour; 
  uint8_t Wday;   // day of week, sunday is day 1
  uint8_t Day;
  uint8_t Month; 
  uint8_t Year;   // offset from 1970; 
} 	tmElements_t, TimeElements, *tmElementsPtr_t;

//convenience macros to convert to and from tm years 
#define  tmYearToCalendar(Y) ((Y) + 1970)  // full four digit year 
#define  CalendarYrToTm(Y)   ((Y) - 1970)
#define  tmYearToY2k(Y)      ((Y) - 30)    // offset is from 2000
#define  y2kYearToTm(Y)      ((Y) + 30)   

typedef time_t(*getExternalTime)();
//typedef void  (*setExternalTime)(const time_t); // not used in this version


/*==============================================================================*/
/* Useful Constants */
#define SECS_PER_MIN  (60UL)
#define SECS_PER_HOUR (3600UL)
#define SECS_PER_DAY  (SECS_PER_HOUR * 24UL)
#define DAYS_PER_WEEK (7UL)
#define SECS_PER_WEEK (SECS_PER_DAY * DAYS_PER_WEEK)
#define SECS_PER_YEAR (SECS_PER_WEEK * 52UL)
#define SECS_YR_2000  (946684800UL) // the time at the start of y2k
 
/* Useful Macros for getting elapsed time */
#define numberOfSeconds(_time_) (_time_ % SECS_PER_MIN)  
#define numberOfMinutes(_time_) ((_time_ / SECS_PER_MIN) % SECS_PER_MIN) 
#define numberOfHours(_time_) (( _time_% SECS_PER_DAY) / SECS_PER_HOUR)
#define dayOfWeek(_time_)  ((( _time_ / SECS_PER_DAY + 4)  % DAYS_PER_WEEK)+1) // 1 = Sunday
#define elapsedDays(_time_) ( _time_ / SECS_PER_DAY)  // this is number of days since Jan 1 1970
#define elapsedSecsToday(_time_)  (_time_ % SECS_PER_DAY)   // the number of seconds since last midnight 
// The following macros are used in calculating alarms and assume the clock is set to a date later than Jan 1 1971
// Always set the correct time before settting alarms
#define previousMidnight(_time_) (( _time_ / SECS_PER_DAY) * SECS_PER_DAY)  // time at the start of the given day
#define nextMidnight(_time_) ( previousMidnight(_time_)  + SECS_PER_DAY )   // time at the end of the given day 
#define elapsedSecsThisWeek(_time_)  (elapsedSecsToday(_time_) +  ((dayOfWeek(_time_)-1) * SECS_PER_DAY) )   // note that week starts on day 1
#define previousSunday(_time_)  (_time_ - elapsedSecsThisWeek(_time_))      // time at the start of the week for the given time
#define nextSunday(_time_) ( previousSunday(_time_)+SECS_PER_WEEK)          // time at the end of the week for the given time


/* Useful Macros for converting elapsed time to a time_t */
#define minutesToTime_t ((M)) ( (M) * SECS_PER_MIN)  
#define hoursToTime_t   ((H)) ( (H) * SECS_PER_HOUR)  
#define daysToTime_t    ((D)) ( (D) * SECS_PER_DAY) // fixed on Jul 22 2011
#define weeksToTime_t   ((W)) ( (W) * SECS_PER_WEEK)   

/*============================================================================*/
/*  time and date functions   */
//int     hour();            // the hour now 
int     hour(time_t t);    // the hour for the given time
//int     hourFormat12();    // the hour now in 12 hour format
int     hourFormat12(time_t t); // the hour for the given time in 12 hour format
//uint8_t isAM();            // returns true if time now is AM
uint8_t isAM(time_t t);    // returns true the given time is AM
//uint8_t isPM();            // returns true if time now is PM
uint8_t isPM(time_t t);    // returns true the given time is PM
//int     minute();          // the minute now 
int     minute(time_t t);  // the minute for the given time
//int     second();          // the second now 
int     second(time_t t);  // the second for the given time
//int     day();             // the day now 
int     day(time_t t);     // the day for the given time
//int     weekday();         // the weekday now (Sunday is day 1) 
int     weekday(time_t t); // the weekday for the given time 
//int     month();           // the month now  (Jan is month 1)
int     month(time_t t);   // the month for the given time
//int     year();            // the full four digit year: (2009, 2010 etc) 
int     year(time_t t);    // the year for the given time

time_t now();              // return the current time as seconds since Jan 1 1970 
void    setTime(time_t t);
//void    setTime(int hr,int min,int sec,int day, int month, int yr);
void    adjustTime(long adjustment);

/* date strings */ 
#define dt_MAX_STRING_LEN 9 // length of longest date string (excluding terminating null)
char* monthStr(uint8_t month);
char* dayStr(uint8_t day);
char* monthShortStr(uint8_t month);
char* dayShortStr(uint8_t day);
	
/* time sync functions	*/
timeStatus_t timeStatus(); // indicates if time has been set and recently synchronized
void    setSyncProvider( getExternalTime getTimeFunction); // identify the external time provider
void    setSyncInterval(time_t interval); // set the number of seconds between re-sync

/* low level functions to convert to and from system time                     */
void breakTime(time_t time, tmElements_t &tm);  // break time_t into elements
time_t makeTime(tmElements_t &tm);  // convert time elements into time_t


#endif /* _Time_h */
#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>

const char *monthName[12] = {
  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};

tmElements_t tm;

void setup() {
  bool parse=false;
  bool config=false;

  // get the date and time the compiler was run
  if (getDate(__DATE__) && getTime(__TIME__)) {
    parse = true;
    // and configure the RTC with this info
    if (RTC.write(tm)) {
      config = true;
    }
  }

  Serial.begin(9600);
  while (!Serial) ; // wait for Arduino Serial Monitor
  delay(200);
  if (parse && config) {
    Serial.print("DS1307 configured Time=");
    Serial.print(__TIME__);
    Serial.print(", Date=");
    Serial.println(__DATE__);
  } else if (parse) {
    Serial.println("DS1307 Communication Error :-{");
    Serial.println("Please check your circuitry");
  } else {
    Serial.print("Could not parse info from the compiler, Time=\"");
    Serial.print(__TIME__);
    Serial.print("\", Date=\"");
    Serial.print(__DATE__);
    Serial.println("\"");
  }
}

void loop() {
}

bool getTime(const char *str)
{
  int Hour, Min, Sec;

  if (sscanf(str, "%d:%d:%d", &Hour, &Min, &Sec) != 3) return false;
  tm.Hour = Hour;
  tm.Minute = Min;
  tm.Second = Sec;
  return true;
}

bool getDate(const char *str)
{
  char Month[12];
  int Day, Year;
  uint8_t monthIndex;

  if (sscanf(str, "%s %d %d", Month, &Day, &Year) != 3) return false;
  for (monthIndex = 0; monthIndex < 12; monthIndex++) {
    if (strcmp(Month, monthName[monthIndex]) == 0) break;
  }
  if (monthIndex >= 12) return false;
  tm.Day = Day;
  tm.Month = monthIndex + 1;
  tm.Year = CalendarYrToTm(Year);
  return true;
}

UPDATE:

Read yesterday that the time.h lib is currently not compatible with Arduino-Intel IDE, hopefully this gets looked at on Intel's side. However, I also read that it might be an issue of libraries and IDE not being linked, and I might need to cross-compile them? I'm going to try and look into this today.

UST