Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 3 | ||||
| × | 20 | ||||
| × | 2 | ||||
| × | 1 | ||||
| × | 2 | ||||
| × | 2 | ||||
| × | 20 | ||||
| × | 1 | ||||
Software apps and online services | ||||||
| ||||||
| ||||||
|
In colleges and schools we have seen the usage of registers for making the entry when someone leaves the campus or enters inside the campus. This project uses RFID technology to mark the entry on a web page. See the videos for complete understanding.
void setup()
{
Serial.begin(9600);// Initiate a serial communication
SPI.begin(); // Initiate SPI bus
ESP.wdtEnable(4);
client.setServer(mqtt_server,1883);
client.setCallback(callback);
ESP.wdtDisable();
pinMode(2,INPUT);
pinMode(3,OUTPUT);
pinMode(0,INPUT);
pinMode(16,OUTPUT);
pinMode(15,OUTPUT);
pinMode(10,OUTPUT);
mfrc522.PCD_Init();// Initiate MFRC522
WiFi.begin(ssid, wifi_password);
// Wait until the connection has been confirmed before continuing
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
if (client.connect(clientID)) {
Serial.println("Connected to MQTT Broker!");
}
else {
Serial.println("Connection to MQTT Broker failed...");
}
}
void loop()
{
client.loop();
// Look for new cards
digitalWrite(3,LOW);
digitalWrite(16,LOW);
digitalWrite(15,LOW);
digitalWrite(10,HIGH);
while(!initcard())ESP.wdtFeed();
//Show UID on serial monitor
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
content.toUpperCase();
data+="{";
data+="\'";
data+="ID";
data+="\'";
data+=":";
data+="\'";
data+=content;
data+="\'";
data+="}";
Serial.println(data);
char c[25];
for (int q=0;q<25;q++)
c[q]=data[q];
client.connect("First");
client.publish("Data2",c);
w = "z";
ESP.wdtDisable();
while(w=="z")
{
client.subscribe("Data3");
if (w!="z")
{
client.disconnect();
break;
}
}
ESP.wdtEnable(4);
memset(&c[0], 0, sizeof(c));
Serial.println("Exited from loop 1");
data ="";
if(w=="0")
{
client.connect(clientID);
w="z";
Serial.println("Reached in loop2");
y=digitalRead(2);
z=digitalRead(0);
Serial.println();
digitalWrite(10,LOW);
while((y==HIGH) && (z==HIGH))
{
y=digitalRead(2);
z=digitalRead(0);
digitalWrite(3,HIGH);
ESP.wdtFeed();
if((y==LOW)||(z==LOW))
{
if (y==LOW)
{p="Home";
digitalWrite(16,HIGH);}
else{
p="Market";
digitalWrite(15,HIGH);}
data+="{";
data+="\'";
data+="ID";
data+="\'";
data+=":";
data+="\'";
data+=content;
data+="\'";
data+=",";
data+="\'";
data+="Purpose";
data+="\'";
data+=":";
data+="\'";
data+=p;
data+="\'";
data+="}";
Serial.println(data);
char c[100];
for (int q=0;q<data.length();q++)
c[q]=data[q];
digitalWrite(3,LOW);
if (client.publish(mqtt_topic,c)) {
Serial.println("Button pushed and message sent!");
}
else {
Serial.println("Message failed to send. Reconnecting to MQTT Broker and trying again");
client.connect(clientID);
delay(1000); // This delay ensures that client.publish doesn't clash with the client.connect call
client.publish(mqtt_topic,c);
}
data="";
memset(&c[0], 0, sizeof(c));
delay(1000);
break;
}
}
}
}
def on_message(client, userdata, message):
if message.topic == "Data":
e=""
c=message.payload
for i in range(37):
e+=c[i]
q=0
d=ast.literal_eval(e)
y=time()
if (d['Purpose']=="Mrkt"):
d['Purpose']="Market"
conn=sqlite3.connect('db.sqlite3')
c=conn.cursor()
c.execute("""CREATE TABLE IF NOT EXISTS student_nodemcu (RFID varchar(30),Purpose varchar(20),Status varchar(20), In_Time varchar(20), Out_Time varchar(20))""")
c.execute("SELECT * FROM student_nodemcu")
fetch = c.fetchall()
for f in fetch:
if (str(f[1])==str(d['ID'])):
q=1
c.execute("UPDATE student_nodemcu SET Status= 'OUT' WHERE RFID=(?)",(str(f[1]),))
c.execute("UPDATE student_nodemcu SET Purpose= (?) WHERE RFID=(?)",(d['Purpose'],str(f[1])))
c.execute("UPDATE student_nodemcu SET Out_Time= (?) WHERE RFID=(?)",(y,str(f[1])))
c.execute("UPDATE student_nodemcu SET In_Time= (?) WHERE RFID=(?)",("-",str(f[1])))
if q==0:
c.execute("""INSERT INTO student_nodemcu (RFID,Purpose,Status,Out_Time,In_Time) VALUES((?), (?),(?),(?),(?))""", (d['ID'],d['Purpose'],'OUT',y,"-") )
conn.commit()
conn.close()
Akansh Saxena
2 projects • 5 followers
I'm currently an engineering student. My field of interest is hardware and working on projects. I always love to learn new things about it.
Pawan singh
1 project • 5 followers
An enthusiastic student with highly motivated and pursuing bachelors in ECE.Expert in implementation of each step of the project.
Comments