DS3231 real time clock

I am trying to generate a program that will run a one time password that will work with Google Authenticate. I have most of it done and built. I built the code to work with the DS1307 and the realized that I have the DS3231. (oops) I am trying to get the code to call up the unix time and it will not. I have scoured the web and starting to come up empty handed. Any help would be great. below is the code and the error.

The main error that I am getting is

OTP_DOOR1.ino: In function 'void loop()':
OTP_DOOR1.ino:125:28: error: 'class DS3231' has no member named 'get'
OTP_DOOR1.ino:126:24: error: 'class DateTime' has no member named 'unixtime'
'class DS3231' has no member named 'get'

The full error Message is at http://pastebin.com/9Fz8bFZ7

#include <RTClib.h>
#include <DS3231.h>
#include <Wire.h>
#include <RTClib.h>
#include <Time.h>
#include <Keypad.h>
#include <sha1.h>
#include <TOTP.h>
#include <Servo.h>

DS3231 RTC;

#define DS3231_I2C_ADDRESS 0x68

// debug print, use #define DEBUG to enable Serial output
#define DEBUG
#ifdef DEBUG
  #define DEBUG_PRINT(x)  Serial.print(x)
  #define DEBUG_PRINTLN(x)  Serial.println(x)
#else
  #define DEBUG_PRINT(x)
  #define DEBUG_PRINTLN(x)
#endif

// servo configuration: PIN, door closed/opened position and speed
#define SERVO_PIN     9
#define SERVO_CLOSED  5
#define SERVO_OPENED  100
#define SERVO_DELAY   20

// shared secret
uint8_t hmacKey[] = {0x34, 0x67, 0x78, 0x71, 0x40, 0x6d, 0x5a, 0x3b, 0x7e, 0x4e};
TOTP totp = TOTP(hmacKey, 10);

// keypad configuration
const byte rows = 4;
const byte cols = 3;
char keys[rows][cols] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[rows] = {2, 3, 4, 5};
byte colPins[cols] = {6, 7, 8};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);

Servo doorServo;


char* totpCode;
char inputCode[7];
int inputCode_idx;
boolean doorOpen;


void setup() {
  
  Serial.begin(9600);
  DEBUG_PRINTLN("TOTP Door lock");
  DEBUG_PRINTLN("");

//setSyncProvider(RTC.get);
  
  // attach servo object to the correct PIN
  doorServo.attach(SERVO_PIN);
  DEBUG_PRINTLN("Servo initialized");

  // init RTC with
  Wire.begin();


  // reset input buffer index
  inputCode_idx = 0;
  
  // close the door
  doorServo.write(SERVO_CLOSED);
  doorOpen = false;
  DEBUG_PRINTLN("Door closed");  
}


void loop() {
  
  char key = keypad.getKey();

  // a key was pressed
  if (key != NO_KEY) {

    // # resets the input buffer    
    if(key == '#') {
      DEBUG_PRINTLN("# pressed, resetting the input buffer...");
      inputCode_idx = 0;      
    }
    
    // * closes the door
    else if(key == '*') {

      if(doorOpen == false) DEBUG_PRINTLN("* pressed but the door is already closed");

      else {

        DEBUG_PRINTLN("* pressed, closing the door...");
        for(int i = 0; i < SERVO_OPENED - SERVO_CLOSED; i++) {
          doorServo.write(SERVO_OPENED - i);
          delay(SERVO_DELAY);
        }
        doorOpen = false;
      }
    }
    else {      
      
      // save key value in input buffer
      inputCode[inputCode_idx++] = key;
      
      // if the buffer is full, add string terminator, reset the index
      // get the actual TOTP code and compare to the buffer's content
      if(inputCode_idx == 6) {
        
        inputCode[inputCode_idx] = '\0';
        inputCode_idx = 0;
        DEBUG_PRINT("New code inserted: ");
        DEBUG_PRINTLN(inputCode);
        
        DateTime now = RTC.get();
        long EST = now.unixtime();
        char* newCode = totp.getCode(EST);
        
        // code is ok :)
        if(strcmp(inputCode, totpCode) == 0) {
          
          if(doorOpen == true) DEBUG_PRINTLN("Code ok but the door is already open");
          
          else {
            DEBUG_PRINTLN("Code ok, opening the door...");
            for(int i = 0; i < SERVO_OPENED - SERVO_CLOSED; i++) {
              doorServo.write(SERVO_CLOSED + i);
              delay(SERVO_DELAY);
            }
            doorOpen = true;
          }
          
        // code is wrong :(  
        } else {
          DEBUG_PRINT("Wrong code... the correct was: ");
          DEBUG_PRINTLN(totpCode);         
        }
      }      
    }
  }
}

See if adding #include <Arduino.h> before all the includes solve your problem.

I added the line and it is still giving me the same error. I can offer the libraries if that may help.

Open the RTClib.h file and add

#include <Arduino.h>

at the the first line
and check again.

I added the line. I am getting this error.

OTP_DOOR1.ino: In function 'void loop()':
OTP_DOOR1.ino:126:28: error: 'class DS3231' has no member named 'get'
'class DS3231' has no member named 'get'

Is there just the following message errors

OTP_DOOR1.ino: In function 'void loop()':
OTP_DOOR1.ino:126:28: error: 'class DS3231' has no member named 'get'
'class DS3231' has no member named 'get'

?

The code you posted at the beginning of this topic, did you write it or it's a default example that came with the library?

In the place of this line:

DateTime now = RTC.get();

use:

DateTime now = RTC.now();

The code did not come with the library. it was created with a software RTC and I modified it to work with the DS1307 but the realized that my RTC is a DS3231. The code worked with the DS1307 but it would not call time due to the wrong RTC. Here is my DS3231.h library.

/*
DS3231.h - Header file for the DS3231 Real-Time Clock

Version: 1.0.1
(c) 2014 Korneliusz Jarzebski
www.jarzebski.pl

This program is free software: you can redistribute it and/or modify
it under the terms of the version 3 GNU General Public License as
published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef DS3231_h
#define DS3231_h

#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#define DS3231_ADDRESS              (0x68)

#define DS3231_REG_TIME             (0x00)
#define DS3231_REG_ALARM_1          (0x07)
#define DS3231_REG_ALARM_2          (0x0B)
#define DS3231_REG_CONTROL          (0x0E)
#define DS3231_REG_STATUS           (0x0F)
#define DS3231_REG_TEMPERATURE      (0x11)

#ifndef RTCDATETIME_STRUCT_H
#define RTCDATETIME_STRUCT_H
struct RTCDateTime
{
    uint16_t year;
    uint8_t month;
    uint8_t day;
    uint8_t hour;
    uint8_t minute;
    uint8_t second;
    uint8_t dayOfWeek;
    uint32_t unixtime;
};

struct RTCAlarmTime
{
    uint8_t day;
    uint8_t hour;
    uint8_t minute;
    uint8_t second;
};
#endif

typedef enum
{
    DS3231_1HZ          = 0x00,
    DS3231_4096HZ       = 0x01,
    DS3231_8192HZ       = 0x02,
    DS3231_32768HZ      = 0x03
} DS3231_sqw_t;

typedef enum
{
    DS3231_EVERY_SECOND   = 0b00001111,
    DS3231_MATCH_S        = 0b00001110,
    DS3231_MATCH_M_S      = 0b00001100,
    DS3231_MATCH_H_M_S    = 0b00001000,
    DS3231_MATCH_DT_H_M_S = 0b00000000,
    DS3231_MATCH_DY_H_M_S = 0b00010000
} DS3231_alarm1_t;

typedef enum
{
    DS3231_EVERY_MINUTE   = 0b00001110,
    DS3231_MATCH_M        = 0b00001100,
    DS3231_MATCH_H_M      = 0b00001000,
    DS3231_MATCH_DT_H_M   = 0b00000000,
    DS3231_MATCH_DY_H_M   = 0b00010000
} DS3231_alarm2_t;

class DS3231
{
    public:

	bool begin(void);

	void setDateTime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second);
	void setDateTime(uint32_t t);
	void setDateTime(const char* date, const char* time);
	RTCDateTime getDateTime(void);
	uint8_t isReady(void);

	DS3231_sqw_t getOutput(void);
	void setOutput(DS3231_sqw_t mode);
	void enableOutput(bool enabled);
	bool isOutput(void);
	void enable32kHz(bool enabled);
	bool is32kHz(void);

	void forceConversion(void);
	float readTemperature(void);

	void setAlarm1(uint8_t dydw, uint8_t hour, uint8_t minute, uint8_t second, DS3231_alarm1_t mode, bool armed = true);
	RTCAlarmTime getAlarm1(void);
	DS3231_alarm1_t getAlarmType1(void);
	bool isAlarm1(bool clear = true);
	void armAlarm1(bool armed);
	bool isArmed1(void);
	void clearAlarm1(void);

	void setAlarm2(uint8_t dydw, uint8_t hour, uint8_t minute, DS3231_alarm2_t mode, bool armed = true);
	RTCAlarmTime getAlarm2(void);
	DS3231_alarm2_t getAlarmType2(void);
	bool isAlarm2(bool clear = true);
	void armAlarm2(bool armed);
	bool isArmed2(void);
	void clearAlarm2(void);

	void setBattery(bool timeBattery, bool squareBattery);

	char* dateFormat(const char* dateFormat, RTCDateTime dt);
	char* dateFormat(const char* dateFormat, RTCAlarmTime dt);

    private:
	RTCDateTime t;

	char *strDayOfWeek(uint8_t dayOfWeek);
	char *strMonth(uint8_t month);
	char *strAmPm(uint8_t hour, bool uppercase);
	char *strDaySufix(uint8_t day);

	uint8_t hour12(uint8_t hour24);
	uint8_t bcd2dec(uint8_t bcd);
	uint8_t dec2bcd(uint8_t dec);

	long time2long(uint16_t days, uint8_t hours, uint8_t minutes, uint8_t seconds);
	uint16_t date2days(uint16_t year, uint8_t month, uint8_t day);
	uint8_t daysInMonth(uint16_t year, uint8_t month);
	uint16_t dayInYear(uint16_t year, uint8_t month, uint8_t day);
	bool isLeapYear(uint16_t year);
	uint8_t dow(uint16_t y, uint8_t m, uint8_t d);

	uint32_t unixtime(void);
	uint8_t conv2d(const char* p);

	void writeRegister8(uint8_t reg, uint8_t value);
	uint8_t readRegister8(uint8_t reg);
};

#endif

Replace this line in your code:

DateTime now = RTC.get();

for:

RTCDateTime now = RTC.now();

Just a comment:
When you implemented the DS3231 in the place of the DS1307, there a high chance (almost 100%) that the new library members / functions don't have the same name as the old library. Check this compability when doing something like changing libraries!

I made the updates and it does not like the now.

OTP_DOOR1.ino: In function 'void loop()':
OTP_DOOR1.ino:126:31: error: 'class DS3231' has no member named 'now'
OTP_DOOR1.ino:127:33: error: expression cannot be used as a function
'class DS3231' has no member named 'now'

Sorry, I confused the things.

Replace this line in your code:

DateTime now = RTC.get();

for:

RTCDateTime now = RTC.getDateTime();

That worked great thank you. Now I am getting this error.

OTP_DOOR1.ino: In function 'void loop()':
OTP_DOOR1.ino:127:33: error: expression cannot be used as a function
expression cannot be used as a function

It has to do with this section of code but errors on the line in red.

        RTCDateTime now = RTC.getDateTime();
        [color=red]long EST = now.unixtime();[/color]
        char* newCode = totp.getCode(EST);

Replace this:

long EST = now.unixtime();

with:

unsigned long EST = now.unixtime;

Check the DS321.h file to see what is the types of variables and returns of the functions.

YOU ROCK it worked thank you so very very much.