IoT Based Biometric Door Lock using Fingerprint Sensor and NodeMCU ESP8266

IoT Based Biometric Door Lock using Fingerprint Sensor and NodeMCU ESP8266

0 comments / Posted on by Quartz Components

IoT Based Biometric Door Lock using Fingerprint Sensor and NodeMCU ESP8266

Fingerprint scanner sensors are used at many places like Industries, Offices, Schools, Colleges and Hotels. By embedding IoT with the Fingerprint sensor, we can elevate the Fingerprint-based security system project to the next level.

So in this project tutorial, we are going to build and IoT Based Biometric Security System using the GT5111C3 fingerprint sensor, NodeMCU and Solenoid lock. Adafruit IO is used to save the entry details online while IFTTT is used to send the Email notifications when an unauthorised person scans the finger on the fingerprint sensor.

 

Components Required

 

GT511C3 Fingerprint Sensor Module

GT-511C3 Fingerprint Scanner Sensor module

The GT-511C3 Fingerprint Scanner Sensor module consists of an optical sensor mounted on a small circuit board. The optical sensor scans a fingerprint and ARM Microcontroller coupled with EEPROM processes the scanned fingerprint. GT-511C3 module can store 200 fingerprints. Each fingerprint is saved with a different ID. Operating voltage for GT-511C3 is from 3.3V to 6V.

GT511C3 Fingerprint Sensor Module Pinout

 

Solenoid Lock

Solenoid lock work on the electronic-mechanical locking mechanism. This solenoid lock has a slug with a slanted cut and a good mounting bracket. In normal conditions slug remains outside the bracket but when DC voltage is applied slug moves inside the bracket. Ideal Operating voltage for the solenoid lock is 12V. It can be used with 9V, but it results in slower operation.

 

 

IoT Biometric Security System Circuit Diagram

Circuit Diagram for Smart Door Lock using Fingerprint Sensor and NodeMCU

The circuit for IoT based Biometric Security System consists of a NodeMCU, GT511C3 Fingerprint Sensor, Solenoid Lock, Relay Module and Buzzer. VCC and GND pin of Fingerprint sensor are connected to 3.3V and GND pin of NodeMCU while TX and RX pins are connected to D6 and D5 pins of NodeMCU. Positive pin of the buzzer is connected to D2 pin of NodeMCU, and the negative pin is connected to GND of NodeMCU. The solenoid lock is connected to NodeMCU through the relay module. The NodeMCU and Solenoid Lock both are powered with 12V Adapter.

 

Adafruit IO Setup

Adafruit IO is an IoT platform that allows you to visualise, and analyse live data on the cloud.  Using Adafruit IO, you can control motors, read sensor data, and make cool IoT applications over the internet. In this project, we are sending the Entry details to Adafruit IO Dashboard.

  1. To send data to, you need to create on Adafruit IO if you don’t have one. For this, navigate to  Adafruit IO website and click on ‘Get started for Free’ on the top right of the screen.

Adafruit IoT Setup for Smart Door Lock

Adafruit username and AIO key are required to send data to Adafruit IO. For that click on ‘View AIO Key’ on the top right corner to get your account username and AIO key

Adafruit IoT Key

 After getting the AIO key, create a feed. For that click on ‘Feeds.’ Then click on ‘Actions,’ you will see some options from them click on ‘Create a New Feed.’

AIO New Feed

All your data will be stored in this feed. You can also create an Adafruit IO dashboard for customised visualisation of your data.

 

IFTTT Setup

Here we are using IFTTT to send Email notifications when an unauthorised person scans his finger on the fingerprint sensor. IFTTT (If This Then That) is a web-based service by which we can create chains of conditional statements, called applets. Using these applets, we can send Emails, Twitter, Facebook notifications.

To use the IFTTT sign in to your IFTTT account if you already have one or create an account.

Now search for ‘Webhooks’ and click on the Webhooks in Services section.

IFTTT Setup

Now, in the Webhooks window, click on ‘Documentation’ in the upper right corner to get the private key.

Copy this key. It will be used in the program.

IFTTT key

After getting the private key now, we will create an applet using Webhooks and Email services. To create an applet, click on your profile and then click on ‘Create.’

Create Applet for IoT Biometric Door Lock

 Now in the next window, click on the ‘This’ icon.

Create This for IoT Door Lock using Fingerprint Sensor

Now search for Webhooks in the search section and click on ‘Webhooks.’

Choose a trigger

Now choose ‘Receive a Web Request’ trigger and in the next window, enter the event name as login_event and then click on create trigger.

create trigger

After this, click on ‘Then That’ and then click on Email.

Choose action service

Now in Email, click on ‘send me an email’ and enter the email subject and body and then click on create action.

 

How to Enrol a Fingerprint

Before programming the NodeMCU for Fingerprint based security system we first have to enrol fingerprints into GT511C3 fingerprint sensor. For that download the FPS_GT511C3 library and add it to your Arduino IDE.

Fingerprint Sensor Library for Arduino IDE

After that restart your IDE and go to File > Example > Fingerprint Scanner TTL > FPS_Enroll

 

Upload the FPS_Enroll program into your NodeMCU.

 

IoT Based Biometric Security System Arduino Code Explanation

In this project, NodeMCU is programmed using the Arduino IDE. So, make sure you have downloaded NodeMCU board files in Arduino IDE. If you are new to this and don’t know how to install the NodeMCU board files in Arduino IDE, then follow this article.

Programming NodeMCU Using Arduino IDE

Complete code for IoT Based Biometric Security System is given at the end of the page.

Start the code by including all the required library files. Here the FPS_GT511C3 library is used for the Fingerprint module, and Adafruit MQTT library is used for MQTT communication between NodeMCU and Adafruit IO.

#include "FPS_GT511C3.h"

#include "SoftwareSerial.h"

#include <ESP8266WiFi.h>

#include "Adafruit_MQTT.h"

#include "Adafruit_MQTT_Client.h"

 

After that enter the Wi-Fi credential and password with the Adafruit IO username, AIO Key and IFTTT Private key.

 

const char *ssid =  "Galaxy-M20";     // Enter your WiFi Name

const char *pass =  "ac312124"; // Enter your WiFi Password

#define MQTT_SERV "io.adafruit.com"

#define MQTT_PORT 1883

#define MQTT_NAME "Enter Your Adafruit IO Username"

#define MQTT_PASS "Enter the AIO Key"

const char *host = "maker.ifttt.com";

const char *privateKey = "Enter the IFTTT Key";

 

Set up the feed you're publishing to. Here ‘Fingerprint is the feed name’, change it with your feed name.

 

Adafruit_MQTT_Client mqtt(&client, MQTT_SERV, MQTT_PORT, MQTT_NAME, MQTT_PASS);

Adafruit_MQTT_Publish Fingerprint = Adafruit_MQTT_Publish(&mqtt,MQTT_NAME "/f/Fingerprint");

 

Inside the void loop function check the scanned fingerprint and if it matches with the enrolled fingerprint then open the solenoid lock and publish the person’s name on the Adafruit IO dashboard.

if (id ==7) //<- change id value depending model you are using

     {

      Serial.print("Ashish Entered");

      Buzzer();

      digitalWrite(relay, HIGH);

      delay(6000);

      digitalWrite(relay, LOW);

      msg = "Ashish Entered";

      msg.toCharArray(msg1, 20);

      if (! Fingerprint.publish(msg1))

        {                     

         //delay(7000);   

          }

         }

     else if (id ==8)

       {

        Serial.print("Manoj Entered");

        Buzzer();

        digitalWrite(relay, HIGH);

        delay(6000);

        digitalWrite(relay, LOW);

        msg = "Manoj Entered";

        msg.toCharArray(msg1, 20);

        if (! Fingerprint.publish(msg1))

        {                     

          }

       }

 

And if the scanned fingerprint doesn’t match with enrolled fingerprint then send an email to the mentioned email address using the IFTTT trigger.

else

      {//if unable to recognize

       send_event("login_event");

       Serial.println("Finger not found");

       for(int i = 7; i > 0; i--){

        digitalWrite(buzzer, HIGH);

        delay(100);

        digitalWrite(buzzer, LOW);

        delay(100);

       }

 

Testing the IoT Based Biometric Security Door Lock Project

Once the Code and Hardware are ready, we can check if everything is working or not. Upload the code to NodeMCU and connect it to Adapter. Now, wait for Wi-Fi connection. Once the NodeMCU connects to the Wi-Fi, scan your finger on the fingerprint sensor. If the finger is enrolled, then it will open the lock with a beep sound, and it will send a message with the person’s name to Adafruit IO. And if the finger isn’t enrolled, then it will send an email to the associated email address that an unauthorised person tried to enter.

 

Complete Arduino IDE Code for IoT Smart Fingerprint Door Lock

#include "FPS_GT511C3.h"
#include "SoftwareSerial.h"
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"

const char *ssid = "Galaxy-M20"; // Enter your WiFi Name
const char *pass = "ac312124"; // Enter your WiFi Password

String msg;
char msg1[20];
WiFiClient client;

#define MQTT_SERV "io.adafruit.com"
#define MQTT_PORT 1883
#define MQTT_NAME "choudharyas"
#define MQTT_PASS "988c4e045ef64c1b9bc8b5bb7ef5f2d9"

void send_event(const char *event);
const char *host = "maker.ifttt.com";
const char *privateKey = "hUAAAz0AVvc6-NW1UmqWXXv6VQWmpiGFxx3sV5rnaM9";


FPS_GT511C3 fps(D6, D5);
#define relay D1
#define buzzer D2

Adafruit_MQTT_Client mqtt(&client, MQTT_SERV, MQTT_PORT, MQTT_NAME, MQTT_PASS);
//Set up the feed you'r publishing to
Adafruit_MQTT_Publish Fingerprint = Adafruit_MQTT_Publish(&mqtt,MQTT_NAME "/f/Fingerprint");


void setup()
{
Serial.begin(9600); //set up Arduino's hardware serial UART
delay(100);
fps.Open(); //send serial command to initialize fps
fps.SetLED(true); //turn on LED so fps can see fingerprint
pinMode(relay, OUTPUT);
pinMode(buzzer, OUTPUT);
digitalWrite(relay, LOW); // keep motor off initally

Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print("."); // print ... till not connected
}
Serial.println("");
Serial.println("WiFi connected");
}

void loop()
{
MQTT_connect();
// Identify fingerprint test
if (fps.IsPressFinger())
{
fps.CaptureFinger(false);
int id = fps.Identify1_N();

if (id ==7) //<- change id value depending model you are using
{
Serial.print("Ashish Entered");
Buzzer();
digitalWrite(relay, HIGH);
delay(6000);
digitalWrite(relay, LOW);
msg = "Ashish Entered";
msg.toCharArray(msg1, 20);
if (! Fingerprint.publish(msg1))
{
//delay(7000);
}
}
else if (id ==8)
{
Serial.print("Manoj Entered");
Buzzer();
digitalWrite(relay, HIGH);
delay(6000);
digitalWrite(relay, LOW);
msg = "Manoj Entered";
msg.toCharArray(msg1, 20);
if (! Fingerprint.publish(msg1))
{
//delay(7000);
}
}

else if (id ==9)
{
Serial.print("Aswinth Entered");
Buzzer();
digitalWrite(relay, HIGH);
delay(6000);
digitalWrite(relay, LOW);
msg = "Aswinth Entered";
msg.toCharArray(msg1, 20);
if (! Fingerprint.publish(msg1))
{
//delay(7000);
}
}


else
{//if unable to recognize
send_event("login_event");
Serial.println("Finger not found");
for(int i = 7; i > 0; i--){
digitalWrite(buzzer, HIGH);
delay(100);
digitalWrite(buzzer, LOW);
delay(100);
}

}
}
else
{
Serial.println("Please press finger");
}
delay(100);


}

void send_event(const char *event)
{
Serial.print("Connecting to ");
Serial.println(host);

// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("Connection failed");
return;
}

// We now create a URI for the request
String url = "/trigger/";
url += event;
url += "/with/key/";
url += privateKey;

Serial.print("Requesting URL: ");
Serial.println(url);

// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
while(client.connected())
{
if(client.available())
{
String line = client.readStringUntil('\r');
Serial.print(line);
} else {
// No data yet, wait a bit
delay(50);
};
}

Serial.println();
Serial.println("closing connection");
client.stop();
}

void MQTT_connect()
{
int8_t ret;

// Stop if already connected.
if (mqtt.connected())
{
return;
}

uint8_t retries = 3;
while ((ret = mqtt.connect()) != 0) // connect will return 0 for connected
{

mqtt.disconnect();
delay(5000); // wait 5 seconds
retries--;
if (retries == 0)
{
// basically die and wait for WDT to reset me
while (1);
}
}
}

void Buzzer()
{
digitalWrite(buzzer, HIGH);
delay(1000);
digitalWrite(buzzer, LOW);
}

Fingerprint scanner sensors are used at many places like Industries, Offices, Schools, Colleges and Hotels. By embedding IoT with the Fingerprint sensor, we can elevate the Fingerprint-based security system project to the next level.

So in this project tutorial, we are going to build and IoT Based Biometric Security System using the GT5111C3 fingerprint sensor, NodeMCU and Solenoid lock. Adafruit IO is used to save the entry details online while IFTTT is used to send the Email notifications when an unauthorised person scans the finger on the fingerprint sensor.

 

Components Required

 

GT511C3 Fingerprint Sensor Module

GT-511C3 Fingerprint Scanner Sensor module

The GT-511C3 Fingerprint Scanner Sensor module consists of an optical sensor mounted on a small circuit board. The optical sensor scans a fingerprint and ARM Microcontroller coupled with EEPROM processes the scanned fingerprint. GT-511C3 module can store 200 fingerprints. Each fingerprint is saved with a different ID. Operating voltage for GT-511C3 is from 3.3V to 6V.

GT511C3 Fingerprint Sensor Module Pinout

 

Solenoid Lock

Solenoid lock work on the electronic-mechanical locking mechanism. This solenoid lock has a slug with a slanted cut and a good mounting bracket. In normal conditions slug remains outside the bracket but when DC voltage is applied slug moves inside the bracket. Ideal Operating voltage for the solenoid lock is 12V. It can be used with 9V, but it results in slower operation.

 

 

IoT Biometric Security System Circuit Diagram

Circuit Diagram for Smart Door Lock using Fingerprint Sensor and NodeMCU

The circuit for IoT based Biometric Security System consists of a NodeMCU, GT511C3 Fingerprint Sensor, Solenoid Lock, Relay Module and Buzzer. VCC and GND pin of Fingerprint sensor are connected to 3.3V and GND pin of NodeMCU while TX and RX pins are connected to D6 and D5 pins of NodeMCU. Positive pin of the buzzer is connected to D2 pin of NodeMCU, and the negative pin is connected to GND of NodeMCU. The solenoid lock is connected to NodeMCU through the relay module. The NodeMCU and Solenoid Lock both are powered with 12V Adapter.

 

Adafruit IO Setup

Adafruit IO is an IoT platform that allows you to visualise, and analyse live data on the cloud.  Using Adafruit IO, you can control motors, read sensor data, and make cool IoT applications over the internet. In this project, we are sending the Entry details to Adafruit IO Dashboard.

  1. To send data to, you need to create on Adafruit IO if you don’t have one. For this, navigate to  Adafruit IO website and click on ‘Get started for Free’ on the top right of the screen.

Adafruit IoT Setup for Smart Door Lock

Adafruit username and AIO key are required to send data to Adafruit IO. For that click on ‘View AIO Key’ on the top right corner to get your account username and AIO key

Adafruit IoT Key

 After getting the AIO key, create a feed. For that click on ‘Feeds.’ Then click on ‘Actions,’ you will see some options from them click on ‘Create a New Feed.’

AIO New Feed

All your data will be stored in this feed. You can also create an Adafruit IO dashboard for customised visualisation of your data.

 

IFTTT Setup

Here we are using IFTTT to send Email notifications when an unauthorised person scans his finger on the fingerprint sensor. IFTTT (If This Then That) is a web-based service by which we can create chains of conditional statements, called applets. Using these applets, we can send Emails, Twitter, Facebook notifications.

To use the IFTTT sign in to your IFTTT account if you already have one or create an account.

Now search for ‘Webhooks’ and click on the Webhooks in Services section.

IFTTT Setup

Now, in the Webhooks window, click on ‘Documentation’ in the upper right corner to get the private key.

Copy this key. It will be used in the program.

IFTTT key

After getting the private key now, we will create an applet using Webhooks and Email services. To create an applet, click on your profile and then click on ‘Create.’

Create Applet for IoT Biometric Door Lock

 Now in the next window, click on the ‘This’ icon.

Create This for IoT Door Lock using Fingerprint Sensor

Now search for Webhooks in the search section and click on ‘Webhooks.’

Choose a trigger

Now choose ‘Receive a Web Request’ trigger and in the next window, enter the event name as login_event and then click on create trigger.

create trigger

After this, click on ‘Then That’ and then click on Email.

Choose action service

Now in Email, click on ‘send me an email’ and enter the email subject and body and then click on create action.

 

How to Enrol a Fingerprint

Before programming the NodeMCU for Fingerprint based security system we first have to enrol fingerprints into GT511C3 fingerprint sensor. For that download the FPS_GT511C3 library and add it to your Arduino IDE.

Fingerprint Sensor Library for Arduino IDE

After that restart your IDE and go to File > Example > Fingerprint Scanner TTL > FPS_Enroll

 

Upload the FPS_Enroll program into your NodeMCU.

 

IoT Based Biometric Security System Arduino Code Explanation

In this project, NodeMCU is programmed using the Arduino IDE. So, make sure you have downloaded NodeMCU board files in Arduino IDE. If you are new to this and don’t know how to install the NodeMCU board files in Arduino IDE, then follow this article.

Programming NodeMCU Using Arduino IDE

Complete code for IoT Based Biometric Security System is given at the end of the page.

Start the code by including all the required library files. Here the FPS_GT511C3 library is used for the Fingerprint module, and Adafruit MQTT library is used for MQTT communication between NodeMCU and Adafruit IO.

#include "FPS_GT511C3.h"

#include "SoftwareSerial.h"

#include <ESP8266WiFi.h>

#include "Adafruit_MQTT.h"

#include "Adafruit_MQTT_Client.h"

 

After that enter the Wi-Fi credential and password with the Adafruit IO username, AIO Key and IFTTT Private key.

 

const char *ssid =  "Galaxy-M20";     // Enter your WiFi Name

const char *pass =  "ac312124"; // Enter your WiFi Password

#define MQTT_SERV "io.adafruit.com"

#define MQTT_PORT 1883

#define MQTT_NAME "Enter Your Adafruit IO Username"

#define MQTT_PASS "Enter the AIO Key"

const char *host = "maker.ifttt.com";

const char *privateKey = "Enter the IFTTT Key";

 

Set up the feed you're publishing to. Here ‘Fingerprint is the feed name’, change it with your feed name.

 

Adafruit_MQTT_Client mqtt(&client, MQTT_SERV, MQTT_PORT, MQTT_NAME, MQTT_PASS);

Adafruit_MQTT_Publish Fingerprint = Adafruit_MQTT_Publish(&mqtt,MQTT_NAME "/f/Fingerprint");

 

Inside the void loop function check the scanned fingerprint and if it matches with the enrolled fingerprint then open the solenoid lock and publish the person’s name on the Adafruit IO dashboard.

if (id ==7) //<- change id value depending model you are using

     {

      Serial.print("Ashish Entered");

      Buzzer();

      digitalWrite(relay, HIGH);

      delay(6000);

      digitalWrite(relay, LOW);

      msg = "Ashish Entered";

      msg.toCharArray(msg1, 20);

      if (! Fingerprint.publish(msg1))

        {                     

         //delay(7000);   

          }

         }

     else if (id ==8)

       {

        Serial.print("Manoj Entered");

        Buzzer();

        digitalWrite(relay, HIGH);

        delay(6000);

        digitalWrite(relay, LOW);

        msg = "Manoj Entered";

        msg.toCharArray(msg1, 20);

        if (! Fingerprint.publish(msg1))

        {                     

          }

       }

 

And if the scanned fingerprint doesn’t match with enrolled fingerprint then send an email to the mentioned email address using the IFTTT trigger.

else

      {//if unable to recognize

       send_event("login_event");

       Serial.println("Finger not found");

       for(int i = 7; i > 0; i--){

        digitalWrite(buzzer, HIGH);

        delay(100);

        digitalWrite(buzzer, LOW);

        delay(100);

       }

 

Testing the IoT Based Biometric Security Door Lock Project

Once the Code and Hardware are ready, we can check if everything is working or not. Upload the code to NodeMCU and connect it to Adapter. Now, wait for Wi-Fi connection. Once the NodeMCU connects to the Wi-Fi, scan your finger on the fingerprint sensor. If the finger is enrolled, then it will open the lock with a beep sound, and it will send a message with the person’s name to Adafruit IO. And if the finger isn’t enrolled, then it will send an email to the associated email address that an unauthorised person tried to enter.

 

Complete Arduino IDE Code for IoT Smart Fingerprint Door Lock

#include "FPS_GT511C3.h"
#include "SoftwareSerial.h"
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"

const char *ssid = "Galaxy-M20"; // Enter your WiFi Name
const char *pass = "ac312124"; // Enter your WiFi Password

String msg;
char msg1[20];
WiFiClient client;

#define MQTT_SERV "io.adafruit.com"
#define MQTT_PORT 1883
#define MQTT_NAME "choudharyas"
#define MQTT_PASS "988c4e045ef64c1b9bc8b5bb7ef5f2d9"

void send_event(const char *event);
const char *host = "maker.ifttt.com";
const char *privateKey = "hUAAAz0AVvc6-NW1UmqWXXv6VQWmpiGFxx3sV5rnaM9";


FPS_GT511C3 fps(D6, D5);
#define relay D1
#define buzzer D2

Adafruit_MQTT_Client mqtt(&client, MQTT_SERV, MQTT_PORT, MQTT_NAME, MQTT_PASS);
//Set up the feed you'r publishing to
Adafruit_MQTT_Publish Fingerprint = Adafruit_MQTT_Publish(&mqtt,MQTT_NAME "/f/Fingerprint");


void setup()
{
Serial.begin(9600); //set up Arduino's hardware serial UART
delay(100);
fps.Open(); //send serial command to initialize fps
fps.SetLED(true); //turn on LED so fps can see fingerprint
pinMode(relay, OUTPUT);
pinMode(buzzer, OUTPUT);
digitalWrite(relay, LOW); // keep motor off initally

Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print("."); // print ... till not connected
}
Serial.println("");
Serial.println("WiFi connected");
}

void loop()
{
MQTT_connect();
// Identify fingerprint test
if (fps.IsPressFinger())
{
fps.CaptureFinger(false);
int id = fps.Identify1_N();

if (id ==7) //<- change id value depending model you are using
{
Serial.print("Ashish Entered");
Buzzer();
digitalWrite(relay, HIGH);
delay(6000);
digitalWrite(relay, LOW);
msg = "Ashish Entered";
msg.toCharArray(msg1, 20);
if (! Fingerprint.publish(msg1))
{
//delay(7000);
}
}
else if (id ==8)
{
Serial.print("Manoj Entered");
Buzzer();
digitalWrite(relay, HIGH);
delay(6000);
digitalWrite(relay, LOW);
msg = "Manoj Entered";
msg.toCharArray(msg1, 20);
if (! Fingerprint.publish(msg1))
{
//delay(7000);
}
}

else if (id ==9)
{
Serial.print("Aswinth Entered");
Buzzer();
digitalWrite(relay, HIGH);
delay(6000);
digitalWrite(relay, LOW);
msg = "Aswinth Entered";
msg.toCharArray(msg1, 20);
if (! Fingerprint.publish(msg1))
{
//delay(7000);
}
}


else
{//if unable to recognize
send_event("login_event");
Serial.println("Finger not found");
for(int i = 7; i > 0; i--){
digitalWrite(buzzer, HIGH);
delay(100);
digitalWrite(buzzer, LOW);
delay(100);
}

}
}
else
{
Serial.println("Please press finger");
}
delay(100);


}

void send_event(const char *event)
{
Serial.print("Connecting to ");
Serial.println(host);

// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("Connection failed");
return;
}

// We now create a URI for the request
String url = "/trigger/";
url += event;
url += "/with/key/";
url += privateKey;

Serial.print("Requesting URL: ");
Serial.println(url);

// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
while(client.connected())
{
if(client.available())
{
String line = client.readStringUntil('\r');
Serial.print(line);
} else {
// No data yet, wait a bit
delay(50);
};
}

Serial.println();
Serial.println("closing connection");
client.stop();
}

void MQTT_connect()
{
int8_t ret;

// Stop if already connected.
if (mqtt.connected())
{
return;
}

uint8_t retries = 3;
while ((ret = mqtt.connect()) != 0) // connect will return 0 for connected
{

mqtt.disconnect();
delay(5000); // wait 5 seconds
retries--;
if (retries == 0)
{
// basically die and wait for WDT to reset me
while (1);
}
}
}

void Buzzer()
{
digitalWrite(buzzer, HIGH);
delay(1000);
digitalWrite(buzzer, LOW);
}

0 comments

Leave a comment

All blog comments are checked prior to publishing