Advertisement
mfahri

Untitled

Jan 16th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Initial Author: ryand1011 (https://github.com/ryand1011)
  3.  *
  4.  * Reads data written by a program such as "rfid_write_personal_data.ino"
  5.  *
  6.  * See: https://github.com/miguelbalboa/rfid/tree/master/examples/rfid_write_personal_data
  7.  *
  8.  * Uses MIFARE RFID card using RFID-RC522 reader
  9.  * Uses MFRC522 - Library
  10.  * -----------------------------------------------------------------------------------------
  11.  *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
  12.  *             Reader/PCD   Uno/101       Mega      Nano v3    Leonardo/Micro   Pro Micro
  13.  * Signal      Pin          Pin           Pin       Pin        Pin              Pin
  14.  * -----------------------------------------------------------------------------------------
  15.  * RST/Reset   RST          5             5         D9         RESET/ICSP-5     RST
  16.  * SPI SS      SDA(SS)      6            53        D10        10               10
  17.  * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
  18.  * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
  19.  * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
  20. */
  21.  
  22. /////////// catatan PIN LED 4 ( Putih ) dan Hitam GND //
  23. // Catatan Buzzer PIN 3 + GND
  24.  
  25. //////////
  26.  
  27. #include <SPI.h>
  28. #include <MFRC522.h>
  29.  
  30. #include <Wire.h>
  31. #include <LiquidCrystal_I2C.h>
  32.  
  33. LiquidCrystal_I2C lcd(0x3f,16,2);
  34. constexpr uint8_t RST_PIN = 5;     // Configurable, see typical pin layout above
  35. constexpr uint8_t SS_PIN = 6;     // Configurable, see typical pin layout above
  36.  
  37. MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance
  38. char bufferx[16] ;
  39. ////////////// buzzer
  40. //int speakerPin = 4;
  41. //int length = 15; // the number of notes
  42. //char notes[] = "ccggaagffeeddc "; // a space represents a rest
  43. //int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
  44. //int tempo = 300;
  45.  
  46. ////////////
  47.  
  48.  
  49. #include <Ethernet.h>
  50.  
  51. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  52. IPAddress server(192, 168, 0, 130);  // numeric IP for Google (no DNS)
  53. //char server[] = "www.mfahri.web.id";    // name address for Google (using DNS)
  54.  
  55. // Set the static IP address to use if the DHCP fails to assign
  56. IPAddress ip(192, 168, 0, 177);
  57.  
  58.  
  59. //*****************************************************************************************//
  60. void(*resetFunc) (void) = 0 ;
  61.  
  62. void setup() {
  63.  
  64.   Serial.begin(9600);                                           // Initialize serial communications with the PC
  65.   SPI.begin();                                                  // Init SPI bus
  66.   mfrc522.PCD_Init();                                              // Init MFRC522 card
  67.   Serial.println(F("Read personal data on a MIFARE PICC:"));    //shows in serial that it is ready to read
  68.  pinMode(4, OUTPUT);
  69.   pinMode(3, OUTPUT);
  70.   /////////////////ethernet /////
  71.  lcd.begin();
  72.  lcd.setCursor(1,0);
  73.   lcd.print("Tab Your Card");
  74.    lcd.setCursor(5,1);
  75.     lcd.print("-----");
  76.   /////////////////////////////
  77. }
  78.  
  79. //*****************************************************************************************//
  80. void loop() {
  81.    
  82.   // Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
  83.   MFRC522::MIFARE_Key key;
  84.   for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF;
  85.  
  86.   //some variables we need
  87.   byte block;
  88.   byte len;
  89.   MFRC522::StatusCode status;
  90.  
  91.   //-------------------------------------------
  92.  
  93.   // Look for new cards
  94.   if ( ! mfrc522.PICC_IsNewCardPresent()) {
  95.     return;
  96.       resetFunc() ;
  97.   }
  98.  
  99.   // Select one of the cards
  100.   if ( ! mfrc522.PICC_ReadCardSerial()) {
  101.     return;
  102.       resetFunc() ;
  103.   }
  104.  
  105.   Serial.println(F("**Card Detected:**"));
  106.  
  107.   //-------------------------------------------
  108.  
  109.   mfrc522.PICC_DumpDetailsToSerial(&(mfrc522.uid)); //dump some details about the card
  110.  
  111.   //mfrc522.PICC_DumpToSerial(&(mfrc522.uid));      //uncomment this to see all blocks in hex
  112.  
  113.   //-------------------------------------------
  114.  
  115.  
  116.   Serial.print(F("Status Mysql : "));
  117.  
  118.   byte buffer1[18];
  119.  
  120.   block = 4;
  121.   len = 18;
  122.  
  123.   //------------------------------------------- GET FIRST NAME
  124.   status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 4, &key, &(mfrc522.uid)); //line 834 of MFRC522.cpp file
  125.   if (status != MFRC522::STATUS_OK) {
  126.     Serial.print(F("Authentication failed: "));
  127.     Serial.println(mfrc522.GetStatusCodeName(status));
  128.     return;
  129.     resetFunc() ;
  130.   }
  131.  
  132.   status = mfrc522.MIFARE_Read(block, buffer1, &len);
  133.   if (status != MFRC522::STATUS_OK) {
  134.     Serial.print(F("Reading failed: "));
  135.     Serial.println(mfrc522.GetStatusCodeName(status));
  136.     return;
  137.       resetFunc() ;
  138.   }
  139.  
  140.   //PRINT FIRST NAME
  141.   for (uint8_t i = 0; i < 16; i++)
  142.   {
  143.     if (buffer1[i] != 32)
  144.     {
  145.       //Serial.write(buffer1[i]);
  146.      bufferx[i] = buffer1[i];
  147.     }
  148.   }
  149.  
  150.  
  151.   //---------------------------------------- GET LAST NAME
  152.  
  153.   byte buffer2[18];
  154.   block = 1;
  155.  
  156.  
  157.  
  158.   status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 1, &key, &(mfrc522.uid)); //line 834
  159.   if (status != MFRC522::STATUS_OK) {
  160.     Serial.print(F("Authentication failed: "));
  161.     Serial.println(mfrc522.GetStatusCodeName(status));
  162.     return;
  163.   }
  164.  
  165.   status = mfrc522.MIFARE_Read(block, buffer2, &len);
  166.   if (status != MFRC522::STATUS_OK) {
  167.     Serial.print(F("Reading failed: "));
  168.     Serial.println(mfrc522.GetStatusCodeName(status));
  169.     return;
  170.   }
  171.  
  172.   //PRINT LAST NAME
  173.   for (uint8_t i = 0; i < 16; i++) {
  174.     Serial.write(buffer2[i]);    
  175.  
  176.   }
  177.  
  178.  
  179.   //----------------------------------------
  180.  
  181.  ///////////////////////// ethernet ///////////////////////////////////////////-----------------------///////////
  182.  
  183. // Ethetnet Konfigurasi ////----------------------------------------------------------------
  184.  
  185.  
  186. // Initialize the Ethernet client library
  187. // with the IP address and port of the server
  188. // that you want to connect to (port 80 is default for HTTP):
  189. EthernetClient client;
  190.  
  191. ///////////////////////////////////////////////////////////////////--------------------------------/////////////////////////////////
  192.  
  193.  
  194.  
  195.    Ethernet.begin(mac, ip);
  196.    client.connect(server, 80) ;
  197.     String kelas = "Akademik" ;
  198. ///
  199. unsigned int hex_num ;
  200. hex_num = mfrc522.uid.uidByte[0] << 24 ;
  201. hex_num += mfrc522.uid.uidByte[1] << 16 ;
  202. hex_num += mfrc522.uid.uidByte[2] << 8 ;
  203. hex_num += mfrc522.uid.uidByte[3]  ;
  204.  
  205. //int id_kartu = hex_num;
  206.  
  207. bufferx[15] = 0x0 ;
  208. Serial.print(bufferx) ;
  209.  
  210. String id_kartu = bufferx ;
  211.  
  212. //int id_kartu  = mfrc522.uid.uidByte[0] << 24 ;
  213.  
  214.     Serial.println("connected");
  215. // Serial.println(idk);
  216.     Serial.println(id_kartu);
  217.     // Make a HTTP request:
  218.     client.println("GET http://192.168.0.130/pm/si/absen_local/absen.php?kartu="+id_kartu+" HTTP/1.1");
  219.    // client.println("GET http://mfahri.web.id/coba/coba.php?kartu=1 HTTP/1.1");
  220.    client.println("Host: 192, 168, 0, 130");
  221.     client.println();
  222. delay(100);
  223. // set cursor to first line
  224.  
  225. {
  226.   lcd.clear();
  227. lcd.display();
  228.  
  229. lcd.setCursor(5, 0);
  230.   lcd.backlight();
  231.   lcd.print(id_kartu);
  232.   lcd.setCursor(4,1);
  233.   lcd.print("Success");
  234.   delay(100);
  235. }
  236.  
  237.  
  238. digitalWrite(4, HIGH);
  239. delay(1000);                       // wait for a second
  240.   digitalWrite(4, LOW);
  241.  
  242. tone(3,1000,1000) ;
  243.    
  244.   //////----------------------------//////////////////////////////////////////////////////////
  245. //digitalWrite(speakerPin, HIGH);
  246.   //  delayMicroseconds(tone);
  247. ////////////////////////////////////////////
  248.  
  249.  
  250.   Serial.println(F("\n**End Reading**\n"));
  251.  
  252.   delay(1000); //change value if you want to read cards faster
  253.  
  254.   mfrc522.PICC_HaltA();
  255.   mfrc522.PCD_StopCrypto1();
  256.       lcd.clear();
  257.  
  258.  lcd.setCursor(1,0);
  259.   lcd.print("Tab Your Card");
  260.    lcd.setCursor(5,1);
  261.     lcd.print("-----");
  262. }
  263. //*****************************************************************************************//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement