Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Initial Author: ryand1011 (https://github.com/ryand1011)
- *
- * Reads data written by a program such as "rfid_write_personal_data.ino"
- *
- * See: https://github.com/miguelbalboa/rfid/tree/master/examples/rfid_write_personal_data
- *
- * Uses MIFARE RFID card using RFID-RC522 reader
- * Uses MFRC522 - Library
- * -----------------------------------------------------------------------------------------
- * MFRC522 Arduino Arduino Arduino Arduino Arduino
- * Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro
- * Signal Pin Pin Pin Pin Pin Pin
- * -----------------------------------------------------------------------------------------
- * RST/Reset RST 5 5 D9 RESET/ICSP-5 RST
- * SPI SS SDA(SS) 6 53 D10 10 10
- * SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
- * SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
- * SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
- */
- /////////// catatan PIN LED 4 ( Putih ) dan Hitam GND //
- // Catatan Buzzer PIN 3 + GND
- //////////
- #include <SPI.h>
- #include <MFRC522.h>
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x3f,16,2);
- constexpr uint8_t RST_PIN = 5; // Configurable, see typical pin layout above
- constexpr uint8_t SS_PIN = 6; // Configurable, see typical pin layout above
- MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
- char bufferx[16] ;
- ////////////// buzzer
- //int speakerPin = 4;
- //int length = 15; // the number of notes
- //char notes[] = "ccggaagffeeddc "; // a space represents a rest
- //int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
- //int tempo = 300;
- ////////////
- #include <Ethernet.h>
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
- IPAddress server(192, 168, 0, 130); // numeric IP for Google (no DNS)
- //char server[] = "www.mfahri.web.id"; // name address for Google (using DNS)
- // Set the static IP address to use if the DHCP fails to assign
- IPAddress ip(192, 168, 0, 177);
- //*****************************************************************************************//
- void(*resetFunc) (void) = 0 ;
- void setup() {
- Serial.begin(9600); // Initialize serial communications with the PC
- SPI.begin(); // Init SPI bus
- mfrc522.PCD_Init(); // Init MFRC522 card
- Serial.println(F("Read personal data on a MIFARE PICC:")); //shows in serial that it is ready to read
- pinMode(4, OUTPUT);
- pinMode(3, OUTPUT);
- /////////////////ethernet /////
- lcd.begin();
- lcd.setCursor(1,0);
- lcd.print("Tab Your Card");
- lcd.setCursor(5,1);
- lcd.print("-----");
- /////////////////////////////
- }
- //*****************************************************************************************//
- void loop() {
- // Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
- MFRC522::MIFARE_Key key;
- for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF;
- //some variables we need
- byte block;
- byte len;
- MFRC522::StatusCode status;
- //-------------------------------------------
- // Look for new cards
- if ( ! mfrc522.PICC_IsNewCardPresent()) {
- return;
- resetFunc() ;
- }
- // Select one of the cards
- if ( ! mfrc522.PICC_ReadCardSerial()) {
- return;
- resetFunc() ;
- }
- Serial.println(F("**Card Detected:**"));
- //-------------------------------------------
- mfrc522.PICC_DumpDetailsToSerial(&(mfrc522.uid)); //dump some details about the card
- //mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); //uncomment this to see all blocks in hex
- //-------------------------------------------
- Serial.print(F("Status Mysql : "));
- byte buffer1[18];
- block = 4;
- len = 18;
- //------------------------------------------- GET FIRST NAME
- status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 4, &key, &(mfrc522.uid)); //line 834 of MFRC522.cpp file
- if (status != MFRC522::STATUS_OK) {
- Serial.print(F("Authentication failed: "));
- Serial.println(mfrc522.GetStatusCodeName(status));
- return;
- resetFunc() ;
- }
- status = mfrc522.MIFARE_Read(block, buffer1, &len);
- if (status != MFRC522::STATUS_OK) {
- Serial.print(F("Reading failed: "));
- Serial.println(mfrc522.GetStatusCodeName(status));
- return;
- resetFunc() ;
- }
- //PRINT FIRST NAME
- for (uint8_t i = 0; i < 16; i++)
- {
- if (buffer1[i] != 32)
- {
- //Serial.write(buffer1[i]);
- bufferx[i] = buffer1[i];
- }
- }
- //---------------------------------------- GET LAST NAME
- byte buffer2[18];
- block = 1;
- status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 1, &key, &(mfrc522.uid)); //line 834
- if (status != MFRC522::STATUS_OK) {
- Serial.print(F("Authentication failed: "));
- Serial.println(mfrc522.GetStatusCodeName(status));
- return;
- }
- status = mfrc522.MIFARE_Read(block, buffer2, &len);
- if (status != MFRC522::STATUS_OK) {
- Serial.print(F("Reading failed: "));
- Serial.println(mfrc522.GetStatusCodeName(status));
- return;
- }
- //PRINT LAST NAME
- for (uint8_t i = 0; i < 16; i++) {
- Serial.write(buffer2[i]);
- }
- //----------------------------------------
- ///////////////////////// ethernet ///////////////////////////////////////////-----------------------///////////
- // Ethetnet Konfigurasi ////----------------------------------------------------------------
- // Initialize the Ethernet client library
- // with the IP address and port of the server
- // that you want to connect to (port 80 is default for HTTP):
- EthernetClient client;
- ///////////////////////////////////////////////////////////////////--------------------------------/////////////////////////////////
- Ethernet.begin(mac, ip);
- client.connect(server, 80) ;
- String kelas = "Akademik" ;
- ///
- unsigned int hex_num ;
- hex_num = mfrc522.uid.uidByte[0] << 24 ;
- hex_num += mfrc522.uid.uidByte[1] << 16 ;
- hex_num += mfrc522.uid.uidByte[2] << 8 ;
- hex_num += mfrc522.uid.uidByte[3] ;
- //int id_kartu = hex_num;
- bufferx[15] = 0x0 ;
- Serial.print(bufferx) ;
- String id_kartu = bufferx ;
- //int id_kartu = mfrc522.uid.uidByte[0] << 24 ;
- Serial.println("connected");
- // Serial.println(idk);
- Serial.println(id_kartu);
- // Make a HTTP request:
- client.println("GET http://192.168.0.130/pm/si/absen_local/absen.php?kartu="+id_kartu+" HTTP/1.1");
- // client.println("GET http://mfahri.web.id/coba/coba.php?kartu=1 HTTP/1.1");
- client.println("Host: 192, 168, 0, 130");
- client.println();
- delay(100);
- // set cursor to first line
- {
- lcd.clear();
- lcd.display();
- lcd.setCursor(5, 0);
- lcd.backlight();
- lcd.print(id_kartu);
- lcd.setCursor(4,1);
- lcd.print("Success");
- delay(100);
- }
- digitalWrite(4, HIGH);
- delay(1000); // wait for a second
- digitalWrite(4, LOW);
- tone(3,1000,1000) ;
- //////----------------------------//////////////////////////////////////////////////////////
- //digitalWrite(speakerPin, HIGH);
- // delayMicroseconds(tone);
- ////////////////////////////////////////////
- Serial.println(F("\n**End Reading**\n"));
- delay(1000); //change value if you want to read cards faster
- mfrc522.PICC_HaltA();
- mfrc522.PCD_StopCrypto1();
- lcd.clear();
- lcd.setCursor(1,0);
- lcd.print("Tab Your Card");
- lcd.setCursor(5,1);
- lcd.print("-----");
- }
- //*****************************************************************************************//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement