#include <WiFi.h>
#include <Firebase_ESP_Client.h>
#include <addons/TokenHelper.h>
#include <addons/RTDBHelper.h>
#include <Keypad.h>
#include <LiquidCrystal.h>
#define WIFI_SSID "MEMO"
#define WIFI_PASSWORD "FCbarcelona2009"
//Define the API key
#define API_KEY "AIzaSyDMs7hmxYQxzZjCTKeub2faE9JsOanQ4YQ"
/* If work with RTDB, define the RTDB URL */
#define DATABASE_URL "https://first-assignment-in-cloud-default-rtdb.firebaseio.com/"
/*Define the Firebase Data object */
FirebaseData fbdo;
/*Define the FirebaseAuth data for authentication data */
FirebaseAuth auth;
/*Define the FirebaseConfig data for config data */
FirebaseConfig config;
// Delaying time
unsigned long dataMillis = 0;
// Define your keypad configuration
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {12, 11, 10, 3}; //connect to the column pinouts of the keypad
// Keypad Deceleration
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// LCD Declearing
LiquidCrystal lcd(4, 13, 14, 15, 16, 17);
// Checking if Auth True will continue, Else won't work
String readKeypadInput() {
int i = 0;
String password = "";
while (i < 9) {
char key = keypad.getKey();
if (key) {
password += key;
i++;
}
}
return password;
}
String password = readKeypadInput();
// Declearing IR SENSOR
const int IR_PIN = 35;
void setup()
{
pinMode(IR_PIN, INPUT);
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
Serial.printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);
/* Assign the api key (required) */
config.api_key = API_KEY;
/* Assign the user sign in credentials */
auth.user.email = "[email protected]";
auth.user.password = password;
config.database_url = DATABASE_URL;
Firebase.reconnectWiFi(true);
fbdo.setResponseSize(4096);
/* Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback;
/* Initialize the library with the Firebase authen and config */
Firebase.begin(&config, &auth);
}
void loop(){
// Firebase.ready() should be called repeatedly to handle authentication tasks.
if (millis() - dataMillis > 5000 && Firebase.ready()){
dataMillis = millis();
Serial.println(auth.token.uid.c_str());
Serial.println("---------------------");
}
}