printDec(rfid.uid.uidByte, rfid.uid.size);
Serial.println();
}
else Serial.println(F("Card read previously."));
// PICC to’xtatish
rfid.PICC_HaltA();
// shifrlashni to’xtatish
rfid.PCD_StopCrypto1();
}
/**
* Helper routine to dump a byte array as hex values to Serial.
*/
void printHex(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);
}
}
/**
* Helper routine to dump a byte array as dec values to Serial.
*/
void printDec(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], DEC);
RFID hamda NODEMCU qurilmalari orqali kitobxonni ro’yhatga olish:
#include
#include
#include
#include
MFRC522 mfrc522(D4, D3);
OLED display(D2, D1);
char* ssid = "Shaheer and Sadeem";
char* password = "alpha222";
WiFiClient c;
WiFiServer server(23);
String getUID(byte *buffer, byte bufferSize) {
String id = "";
for (byte i = 0; i < bufferSize; i++) {
id.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : ""));
id.concat(String(mfrc522.uid.uidByte[i], HEX));
}
return id;
}
char *status;
char buf[10];
char recv[20];
bool disp = true;
void setup() {
display.begin();
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
display.print("Connecting to ");
display.print(ssid,2);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
int i = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
display.print(".",4,i++);
if(i > 8) i = 0;
}
display.print("WiFi connected",7);
server.begin();
server.setNoDelay(true);
delay(1000);
}
void loop() {
if (server.hasClient()) {
if (!c || !c.connected()) {
if (c) c.stop();
c = server.available();
//Serial.print("New client");
}
}
if (c && c.connected())
{
status = "ONLINE ";
if (disp == false)
{
display.begin();
display.print(status, 0);
disp = true;
}
mfrc522.PCD_Init();
if (mfrc522.PICC_IsNewCardPresent())
if (mfrc522.PICC_ReadCardSerial()) {
String x = getUID(mfrc522.uid.uidByte, mfrc522.uid.size);
x.toUpperCase();
x.toCharArray(buf, x.length());
//Serial.println(buf);
c.println(buf);
delay(1);
c.flush();
}
if (c.available()) {
String r = c.readStringUntil('\n');
r.toUpperCase();
r.toCharArray(recv, r.length());
//Serial.println(recv);
display.begin();
display.print(status, 0);
display.print(recv, 2);
if(r.charAt(r.length()-1) == 'M')
display.print("MARKED", 4);
if(r.charAt(r.length()-1) == 'A')
Do'stlaringiz bilan baham: |