Attendance System using ESP8266(Wi-Fi) with MySQL By Deligence Technologies www.deligence.com
What we will Cover? Project Description Software Required Hardware Required Node MCU V3 RFID-RC522 Circuit Diagram CODE: (Node MCU ESP8266) CODE: (PHP) Video Presentation
Project Description Here We are going to connect Node MCU ESP8266 and RFID- RC522 with MYSQL Database. So for that first we should connect our Node MCU ESP8266 Board with RFID Module. By using the RFID Module we are going to scan our RFID card and tag which are allow or not. And by using our ESP8266 we are going to send that data to our MYSQL Database which is connect through a php page. You can watch it in action in slide 20.
Software Used  Arduino IDE  LAMP Server for Linux or WAMP Server for Windows or MAMP Server for MAC OS
Hardware Used  Node MCU V3  RFID Reader with Tag  Jumper Wire
Node MCU V3 Node MCU is an open source IOT platform. It includes firmware which runs on the ESP8266 Wi-Fi SoC from hardware which is based on the ESP-12 module. The term "Node MCU" by default refers to the firmware rather than the dev kits.
RFID-RC522 RFID RC522 is a low cost and easy to use module suitable for equipment and advanced application development that needs RFID applications. RFID application. RFID stands for Radio-Frequency Identification. The acronym refers to small electronic devices that consist of a small chip and an antenna.
Circuit Diagram
CODE: (Node MCU ESP8266) #include<SoftwareSerial.h> #include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> #include <ESP8266mDNS.h> #include <SPI.h> #include <MFRC522.h> const char* ssid = "TP-LINK_28C6"; const char* password = "02105604"; //WiFiClient client; char server[] = "192.168.0.115"; //YOUR SERVER #define SS_PIN 2 //FOR RFID SS PIN BECASUSE WE ARE USING BOTH ETHERNET SHIELD AND RS-522 #define RST_PIN 15 #define No_Of_Card 3 Cont…. >>>>>
CODE: (Node MCU ESP8266) WiFiClient client; //WiFiServer server(80); SoftwareSerial mySerial(8,9); MFRC522 rfid(SS_PIN,RST_PIN); MFRC522::MIFARE_Key key; byte id[No_Of_Card][4]={ {44,153,22,219}, //RFID NO-1 {112,224,72,84}, //RFID NO-2 {151,94,80,84} //RFID NO-3 }; byte id_temp[3][3]; byte i; int j=0; Cont…. >>>>>
CODE: (Node MCU ESP8266) for(byte i=0;i<6;i++) { key.keyByte[i]=0xFF; } // Connect to WiFi network Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); Cont…. >>>>>
CODE: (Node MCU ESP8266) // Start the server // server.begin(); Serial.println("Server started"); Serial.print(WiFi.localIP()); delay(1000); Serial.println("connecting..."); } void loop() { // Check if a client has connected int m=0; if(!rfid.PICC_IsNewCardPresent()) return; if(!rfid.PICC_ReadCardSerial()) return; for(i=0;i<4;i++) { id_temp[0][i]=rfid.uid.uidByte[i]; delay(50); } Cont…. >>>>>
for(i=0;i<No_Of_Card;i++) { if(id[i][0]==id_temp[0][0]) { if(id[i][1]==id_temp[0][1]) { if(id[i][2]==id_temp[0][2]) { if(id[i][3]==id_temp[0][3]) { Serial.print("your card no :"); for(int s=0;s<4;s++) { Serial.print(rfid.uid.uidByte[s]); Serial.print(" "); } Cont…. >>>>> CODE: (Node MCU ESP8266)
CODE: (Node MCU ESP8266) Serial.println("nVALID"); Sending_To_DB(); j=0; rfid.PICC_HaltA(); rfid.PCD_StopCrypto1(); return; } } } } else {j++; if(j==No_Of_Card) { Serial.println("inVALID"); Sending_To_DB(); j=0; } } } Cont…. >>>>>
CODE: (Node MCU ESP8266) // Halt PICC rfid.PICC_HaltA(); // Stop encryption on PCD rfid.PCD_StopCrypto1(); } void Sending_To_DB() //CONNECTING WITH MYSQL { if (client.connect(server, 80)) { Serial.println("connected"); // Make a HTTP request: Serial.println("GET /rfid/rfid_read.php?allow="); //YOUR URL /rfid/rfid_read.php?allow client.print("GET /rfid/nodemcu_rfid/rfid_read.php?allow="); //YOUR URL /rfid/rfid_read.php?allow /var/www/html/rfid/rfid_read.php Cont…. >>>>>
CODE: (Node MCU ESP8266) if(j!=No_Of_Card) { Serial.println('1'); client.print('1'); } else { Serial.println('0'); client.print('0'); } Serial.println("&id="); client.print("&id="); for(int s=0;s<4;s++) { Serial.println(rfid.uid.uidByte[s]); client.print(rfid.uid.uidByte[s]); } Cont…. >>>>>
CODE: (Node MCU ESP8266) client.print(" "); //SPACE BEFORE HTTP/1.1 client.print("HTTP/1.1"); client.print("Host: "); client.println(server); client.println("Host: 192.168.0.115"); client.println("Connection: close"); client.println(); } else { // if you didn't get a connection to the server: Serial.println("connection failed"); } client.stop(); }
CODE: (PHP) <?php class rfid{ public $link=''; function __construct($allow, $id){ $this->connect(); $this->storeInDB($allow, $id); } function connect(){ $this->link = mysqli_connect('localhost','root','Deligence@1') or die('Cannot connect to the DB'); mysqli_select_db($this->link,'rfidesp') or die('Cannot select the DB'); } Cont…. >>>>>
CODE: (PHP) function storeInDB($allow, $id){ $query = "insert into rfid set rfid='".$id."', allow='".$allow."'"; $result = mysqli_query($this->link,$query) or die('Errant query: '.$query); } } if($_GET['allow'] != '' and $_GET['id'] != ''){ $rfid=new rfid($_GET['allow'],$_GET['id']); } ?>
You can get it's source code at - https://github.com/DeligenceTechnologies/ Attendance-System-using-ESP8266-Wi-Fi- with-MySQL In case, you need any Embedded Systems Development or IoT work - you can send an email to us at sales @ deligence.com Deligence Technologies – (your growing technology partner) www.deligence.com/contact-us Email : info@deligence.com Phone : +91 9910130340
Attendance System using ESP8266(Wi-Fi) with MySQL

Attendance System using ESP8266(Wi-Fi) with MySQL

  • 1.
    Attendance System usingESP8266(Wi-Fi) with MySQL By Deligence Technologies www.deligence.com
  • 2.
    What we willCover? Project Description Software Required Hardware Required Node MCU V3 RFID-RC522 Circuit Diagram CODE: (Node MCU ESP8266) CODE: (PHP) Video Presentation
  • 3.
    Project Description Here Weare going to connect Node MCU ESP8266 and RFID- RC522 with MYSQL Database. So for that first we should connect our Node MCU ESP8266 Board with RFID Module. By using the RFID Module we are going to scan our RFID card and tag which are allow or not. And by using our ESP8266 we are going to send that data to our MYSQL Database which is connect through a php page. You can watch it in action in slide 20.
  • 4.
    Software Used  ArduinoIDE  LAMP Server for Linux or WAMP Server for Windows or MAMP Server for MAC OS
  • 5.
    Hardware Used  NodeMCU V3  RFID Reader with Tag  Jumper Wire
  • 6.
    Node MCU V3 NodeMCU is an open source IOT platform. It includes firmware which runs on the ESP8266 Wi-Fi SoC from hardware which is based on the ESP-12 module. The term "Node MCU" by default refers to the firmware rather than the dev kits.
  • 7.
    RFID-RC522 RFID RC522 isa low cost and easy to use module suitable for equipment and advanced application development that needs RFID applications. RFID application. RFID stands for Radio-Frequency Identification. The acronym refers to small electronic devices that consist of a small chip and an antenna.
  • 8.
  • 9.
    CODE: (Node MCUESP8266) #include<SoftwareSerial.h> #include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> #include <ESP8266mDNS.h> #include <SPI.h> #include <MFRC522.h> const char* ssid = "TP-LINK_28C6"; const char* password = "02105604"; //WiFiClient client; char server[] = "192.168.0.115"; //YOUR SERVER #define SS_PIN 2 //FOR RFID SS PIN BECASUSE WE ARE USING BOTH ETHERNET SHIELD AND RS-522 #define RST_PIN 15 #define No_Of_Card 3 Cont…. >>>>>
  • 10.
    CODE: (Node MCUESP8266) WiFiClient client; //WiFiServer server(80); SoftwareSerial mySerial(8,9); MFRC522 rfid(SS_PIN,RST_PIN); MFRC522::MIFARE_Key key; byte id[No_Of_Card][4]={ {44,153,22,219}, //RFID NO-1 {112,224,72,84}, //RFID NO-2 {151,94,80,84} //RFID NO-3 }; byte id_temp[3][3]; byte i; int j=0; Cont…. >>>>>
  • 11.
    CODE: (Node MCUESP8266) for(byte i=0;i<6;i++) { key.keyByte[i]=0xFF; } // Connect to WiFi network Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); Cont…. >>>>>
  • 12.
    CODE: (Node MCUESP8266) // Start the server // server.begin(); Serial.println("Server started"); Serial.print(WiFi.localIP()); delay(1000); Serial.println("connecting..."); } void loop() { // Check if a client has connected int m=0; if(!rfid.PICC_IsNewCardPresent()) return; if(!rfid.PICC_ReadCardSerial()) return; for(i=0;i<4;i++) { id_temp[0][i]=rfid.uid.uidByte[i]; delay(50); } Cont…. >>>>>
  • 13.
    for(i=0;i<No_Of_Card;i++) { if(id[i][0]==id_temp[0][0]) { if(id[i][1]==id_temp[0][1]) { if(id[i][2]==id_temp[0][2]) { if(id[i][3]==id_temp[0][3]) { Serial.print("your card no:"); for(int s=0;s<4;s++) { Serial.print(rfid.uid.uidByte[s]); Serial.print(" "); } Cont…. >>>>> CODE: (Node MCU ESP8266)
  • 14.
    CODE: (Node MCUESP8266) Serial.println("nVALID"); Sending_To_DB(); j=0; rfid.PICC_HaltA(); rfid.PCD_StopCrypto1(); return; } } } } else {j++; if(j==No_Of_Card) { Serial.println("inVALID"); Sending_To_DB(); j=0; } } } Cont…. >>>>>
  • 15.
    CODE: (Node MCUESP8266) // Halt PICC rfid.PICC_HaltA(); // Stop encryption on PCD rfid.PCD_StopCrypto1(); } void Sending_To_DB() //CONNECTING WITH MYSQL { if (client.connect(server, 80)) { Serial.println("connected"); // Make a HTTP request: Serial.println("GET /rfid/rfid_read.php?allow="); //YOUR URL /rfid/rfid_read.php?allow client.print("GET /rfid/nodemcu_rfid/rfid_read.php?allow="); //YOUR URL /rfid/rfid_read.php?allow /var/www/html/rfid/rfid_read.php Cont…. >>>>>
  • 16.
    CODE: (Node MCUESP8266) if(j!=No_Of_Card) { Serial.println('1'); client.print('1'); } else { Serial.println('0'); client.print('0'); } Serial.println("&id="); client.print("&id="); for(int s=0;s<4;s++) { Serial.println(rfid.uid.uidByte[s]); client.print(rfid.uid.uidByte[s]); } Cont…. >>>>>
  • 17.
    CODE: (Node MCUESP8266) client.print(" "); //SPACE BEFORE HTTP/1.1 client.print("HTTP/1.1"); client.print("Host: "); client.println(server); client.println("Host: 192.168.0.115"); client.println("Connection: close"); client.println(); } else { // if you didn't get a connection to the server: Serial.println("connection failed"); } client.stop(); }
  • 18.
    CODE: (PHP) <?php class rfid{ public$link=''; function __construct($allow, $id){ $this->connect(); $this->storeInDB($allow, $id); } function connect(){ $this->link = mysqli_connect('localhost','root','Deligence@1') or die('Cannot connect to the DB'); mysqli_select_db($this->link,'rfidesp') or die('Cannot select the DB'); } Cont…. >>>>>
  • 19.
    CODE: (PHP) function storeInDB($allow,$id){ $query = "insert into rfid set rfid='".$id."', allow='".$allow."'"; $result = mysqli_query($this->link,$query) or die('Errant query: '.$query); } } if($_GET['allow'] != '' and $_GET['id'] != ''){ $rfid=new rfid($_GET['allow'],$_GET['id']); } ?>
  • 20.
    You can getit's source code at - https://github.com/DeligenceTechnologies/ Attendance-System-using-ESP8266-Wi-Fi- with-MySQL In case, you need any Embedded Systems Development or IoT work - you can send an email to us at sales @ deligence.com Deligence Technologies – (your growing technology partner) www.deligence.com/contact-us Email : info@deligence.com Phone : +91 9910130340