Skip to content

Instantly share code, notes, and snippets.

@thomasvt1
Created September 16, 2017 22:10
Show Gist options
  • Save thomasvt1/b9d0affbe64cb55bd719706c3d9acd31 to your computer and use it in GitHub Desktop.
Save thomasvt1/b9d0affbe64cb55bd719706c3d9acd31 to your computer and use it in GitHub Desktop.
// GetCode.ino
//
// Basic example for the TOTP library
//
// This example uses the opensource SwRTC library as a software real-time clock
// you can download from https://github.com/leomil72/swRTC
// for real implementation it's suggested the use of an hardware RTC
#include "sha1.h"
#include "TOTP.h"
#include "RTClib.h"
// The shared secret is MyLegoDoor
uint8_t hmacKey[] = {ENTER YOURSELF};
TOTP totp = TOTP(hmacKey, 10);
RTC_DS3231 rtc;
char code[7];
void setup() {
Serial.begin(9600);
}
void loop() {
DateTime now = rtc.now();
char* newCode = totp.getCode(now.unixtime());
if(strcmp(code, newCode) != 0) {
strcpy(code, newCode);
Serial.print(code);
Serial.print(" - ");
Serial.println(now.unixtime());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment