Time & TimeLib error when using timeStatus

I am getting an error when trying to see if Time has synced with the ds3231 rtc.

The error message

Arduino: 1.6.13 (Windows 10), Board: "Arduino/Genuino Uno"

In file included from C:\Program Files (x86)\Arduino\libraries\Time/Time.h:1:0,

                 from C:\Users\Tara Stanley\Documents\Arduino\AquariumControllerIfElseTest\AquariumControllerIfElseTest.ino:1:

C:\Program Files (x86)\Arduino\libraries\Time/TimeLib.h:79:39: error: expected unqualified-id before '/' token

 #define dayOfWeek(_time_)  ((( _time_ / SECS_PER_DAY + 4)  % DAYS_PER_WEEK)+1) // 1 = Sunday

                                       ^

C:\Users\Tara Stanley\Documents\Arduino\libraries\Sodaq_DS3231\src/Sodaq_DS3231.h:36:13: note: in expansion of macro 'dayOfWeek'

     uint8_t dayOfWeek() const   { return wday;}  /*Su=1 Mo=2 Tu=3 We=4 Th=5 Fr=6 Sa=7 */

             ^

C:\Program Files (x86)\Arduino\libraries\Time/TimeLib.h:79:39: error: expected ')' before '/' token

 #define dayOfWeek(_time_)  ((( _time_ / SECS_PER_DAY + 4)  % DAYS_PER_WEEK)+1) // 1 = Sunday

                                       ^

C:\Users\Tara Stanley\Documents\Arduino\libraries\Sodaq_DS3231\src/Sodaq_DS3231.h:36:13: note: in expansion of macro 'dayOfWeek'

     uint8_t dayOfWeek() const   { return wday;}  /*Su=1 Mo=2 Tu=3 We=4 Th=5 Fr=6 Sa=7 */

             ^

C:\Program Files (x86)\Arduino\libraries\Time/TimeLib.h:79:39: error: expected ')' before '/' token

 #define dayOfWeek(_time_)  ((( _time_ / SECS_PER_DAY + 4)  % DAYS_PER_WEEK)+1) // 1 = Sunday

                                       ^

C:\Users\Tara Stanley\Documents\Arduino\libraries\Sodaq_DS3231\src/Sodaq_DS3231.h:36:13: note: in expansion of macro 'dayOfWeek'

     uint8_t dayOfWeek() const   { return wday;}  /*Su=1 Mo=2 Tu=3 We=4 Th=5 Fr=6 Sa=7 */

             ^

C:\Program Files (x86)\Arduino\libraries\Time/TimeLib.h:79:39: error: expected ')' before '/' token

 #define dayOfWeek(_time_)  ((( _time_ / SECS_PER_DAY + 4)  % DAYS_PER_WEEK)+1) // 1 = Sunday

                                       ^

C:\Users\Tara Stanley\Documents\Arduino\libraries\Sodaq_DS3231\src/Sodaq_DS3231.h:36:13: note: in expansion of macro 'dayOfWeek'

     uint8_t dayOfWeek() const   { return wday;}  /*Su=1 Mo=2 Tu=3 We=4 Th=5 Fr=6 Sa=7 */

             ^

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

The code.

#include <Time.h>
#include <TimeLib.h>

#include <Sodaq_DS3231.h>
#include <Wire.h>

unsigned long currentMillis = 0;
unsigned long previousMillis = 0;
const long interval = 1000;
uint32_t old_ts;
char weekDay[][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };

void setup() {
  Serial.begin(9600);
  Wire.begin();
  rtc.begin();
  
}

void loop() {
  DateTime now = rtc.now();
  uint32_t ts = now.getEpoch();
  currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;                      // Save the last time time and temp was displayed
    clockDisplay();                                      //Print date and time to serial(9600)
    roomTemp();                                          //Print temp from rtc to serial(9600)
  }
timeStatus();
}

void clockDisplay() {
  DateTime now = rtc.now(); //get the current date-time
  uint32_t ts = now.getEpoch();

  if (old_ts == 0 || old_ts != ts) {
    old_ts = ts;
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.date(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.print(' ');
    //Serial.print(weekday[now.dayOfWeek()]);
    Serial.println();
    Serial.print("Seconds since Unix Epoch: ");
    Serial.print(ts, DEC);
    Serial.println();
  }
}

void roomTemp() {
  rtc.convertTemperature();             //convert current temperature into registers
  //Serial.print(rtc.getTemperature()); //read registers and display the temperature
  Serial.print(rtc.getTemperature() * 9 / 5 + 32);
  Serial.println("deg F");
}

Just as i was writing this i noticed i get the error even without using timeStatus, if i comment out #include <TimeLib.h> i no longer get the error but instead get timeStatus not declared in scope.

You have two libraries using the same name for conflicting purposes. One uses it as a function and one uses it as a macro.

I would try commenting out the is line 36 in C:\Users\Tara Stanley\Documents\Arduino\libraries\Sodaq_DS3231\src/Sodaq_DS3231.h:

     uint8_t dayOfWeek() const   { return wday;}  /*Su=1 Mo=2 Tu=3 We=4 Th=5 Fr=6 Sa=7 */

johnwasser:
You have two libraries using the same name for conflicting purposes. One uses it as a function and one uses it as a macro.

I would try commenting out the is line 36 in C:\Users\Tara Stanley\Documents\Arduino\libraries\Sodaq_DS3231\src/Sodaq_DS3231.h:

     uint8_t dayOfWeek() const   { return wday;}  /*Su=1 Mo=2 Tu=3 We=4 Th=5 Fr=6 Sa=7 */

Thanks that fixed that, what does one need to use for the setSyncProvider(); to set the time for timeLib? I know most of the rtc libarys use rtc.get or RTC.get, but the Sodaq_DS3231.h libary gives an error.

C:\Users\Tara Stanley\Documents\Arduino\AquariumController_2.0\AquariumController_2.0.ino: In function 'void loop()':

AquariumController_2.0:75: error: 'class Sodaq_DS3231' has no member named 'get'

     setSyncProvider(rtc.get);

                         ^

exit status 1
'class Sodaq_DS3231' has no member named 'get'[/code

If i use Serial.println(timeStatus());  it displays 0 to the serial.

Ok i think i have it.

uint32_t syncProvider()
{
  DateTime now = rtc.now(); //get the current date-time
  uint32_t ts = now.getEpoch();
  return ts;
}

void setup() {
  Serial.begin(9600);
  Wire.begin();
  rtc.begin();
  pinMode(dayLed, OUTPUT);
  pinMode(moonLed, OUTPUT);
  setSyncProvider(syncProvider);
}

void loop() {
  DateTime now = rtc.now(); //get the current date-time
  uint32_t ts = now.getEpoch();

  currentMillis = millis();
  fadeCurrentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;                      // Save the last time time and temp was displayed
    //clockDisplay();                                      //Print date and time to serial(9600)
    //roomTemp();                                          //Print temp from rtc to serial(9600)
    Serial.println(timeStatus());
  }

timeStatus now prints 2 to serial.

johnwasser:
You have two libraries using the same name for conflicting purposes. One uses it as a function and one uses it as a macro.

I would try commenting out the is line 36 in C:\Users\Tara Stanley\Documents\Arduino\libraries\Sodaq_DS3231\src/Sodaq_DS3231.h:

     uint8_t dayOfWeek() const   { return wday;}  /*Su=1 Mo=2 Tu=3 We=4 Th=5 Fr=6 Sa=7 */

Ok so that did not work, i removed

    dayOfWeek() const   { return wday;}  /*Su=1 Mo=2 Tu=3 We=4 Th=5 Fr=6 Sa=7 */

from my code and it solved the issue.

Now i have add the Library and the issue returned, so i actually commented out line 36 and now i get this error.

Arduino: 1.6.13 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\Tara Stanley\Documents\Arduino\libraries\Sodaq_DS3231\src\Sodaq_DS3231.cpp: In member function 'void Sodaq_DS3231::setDateTime(const DateTime&)':

C:\Users\Tara Stanley\Documents\Arduino\libraries\Sodaq_DS3231\src\Sodaq_DS3231.cpp:241:23: error: 'const class DateTime' has no member named 'dayOfWeek'

   Wire.write((byte)dt.dayOfWeek());

                       ^

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Before commenting out line 36 of sodaq i was getting this error

Arduino: 1.6.13 (Windows 10), Board: "Arduino/Genuino Uno"

In file included from C:\Program Files (x86)\Arduino\libraries\TimeAlarms/TimeAlarms.h:7:0,

                 from C:\Users\Tara Stanley\Documents\Arduino\AquariumController_2.0\AquariumController_2.0.ino:1:

C:\Program Files (x86)\Arduino\libraries\Time/TimeLib.h:79:39: error: expected unqualified-id before '/' token

 #define dayOfWeek(_time_)  ((( _time_ / SECS_PER_DAY + 4)  % DAYS_PER_WEEK)+1) // 1 = Sunday

                                       ^

C:\Users\Tara Stanley\Documents\Arduino\libraries\Sodaq_DS3231\src/Sodaq_DS3231.h:36:13: note: in expansion of macro 'dayOfWeek'

     uint8_t dayOfWeek() const   { return wday;}  /*Su=1 Mo=2 Tu=3 We=4 Th=5 Fr=6 Sa=7 */

             ^

C:\Program Files (x86)\Arduino\libraries\Time/TimeLib.h:79:39: error: expected ')' before '/' token

 #define dayOfWeek(_time_)  ((( _time_ / SECS_PER_DAY + 4)  % DAYS_PER_WEEK)+1) // 1 = Sunday

                                       ^

C:\Users\Tara Stanley\Documents\Arduino\libraries\Sodaq_DS3231\src/Sodaq_DS3231.h:36:13: note: in expansion of macro 'dayOfWeek'

     uint8_t dayOfWeek() const   { return wday;}  /*Su=1 Mo=2 Tu=3 We=4 Th=5 Fr=6 Sa=7 */

             ^

C:\Program Files (x86)\Arduino\libraries\Time/TimeLib.h:79:39: error: expected ')' before '/' token

 #define dayOfWeek(_time_)  ((( _time_ / SECS_PER_DAY + 4)  % DAYS_PER_WEEK)+1) // 1 = Sunday

                                       ^

C:\Users\Tara Stanley\Documents\Arduino\libraries\Sodaq_DS3231\src/Sodaq_DS3231.h:36:13: note: in expansion of macro 'dayOfWeek'

     uint8_t dayOfWeek() const   { return wday;}  /*Su=1 Mo=2 Tu=3 We=4 Th=5 Fr=6 Sa=7 */

             ^

C:\Program Files (x86)\Arduino\libraries\Time/TimeLib.h:79:39: error: expected ')' before '/' token

 #define dayOfWeek(_time_)  ((( _time_ / SECS_PER_DAY + 4)  % DAYS_PER_WEEK)+1) // 1 = Sunday

                                       ^

C:\Users\Tara Stanley\Documents\Arduino\libraries\Sodaq_DS3231\src/Sodaq_DS3231.h:36:13: note: in expansion of macro 'dayOfWeek'

     uint8_t dayOfWeek() const   { return wday;}  /*Su=1 Mo=2 Tu=3 We=4 Th=5 Fr=6 Sa=7 */

             ^

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Sorry about the previous confusion.

To avoid issues and conflicts between the ds3231 and the Time and TimeAlarms libaries, I would recommend tht you use the Jack Christensen library for the ds3232 and ds3231. It is rock solid, and can be found at GitHub - JChristensen/DS3232RTC: Arduino Library for Maxim Integrated DS3232 and DS3231 Real-Time Clocks

It is designed to work in conjunction with the Time and Time Alarms libraries and is also a drop in replacement for the very common DS1307 library. The effort it will take you to learn some new syntax will quickly pay off.

cattledog:
To avoid issues and conflicts between the ds3231 and the Time and TimeAlarms libaries, I would recommend tht you use the Jack Christensen library for the ds3232 and ds3231. It is rock solid, and can be found at GitHub - JChristensen/DS3232RTC: Arduino Library for Maxim Integrated DS3232 and DS3231 Real-Time Clocks

It is designed to work in conjunction with the Time and Time Alarms libraries and is also a drop in replacement for the very common DS1307 library. The effort it will take you to learn some new syntax will quickly pay off.

Thanks, didn't take but just a minute to swap it over. The reason for using Sodaq was just because of the ability to use the temperature from the rtc, but that is not really going to be applicable to what i'm doing anyways.

The reason for using Sodaq was just because of the ability to use the temperature from the rtc,

That’s actually supported in the Christensen library.