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);
}
}
}
}
}