-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodemcu-rfid.ino
81 lines (69 loc) · 1.64 KB
/
nodemcu-rfid.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#define SS_PIN D2
#define RST_PIN D1
#include <SPI.h>
#include <MFRC522.h>
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
const char* ssid = "SSID";
const char* password = "PASSWORD";
WiFiClient espClient;
PubSubClient client(espClient);
MFRC522 mfrc522(SS_PIN, RST_PIN);
int statuss = 0;
int out = 0;
void setup()
{
Serial.begin(9600);
setup_wifi();
SPI.begin();
mfrc522.PCD_Init();
}
void loop()
{
if (!mfrc522.PICC_IsNewCardPresent()) {
return;
}
if (!mfrc522.PICC_ReadCardSerial()) {
return;
}
//Show UID on serial monitor
Serial.println();
Serial.print(" UID tag :");
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
content.toUpperCase();
Serial.println();
if (content.substring(1) == "02 29 85 59") {
Serial.println(" Access Granted ");
Serial.println(" Welcome Mr.Circuit ");
delay(1000);
Serial.println(" Have FUN ");
Serial.println();
statuss = 1;
} else {
Serial.println(" Access Denied ");
delay(3000);
}
}
//Método de conexão com rede WIFI
void setup_wifi() {
delay(10);
Serial.println();
Serial.print("Conectando");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi conectado");
Serial.println("Endereco IP : ");
Serial.println(WiFi.localIP());
}