IoT-2020-EFREI-M1-Team-Of-2

Our project name is Smart Lock. It's a lock (for a door for example) that works with a fingerprint system.

The system works with an ESP 32 that is connected in Wifi to send data.

The fingerprint are memorize in the module AS 608 and we can manage them through 2 basics programs to add or delete fingerprint.
We also have implemented a door sensor that allow us to know if someone open or close the door. When the door sensor is trigger it's send a mail to notify that the door is open. It's like a quite alarm.
The fingerprint system simulates the outside of the house and a simple button simulates the inside of the house.

Slides & Videos

Members

NameContribution
NGUYEN Luc-EricDesign the smart lock model.
Connection between ESP32 and other elements​.
Do a part of the software for the smart lock with the help of Nathan.
Do the video montage.
Think about hardware part at the begin​.
Fritzing to help before assembly of our project​.
Preparation for the presentation day with powerpoint.
Write the report.
THOMAS NathanImplementation of the system of the fingerprint.
Film all the process of each steps of the project for the future video.
Realize connection between elements to allow the communication between elements.
Think about software part at the begin​.
Develop the notification system.
Manage IFTTT part.
Preparation for the presentation day with powerpoint.
Help Luc-Eric with the report.

State of the Art

Business Aspect

SmartLock's on the Market

  • Reminder :

Connected locks make it possible to open the door of a house thanks to a smartphone and an internet or Bluetooth connection. Instead of opening with a physical key, these locks open remotely via a secure mobile application, or by sending notifications after a fingerprint has been read.

  • How does it work :

The lock opens when its connector detects the proximity of an electronic key, such as a smartphone or the reading of a fingerprint on the reader. Access rights are defined in advance by the lock administrator. There are many technologies and standards for transceivers used to achieve smart lock over the years. Today many variants exist as environmental issues are becoming more and more important, and connected objects are more and more present on the market. However, other projects and designs are mostly smart locks for professional use in a company for example.

  • Our project differs from other competitors

Since it affects both large companies and individuals who need to feel more secure with a practical mind. The use can be accessible for an individual or a family. Our product can be adapted to any type of case either in a company or for a home. The strong point remains its low production cost and therefore low price compared to the competition. It is a security product accessible to all. Finally, nowadays everyone dreams of having their own smart lock.

  •  Why is that?

First of all, there is no need for a key anymore, so for practicality and also for ecology. Because if there is no more need for keys, there is no need to produce them and pollute during key production. It is a lock that our users will be able to install easily without any worries or need for a locksmith. A customizable lock through which the owner will be able to choose other users. Thanks to its intuitive interface, the owner can easily be alerted or filter the information that interests him among many information and notifications.

  • Our values :

Focus on accessibility and ecology as well as user comfort. We are going to show you some locks present on the market in 2020 and so at the end of these presentations we are going to provide you the different criteria to choose your SmartLock.

  • NUKI Combo : – Simple operation – Highly functional application – All-purpose design – But price not accessible to all.

The best smart lock in 2020. With more than 65 employees, it is a leader on the European market and a partner with large companies such as Apple, Google and Airbnb. Already sold 100,000 copies in 2019. A bright future for this firm.

  • Samsung SHS2920 : – Wide range of functionalities – Several means of access – Cheap – But no guarantee.

The brand is known for its smartphones, tablets and televisions, but it is also a leader in this field. Possess many means of access.

  • SOMFY : – Modern design in several variations – Easy to use (even for a child) – Easy installation

Easy to use product with free application provided and very intuitive with classic functionalities. Can be accessed by up to 20 users with either permanent or temporary access. Provided with 3 keys in case of problem.

Technical Aspect

SmartLock's technologies on the Market

Here are the main technologies that smart locks can use.

  • The great advantage of Bluetooth as a transmission standard for smart locks is its low power consumption. Since smart locks are mostly battery-powered, power consumption cannot be neglected. Unlocking is only possible via Bluetooth over short distances.

 

  • Z-Wave is a transmission standard that was developed specifically for Home Automation and is used for communication between different electronic devices. Can only communicate via another standard with Z-Wave. Their range can be significantly higher when using several devices in the house rather than using Bluetooth2.

 

  • Smart locks directly connected to a Wifi router are not really common. In addition to operating over the Internet, another advantage is that smart locks with WiFi support can also be operated using intelligent personal assistants (“Smart Assistants”) such as Google Home, Amazon Echo or Siri3.

 

  • Smart locks under development use NFC for transmission. The advantage is that the smart locks themselves no longer require a power supply but are able to use the induction energy of the smartphone. In this case, the smartphone scans the RFID tag integrated in the smart lock.

After having listed the different types of transmission we are now going to give you the different criteria to choose your smarlock. First of all, the use :

  • Personal housing
  • Rental to individuals
  • Work Premises
  • Working desk
  • Company

Second, the design : It’s all a matter of taste !

  • Modern
  • Discreet
  • imposing
  • round shape
  • rectangular shape

Thirdly, the budget :

  • Safety comes at a price. Minimum 100 euros otherwise you will encounter problems in order to have a well worked out smartlock.

Fourthly, the technology :

  • Bluetooth
  • Wifi
  • Z-Wave
  • NFC It will also depend on the environment in which you would use it as well as the distance you want to manage it.

Project Description

Problem Definition
The problems we want to solve with our SmartLock are numerous.
First it is to greatly improve the poor security that exists and is very present in many homes.
So to make our product accessible to all to have a real comfort of life.
Another logical point to raise is the practical part of our product. No more need to bother looking for your key ring, everything is at your fingertips.
Moreover who says disappearance of key, says a point for the ecology. If our product is a real success. Many keys will never see the light of day and the earth will be better off.

As far as our product is concerned, a lot of people may think that it is a luxury product or reserved for companies and well, on the contrary, this product is made for everyone.
Challenges & Motivation
We decided to take this subject as if it were a challenge.

We want greater equity in household safety. That our product can be used by the most would make us very proud.
Moreover, the real challenge for us is to introduce the fingerprint reader with the lock. Because for us this is a very complex task to achieve in an IoT project.

Moreover we really wanted to carry out this project because it could represent a first model with points of improvement and a better budget for our own personal use.
No more need to have a key pair to access a certain door is really great in our opinion.
Real and Complete Usecases

Use Case Lock

  • First use :

The owner need to install and connect the lock After that he just need to open the interface for the first time to create his admin’s account.

  • Register User :

He can open the lock from the outside with his fingerprint. After that he just need to push the door to close the door and the lock. When he is inside the room and wants to leave this room he just need to push the button to open again the lock and after that he ensures to close the door and lock.

  • Owner_Admin :

Can realize all actions from Register User. After login he can add his fingerprints to open the lock. He can also add other users fingerprints. He can manage the access and add other user after or delete a user. He can receive from notifications each time the lock is used or if someone broke the lock and open the lock, he can call the police.

Technical Description

In this project we use many hardware components. First, we decided to use the ESP32 for the Wifi connection instead of the Arduino Uno and the ESP 8266 as we thought at the beginning. We change our mind after trying with the ESP 8266 without any results. 

Then, we use an AS 608 as fingerprint module to manage our lock. Our lock is a 5V solenoid. We need a relay and some piles to use the lock because we need 5V for the lock (and a bit more for the relay). So the relay help us to simulate the HIGH voltage when we want on the lock. 

To display every information, we use the OLED screen that we use in TP (the SH 1106). We need to wire 4 pins (VCC, GND, SDA, SCL).

Then we use a door sensor that detect when the door is open. We use it with a webhook (from the website IFTTT) to send an email as a notification when the door is open.

Finally, we simulate the inside of the house with a button. It open the lock when we click on it. 

For the software part, we use the example of the fingerprint library (adafruit one) to add and delete every fingerprint that we use. The main program is only focus on handling the lock, by checking (in this order), the door sensor, the inside button and the fingerprint module. We use IFTTT to send request and create notification (by email) or an historic of fingerprint’s user on a Gsheet.

Hardware

Materials
ImageNamePart NumberPriceCountLink
Battery case with pile151🛒
ESP32211.491🛒
Fingertprint Reader310.601🛒
Door Sensor MC 3844.991🛒
Solénoïde ( Lock ) DC 5V51.781🛒
LCD OLED I2C68.491🛒
Push button76.791🛒
Jumper Wire84.2910🛒
Relay 5V981🛒
Schematic

Software

Arduino Code

/***************************************************
  This is an example sketch for our optical Fingerprint sensor

  Designed specifically to work with the Adafruit BMP085 Breakout
  ----> http://www.adafruit.com/products/751

  These displays use TTL Serial to communicate, 2 pins are required to
  interface
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ****************************************************/

// This code is provided with the library of Adafruit fingerprint


#include 
#include 

#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
// For UNO and others without hardware serial, we must use software serial...
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
// Set up the serial port to use softwareserial..
//SoftwareSerial mySerial(2, 3);

#else
// On Leonardo/M0/etc, others with hardware serial, use hardware serial!
// #0 is green wire, #1 is white
#define mySerial Serial1

#endif


Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial2);

uint8_t id;

void setup()
{
  Serial.begin(9600);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nAdafruit Fingerprint sensor enrollment");

  // set the data rate for the sensor serial port
  finger.begin(57600);

  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1) { delay(1); }
  }

  Serial.println(F("Reading sensor parameters"));
  finger.getParameters();
  Serial.print(F("Status: 0x")); Serial.println(finger.status_reg, HEX);
  Serial.print(F("Sys ID: 0x")); Serial.println(finger.system_id, HEX);
  Serial.print(F("Capacity: ")); Serial.println(finger.capacity);
  Serial.print(F("Security level: ")); Serial.println(finger.security_level);
  Serial.print(F("Device address: ")); Serial.println(finger.device_addr, HEX);
  Serial.print(F("Packet len: ")); Serial.println(finger.packet_len);
  Serial.print(F("Baud rate: ")); Serial.println(finger.baud_rate);
}

uint8_t readnumber(void) {
  uint8_t num = 0;

  while (num == 0) {
    while (! Serial.available());
    num = Serial.parseInt();
  }
  return num;
}

void loop()                     // run over and over again
{
  Serial.println("Ready to enroll a fingerprint!");
  Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as...");
  id = readnumber();
  if (id == 0) {// ID #0 not allowed, try again!
     return;
  }
  Serial.print("Enrolling ID #");
  Serial.println(id);

  while (!  getFingerprintEnroll() );
}

uint8_t getFingerprintEnroll() {

  int p = -1;
  Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id);
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger.image2Tz(1);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  Serial.println("Remove finger");
  delay(2000);
  p = 0;
  while (p != FINGERPRINT_NOFINGER) {
    p = finger.getImage();
  }
  Serial.print("ID "); Serial.println(id);
  p = -1;
  Serial.println("Place same finger again");
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.print(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger.image2Tz(2);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK converted!
  Serial.print("Creating model for #");  Serial.println(id);

  p = finger.createModel();
  if (p == FINGERPRINT_OK) {
    Serial.println("Prints matched!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_ENROLLMISMATCH) {
    Serial.println("Fingerprints did not match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }

  Serial.print("ID "); Serial.println(id);
  p = finger.storeModel(id);
  if (p == FINGERPRINT_OK) {
    Serial.println("Stored!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_BADLOCATION) {
    Serial.println("Could not store in that location");
    return p;
  } else if (p == FINGERPRINT_FLASHERR) {
    Serial.println("Error writing to flash");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }

  return true;
}
/***************************************************
  This is an example sketch for our optical Fingerprint sensor

  Designed specifically to work with the Adafruit Fingerprint sensor
  ----> http://www.adafruit.com/products/751

  These displays use TTL Serial to communicate, 2 pins are required to
  interface
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ****************************************************/

// This code is provided with the library of Adafruit fingerprint


#include 


#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
// For UNO and others without hardware serial, we must use software serial...
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
// Set up the serial port to use softwareserial..
SoftwareSerial mySerial(2, 3);

#else
// On Leonardo/M0/etc, others with hardware serial, use hardware serial!
// #0 is green wire, #1 is white
#define mySerial Serial1

#endif


Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()
{
  Serial.begin(9600);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nDelete Finger");

  // set the data rate for the sensor serial port
  finger.begin(57600);

  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1);
  }
}


uint8_t readnumber(void) {
  uint8_t num = 0;

  while (num == 0) {
    while (! Serial.available());
    num = Serial.parseInt();
  }
  return num;
}

void loop()                     // run over and over again
{
  Serial.println("Please type in the ID # (from 1 to 127) you want to delete...");
  uint8_t id = readnumber();
  if (id == 0) {// ID #0 not allowed, try again!
     return;
  }

  Serial.print("Deleting ID #");
  Serial.println(id);

  deleteFingerprint(id);
}

uint8_t deleteFingerprint(uint8_t id) {
  uint8_t p = -1;

  p = finger.deleteModel(id);

  if (p == FINGERPRINT_OK) {
    Serial.println("Deleted!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_BADLOCATION) {
    Serial.println("Could not delete in that location");
    return p;
  } else if (p == FINGERPRINT_FLASHERR) {
    Serial.println("Error writing to flash");
    return p;
  } else {
    Serial.print("Unknown error: 0x"); Serial.println(p, HEX);
    return p;
  }
}
/***************************************************
This code is edited by Sachin Soni for the project called
IoT Attendance System 
whose tutorial video is uploaded his YouTube Channel
Visit techiesms YouTube channel to see this and many other project tutorials
http://www.youtube.com/techiesms
       techiesms
explore | learn | share 
****************************************************/
// This code is adapted for the Smart Lock project By Luc-Eric Nguyen and Nathan Thoams
 
// Initialize library and const 
#include 
#include 
#include 
#include 
#include 
#include 
#include "WiFi.h"
#include 
#include 


const char* NAME;
const char* ID;
const int buttonPin = 4;
const int doorSensorPin = 2;
const int doorLockPin = 23; 
int buttonState = 0;

Adafruit_SH1106 display(23);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial2);

// Initialize IFTTT request
String Event_Name = "Lock_attendance";
String Event_Name2 = "MailDoor";

String Key = "d8l1LfZCIf1yR4uvghuvGF";

// Replace with your unique IFTTT URL resource
String resource = "/trigger/" + Event_Name + "/with/key/" + Key;
String resource2 = "/trigger/" + Event_Name2 + "/with/key/" + Key;

// Maker Webhooks IFTTT
const char* server = "maker.ifttt.com";

// Replace with your SSID and Password
const char* ssid     = "SFR_8388"; // set your WIFI SSID and password
const char* password = "5gdw28vxnm2xbx75izth"; 

//Setup function
void setup()
{
   //Setup components
  Serial.begin(115200);
  Serial2.begin(115200);
  pinMode(doorSensorPin, INPUT_PULLUP);
  pinMode(buttonPin,INPUT);
  pinMode(doorLockPin, OUTPUT);

  digitalWrite(doorLockPin, LOW);
  while (!Serial);
  delay(100);
  Serial.println("\n\nAdafruit finger detect test");
  display.begin();
  display.clearDisplay();
  
  // set the data rate for the sensor serial port
  finger.begin(57600);
  delay(5);
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1) {
      delay(1);
    }
  }

  finger.getTemplateCount();
  Serial.print("Sensor contains "); 
  Serial.print(finger.templateCount); 
  Serial.println(" templates");
  Serial.println("Waiting for valid finger...");
  digitalWrite(doorLockPin, LOW);
  //Setup WIFI connection
  Serial.print("Connecting to: ");
  Serial.print(ssid);
  WiFi.begin(ssid, password);

  int timeout = 10 * 4; // 10 seconds
  while (WiFi.status() != WL_CONNECTED  && (timeout-- > 0)) {
    delay(250);
    Serial.print(".");
  }
  Serial.println("");

  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("Failed to connect, going back to sleep");
  }

  Serial.print("WiFi connected in: ");
  Serial.print(millis());
  Serial.print(", IP address: ");
  Serial.println(WiFi.localIP());
  digitalWrite(doorLockPin, LOW);
}

void loop()                    
{
  //set display
   display.clearDisplay();
   display.setTextColor(WHITE);
   display.setTextSize(1); //default value
   display.setCursor(40,30);
   display.println("Hello");
   display.display();
   delay(3500);
   display.clearDisplay();
  
  int tps = 0;
 
  // Check if the door sensor is open or close
  while ( tps != 10){
    int doorSensor = digitalRead(doorSensorPin);
    if (doorSensor == LOW) {
      display.clearDisplay();
      display.setCursor(5,30);
      display.println("Door sensor is close");
      display.display();
      delay(200);
    }
    else if (doorSensor == HIGH){
      display.clearDisplay();
      display.setCursor(5,30);
      display.println("door sensor is open");
      display.display();
      NAME = "Door";
      ID = "1";
      makeIFTTTRequest2();
      tps = 9;
      delay(2000);
    }
    tps++;
  }

  //Check if the button of inside is use
  tps = 0;
  while(tps != 10){
    
      buttonState = digitalRead(buttonPin);
      display.clearDisplay();
      display.setCursor(5,30);
      display.println("Check for button entrance");
      display.display();
      delay(100);

    if (buttonState == HIGH){
      digitalWrite(doorLockPin, HIGH);
      display.clearDisplay();
      display.setCursor(10,30);
      display.println("door open by inside");
      display.display();
      delay(3000);
      digitalWrite(doorLockPin, LOW);
      tps = 9;
    }
    tps++;
  }

  // Search if the fingerprint is in the database of the component
  getFingerprintIDez();

  //Setup the ID to identity each people
  if (finger.fingerID == 1) {

    Serial.print("!!--");
    Serial.println(finger.fingerID);
    NAME = "Nathan";
    ID = "1";
    if (finger.confidence >= 60) {
      Serial.print("Attendace Marked for "); 
      Serial.println(NAME);
      digitalWrite(doorLockPin, HIGH);
      delay(2000);
      digitalWrite(doorLockPin, LOW);
      makeIFTTTRequest();
     
    }
    else{
      display.clearDisplay();
      display.println("not enough confidence");
      display.display();
      delay(3000);  
    }

  }

  else if (finger.fingerID == 11 ) {
    Serial.print("!!--");
    Serial.println(finger.fingerID);
    NAME = "Luc Eric";
    ID = "11";
    if (finger.confidence >= 60) {
      Serial.print("Attendace Marked for "); 
      Serial.println(NAME);
      digitalWrite(doorLockPin, HIGH);
      delay(2000);
      digitalWrite(doorLockPin, LOW);
      makeIFTTTRequest();
      }
    else{
      display.clearDisplay();
      display.println("not enough confidence");
      display.display();     
      delay(3000);
    }
  }
  finger.fingerID = 0;
}

// Function of searching that can return error if there is a problem
uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK success!
  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK converted!
  p = finger.fingerFastSearch();
  if (p == FINGERPRINT_OK) {
    Serial.println("Found a print match!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
    Serial.println("Did not find a match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }

  // found a match!
  Serial.print("Found ID #"); 
  Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); 
  Serial.println(finger.confidence);

  return finger.fingerID;
}

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.image2Tz();
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)  return -1;

  // found a match!
  Serial.print("Found ID #"); 
  Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); 
  Serial.println(finger.confidence);
  return finger.fingerID;
}

// Make an HTTP request to the IFTTT web service
// UPdate the Gsheet
void makeIFTTTRequest() {
  Serial.print("Connecting to ");
  Serial.print(server);

  WiFiClient client;
  int retries = 5;
  while (!!!client.connect(server, 80) && (retries-- > 0)) {
    Serial.print(".");
  }
  Serial.println();
  if (!!!client.connected()) {
    Serial.println("Failed to connect...");
  }

  Serial.print("Request resource: ");
  Serial.println(resource);

  //First client send data on gsheet
  String jsonObject = String("{\"value1\":\"") + NAME + "\",\"value2\":\"" + ID
                      + "\"}";

  client.println(String("POST ") + resource + " HTTP/1.1");
  client.println(String("Host: ") + server);
  client.println("Connection: close\r\nContent-Type: application/json");
  client.print("Content-Length: ");
  client.println(jsonObject.length());
  client.println();
  client.println(jsonObject);

  int timeout = 5 * 10; // 5 seconds
  while (!!!client.available() && (timeout-- > 0)) {
    delay(100);
  }
  if (!!!client.available()) {
    Serial.println("No response...");
  }
  while (client.available()) {
    Serial.write(client.read());
    
    //Print on display the ID that enter
    display.clearDisplay();
    display.setCursor(20,30);
    display.println(ID);
    display.print("est entre");
    display.display();
    delay(3000);
    display.clearDisplay();
  }
  Serial.println("\nclosing connection");
  client.stop();
}

// Make an HTTP request to the IFTTT web service
// Send email when door sensor is open
void makeIFTTTRequest2() {
  Serial.print("Connecting to ");
  Serial.print(server);

  WiFiClient client;
  int retries = 5;
  while (!!!client.connect(server, 80) && (retries-- > 0)) {
    Serial.print(".");
  }
  Serial.println();
  if (!!!client.connected()) {
    Serial.println("Failed to connect...");
  }

  Serial.print("Request resource: ");
  Serial.println(resource2);

  //First client send data on gsheet
  String jsonObject = String("{\"value1\":\"") + NAME + "\",\"value2\":\"" + ID + "\"}";
  client.println(String("POST ") + resource2 + " HTTP/1.1");
  client.println(String("Host: ") + server);
  client.println("Connection: close\r\nContent-Type: application/json");
  client.print("Content-Length: ");
  client.println(jsonObject.length());
  client.println();
  client.println(jsonObject);

  int timeout = 5 * 10; // 5 seconds
  while (!!!client.available() && (timeout-- > 0)) {
    delay(100);
  }
  if (!!!client.available()) {
    Serial.println("No response...");
  }
  while (client.available()) {
    Serial.write(client.read());
    
    //Print on display the ID that enter
    display.clearDisplay();
    display.setCursor(5,30);
    display.println("Door sensor was open (IFTTT)");
    display.display();
    delay(3000);
    display.clearDisplay();
  }
  Serial.println("\nclosing connection");
  client.stop();
}

External Services

IFTTT

IFTTT is a web service that can connects apps and devices in many ways. In our case, we use webhooks that are trigger by HTTPS requests with the name of the event and the key of the account.

We create 2 webhooks, one for updating the Gsheet with information about people that are using the fingerprint system. The other webhooks is used to send an email when the door sensor is open. It allows the administrator to know if there is people at home.