Skip to content

Wrapper around EEPROM as a key storing database.

Notifications You must be signed in to change notification settings

Prepager/Arduino-KeyDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arduino - EEPROM Key Database

This library is a wrapper around EEPROM as a key storing database. The libraries initial purpose was to be used for RFID HEX ID storing and verification.

Methods

int KeyDB::count() Returns key count from storage.

void KeyDB::loadKeys() Loads keys from storage into array.

void KeyDB::saveKeys() Saves array keys to storage.

void KeyDB::addKey(String key) Adds key to array and storage.

void KeyDB::removeKey(String key) Removes key from array and shift indexes.

Because of heavy read/write actions when removing you must manually call KeyDB::saveKeys() to save changes.

bool KeyDB::keyExists(String key) Checks if key exists in array.

String KeyDB::keyLengthen(String key) Forces a key to a fixed defined length.

Variables

#define DB_KEY_MAX 12 The maximum amount of keys in the database.

#define DB_KEY_LENGTH 8 The char length of the key.

String KeyDB::keys[DB_KEY_MAX] = {""} The main array of keys.

Usage

BEFORE USE: The initial count must be set by doing: #include <EEPROM.h> & EEPROM.write(0, 0);

// Include the KeyDB file.
#include "KeyDB.h"

// Create a new KeyDB object.
KeyDB database;

void setup() {
    Serial.begin(9600);

    // Add new key to database.
    database.addKey("ABC12345");

    // Check if it exists in storage.
    if (database.keyExists("ABC12345"))
        Serial.println("Valid key!");
}