0% found this document useful (0 votes)
10 views6 pages

spreedsheet

The document contains code for an RFID attendance system using the MFRC522 module and Wi-Fi connectivity. It includes functions to read the UID from RFID cards, convert byte arrays to strings, and send HTTP requests to a Google Apps Script Web App for attendance registration. The setup initializes the RFID reader and Wi-Fi connection, while the loop continuously checks for RFID card presence and processes attendance data accordingly.

Uploaded by

ayusharya77447
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views6 pages

spreedsheet

The document contains code for an RFID attendance system using the MFRC522 module and Wi-Fi connectivity. It includes functions to read the UID from RFID cards, convert byte arrays to strings, and send HTTP requests to a Google Apps Script Web App for attendance registration. The setup initializes the RFID reader and Wi-Fi connection, while the loop continuously checks for RFID card presence and processes attendance data accordingly.

Uploaded by

ayusharya77447
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

https://docs.google.

com/spreadsheets/d/1zzDhmtr_TNMsatd-
MZtL9K7HYNH5il4AWW8KDsTLkZE/edit?gid=0#gid=0
https://docs.google.com/spreadsheets/d/1zzDhmtr_TNMsatd-
MZtL9K7HYNH5il4AWW8KDsTLkZE/edit?gid=1540099858#gid=1540099858
#include <deprecated.h>
#include <MFRC522.h>
#include <MFRC522Extended.h>
#include <require_cpp11.h>

//
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>> 01_Test_RFID-RC522_Serial
// This code only takes the UID in string form.
// If you want to see more detailed information about an RFID card or keychain,
please run the program code "DumpInfo".
// The "DumpInfo" program code is located at :
// Library folder "MFRC522" -> "examples" folder -> "DumpInfo" folder ->
DumpInfo.ino
// or
// From Arduino IDE : File -> Examples -> MFRC522 -> DumpInfo
// or
// From Arduino IDE : File -> Examples -> INCOMPATIBLE-> MFRC522 -> DumpInfo

//----------------------------------------Including the libraries.


#include <SPI.h>
#include <MFRC522.h>
//----------------------------------------

// Defines SS/SDA PIN and Reset PIN for RFID-RC522.


#define SS_PIN 5
#define RST_PIN 4

// Variable to read data from RFID-RC522.


int readsuccess;
char str[32] = "";
String UID_Result = "";

// Create MFRC522 object as "mfrc522" and set SS/SDA PIN and Reset PIN.
MFRC522 mfrc522(SS_PIN, RST_PIN);

//
________________________________________________________________________________get
UID()
// Subroutine to obtain UID/ID when RFID card or RFID keychain is tapped to RFID-
RC522 module.
int getUID() {
if(!mfrc522.PICC_IsNewCardPresent()) {
return 0;
}
if(!mfrc522.PICC_ReadCardSerial()) {
return 0;
}

byteArray_to_string(mfrc522.uid.uidByte, mfrc522.uid.size, str);


UID_Result = str;

mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
return 1;
}
//________________________________________________________________________________

//
________________________________________________________________________________byt
eArray_to_string()
void byteArray_to_string(byte array[], unsigned int len, char buffer[]) {
for (unsigned int i = 0; i < len; i++) {
byte nib1 = (array[i] >> 4) & 0x0F;
byte nib2 = (array[i] >> 0) & 0x0F;
buffer[i*2+0] = nib1 < 0xA ? '0' + nib1 : 'A' + nib1 - 0xA;
buffer[i*2+1] = nib2 < 0xA ? '0' + nib2 : 'A' + nib2 - 0xA;
}
buffer[len*2] = '\0';
}
//________________________________________________________________________________

//
________________________________________________________________________________VOI
D SETUP()
void setup(){
// put your setup code here, to run once:

Serial.begin(115200);
Serial.println();
delay(1000);

// Init SPI bus.


SPI.begin();
// Init MFRC522.
mfrc522.PCD_Init();

delay(1000);

Serial.println();
Serial.println("Please tap your card or key chain to the RFID-RC522 module.");
}
//________________________________________________________________________________

//
________________________________________________________________________________VOI
D LOOP()
void loop(){
// put your main code here, to run repeatedly:

readsuccess = getUID();

if(readsuccess){
Serial.println();
Serial.print("UID : ");
Serial.println(UID_Result);
delay(500);
}
delay(10);
}
//________________________________________________________________________________
//
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<<<<<<

endiiiiingggendiiiiingggendiiiiingggendiiiiingggendiiiiingggendiiiiingggendiiiiingg
g

#include <SPI.h>
#include <MFRC522.h>
#include <WiFi.h>
#include <HTTPClient.h>

// Define RFID-RC522 pins


#define SS_PIN 5
#define RST_PIN 4

// Wi-Fi credentials
const char* ssid = "THIRD FLOOR -4G";
const char* password = "abcd@123";

// Google Apps Script Web App URL


String Web_App_URL =
"https://script.google.com/macros/s/AKfycbzlZ0kK8mI94HKehfhr9RhFdpZ2vVxxh6B2Yzwfon2
0IlBslWn2FqPA8r8uwP2-PheDyg/exec";

// Variables for RFID


MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
char str[32] = "";
String UID_Result = "";

// Mode: "atc" for attendance, "reg" for registration


String modes = "atc";

// Function to convert byte array to string


void byteArray_to_string(byte array[], unsigned int len, char buffer[]) {
for (unsigned int i = 0; i < len; i++) {
byte nib1 = (array[i] >> 4) & 0x0F;
byte nib2 = (array[i] >> 0) & 0x0F;
buffer[i*2+0] = nib1 < 0xA ? '0' + nib1 : 'A' + nib1 - 0xA;
buffer[i*2+1] = nib2 < 0xA ? '0' + nib2 : 'A' + nib2 - 0xA;
}
buffer[len*2] = '\0';
}

// Function to get UID from RFID


int getUID() {
if(!mfrc522.PICC_IsNewCardPresent()) {
return 0;
}
if(!mfrc522.PICC_ReadCardSerial()) {
return 0;
}

byteArray_to_string(mfrc522.uid.uidByte, mfrc522.uid.size, str);


UID_Result = str;

mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();

return 1;
}

// Function to split string by separator


String getValue(String data, char separator, int index) {
int found = 0;
int strIndex[] = { 0, -1 };
int maxIndex = data.length() - 1;

for (int i = 0; i <= maxIndex && found <= index; i++) {


if (data.charAt(i) == separator || i == maxIndex) {
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i+1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}

// Function to send HTTP request to Google Sheets


void http_Req(String str_modes, String str_uid) {
if (WiFi.status() == WL_CONNECTED) {
String http_req_url = "";

// Create URL based on mode


if (str_modes == "atc") {
http_req_url = Web_App_URL + "?sts=atc";
http_req_url += "&uid=" + str_uid;
}
if (str_modes == "reg") {
http_req_url = Web_App_URL + "?sts=reg";
http_req_url += "&uid=" + str_uid;
}

Serial.println();
Serial.println("-------------");
Serial.println("Sending request to Google Sheets...");
Serial.print("URL : ");
Serial.println(http_req_url);

HTTPClient http;
http.begin(http_req_url.c_str());
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);

int httpCode = http.GET();


Serial.print("HTTP Status Code : ");
Serial.println(httpCode);

String payload;
if (httpCode > 0) {
payload = http.getString();
Serial.println("Payload : " + payload);
}

Serial.println("-------------");
http.end();

String sts_Res = getValue(payload, ',', 0);

if (sts_Res == "OK") {
String atc_Info = getValue(payload, ',', 1);

if (atc_Info == "TI_Successful") {
String atc_Name = getValue(payload, ',', 2);
String atc_Date = getValue(payload, ',', 3);
String atc_Time_In = getValue(payload, ',', 4);
Serial.println("Time In Recorded:");
Serial.println("Name: " + atc_Name);
Serial.println("Date: " + atc_Date);
Serial.println("Time In: " + atc_Time_In);
}

if (atc_Info == "TO_Successful") {
String atc_Name = getValue(payload, ',', 2);
String atc_Date = getValue(payload, ',', 3);
String atc_Time_In = getValue(payload, ',', 4);
String atc_Time_Out = getValue(payload, ',', 5);
Serial.println("Time Out Recorded:");
Serial.println("Name: " + atc_Name);
Serial.println("Date: " + atc_Date);
Serial.println("Time In: " + atc_Time_In);
Serial.println("Time Out: " + atc_Time_Out);
}
}
}
}

void setup(){
Serial.begin(115200);
Serial.println();
delay(1000);

SPI.begin();
mfrc522.PCD_Init();

Serial.println();
Serial.println("-------------");
Serial.println("WIFI mode : STA");
WiFi.mode(WIFI_STA);
Serial.println("-------------");

Serial.println();
Serial.println("------------");
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);

int connecting_process_timed_out = 20; // 20 seconds timeout


connecting_process_timed_out = connecting_process_timed_out * 2;
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
if (connecting_process_timed_out > 0) connecting_process_timed_out--;
if (connecting_process_timed_out == 0) {
delay(1000);
ESP.restart();
}
}
Serial.println();
Serial.println("WiFi connected");
Serial.println("------------");
}

void loop(){
if (getUID()) {
Serial.println("UID: " + UID_Result);
http_Req(modes, UID_Result);
delay(2000); // Delay to prevent multiple reads
}
}

You might also like