Created
September 16, 2017 22:10
-
-
Save thomasvt1/b9d0affbe64cb55bd719706c3d9acd31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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