Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i try to make project arduino uno + ethernet shield with RFID
can someone help me

What I have tried:

C++
<pre>
//----------------LIBRARIES----------------
    #include <ArduinoJson.h>
    #include <HttpClient.h>
    #include <SPI.h>
    #include <MFRC522.h>
    #include <LiquidCrystal_I2C.h>
    #include <DFPlayer_Mini_Mp3.h>
    #include <Ethernet.h>
    #define SS_PIN 4 //FOR RFID SS PIN BECASUSE WE ARE USING BOTH ETHERNET SHIELD AND RS-522
    #define RST_PIN 9

//-----------------------------------------


//Sesuaikan dengan addres i2c dan ukuran LCD yg digunakan
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Buat object http

EthernetClient client;
MFRC522 rfid(SS_PIN,RST_PIN);

const char* server = "192.168.137.1/rfid";
String rfid_key = "";
String resource = "";


const unsigned long HTTP_TIMEOUT = 10000;  // max respone time from server
const size_t MAX_CONTENT_SIZE = 512;       // max size of the HTTP response

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};

MFRC522 mfrc522(SS_PIN, RST_PIN);
MFRC522::MIFARE_Key key;

byte i;
String ID;
String KEY_API = "abc123"; //silakan sesuaikan dengan KEY_API yg ada di database


void startdisplay() {
    lcd.setCursor(0, 0);
    lcd.print("ABSENSI BOSTO");
    lcd.setCursor(0, 1);
    lcd.print("Stat: Connected");
  }

void setup () {

  Serial.begin(9600);
  SPI.begin();

    //mySerial.begin (9600);
    mp3_set_serial (Serial);  //set softwareSerial for DFPlayer-mini mp3 module 
    delay(1);  //wait 1ms for mp3 module to set volume
    mp3_set_volume (25);
    
    lcd.begin();  
    lcd.backlight();
      

    while (!client.connected()) {
        Serial.println("Connecting...");
        lcd.clear();
        lcd.print("Connecting");
        for(int x = 0; x<16; x++){
        lcd.setCursor(x, 1);
        lcd.print(".");
        delay(100);
        }
      }
  
 if(client.connected()) {
    Serial.println("Connected...!!!");
    lcd.clear();
    lcd.print("Connected...!!!");
    mp3_play(2);
    delay(1000);
    lcd.clear();
    startdisplay();
  }
   
   SPI.begin();
   mfrc522.PCD_Init();

}


void readRFID(byte *buffer, byte bufferSize)
{
  ID="";
  for(byte i = 0;i<bufferSize; i++)
  {
    ID=ID+String(buffer[i], HEX);
  }
}

void loop() {

  if(!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()){
    return;

  }
  readRFID(mfrc522.uid.uidByte, mfrc522.uid.size);

  HttpClient http;
  
  if (client.connected()) {

    http.begin(server + "KEY_API=" + KEY_API + "&ID=" + ID);
    int httpCode = http.GET();

    if (httpCode > 0) {
      char json[500];
      String payload = http.getString();
      payload.toCharArray(json, 500);
      
//      StaticJsonDocument<200> doc;
     DynamicJsonDocument doc(JSON_OBJECT_SIZE(15));


     // Deserialize the JSON document
        deserializeJson(doc, json);
        String IDtag   = doc["ID"];
        String Jam     = doc["Jam"];
        String STAT    = doc["STAT"];
        String Auth    = doc["Auth"];
        
        Serial.println("");
        Serial.print("Response HTTP = ");
        Serial.println(httpCode);
        Serial.print("ID Card = ");
        Serial.println(ID);
        Serial.print("Status= ");
        Serial.println(STAT);
        Serial.print("Jam = ");
        Serial.println(Jam);
        Serial.println("");

        //kepagian
          if(STAT == "kepagian") {
            mp3_play(3);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Sistem Masih");
            lcd.setCursor(0, 1);
            lcd.print("Terkunci!!!");
            delay(3000);
            lcd.clear();
            startdisplay();
          }

          //masuk
          else if(STAT == "masuk") {
            mp3_play(4);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Tap Masuk");
            lcd.setCursor(0, 1);
            lcd.print("diterima");
            delay(2000);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("ID: ");
            lcd.print(IDtag);
            lcd.setCursor(0, 1);
            lcd.print("Jam: ");
            lcd.print(Jam);
            delay(3000);
            lcd.clear();
            startdisplay();
          }

          //terlambat
         else  if(STAT == "terlambat") {
            mp3_play(5);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Tap Masuk");
            lcd.setCursor(0, 1);
            lcd.print("diterima");
            mp3_play(5);
            delay(2000);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Tapi Anda Datang");
            lcd.setCursor(0, 1);
            lcd.print("Terlambat!!!");
            delay(2000);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("ID: ");
            lcd.print(IDtag);
            lcd.setCursor(0, 1);
            lcd.print("Jam: ");
            lcd.print(Jam);
            delay(3000);
            lcd.clear();
            startdisplay();
          }

           //double tap in
          else if(STAT == "double tap in") {
            mp3_play(6);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Tap Masuk Telah");
            lcd.setCursor(0, 1);
            lcd.print("diterima!!!");
            delay(3000);
            lcd.clear();
            startdisplay();
          }

          //pulang cepat
          else if(STAT == "pulang cepat") {
            mp3_play(7);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Tap Pulang");
            lcd.setCursor(0, 1);
            lcd.print("diterima");
            delay(2000);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Anda Pulang");
            lcd.setCursor(0, 1);
            lcd.print("Lebih Awal");
            delay(2000);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("ID: ");
            lcd.print(IDtag);
            lcd.setCursor(0, 1);
            lcd.print("Jam: ");
            lcd.print(Jam);
            delay(3000);
            lcd.clear();
            startdisplay();
          }

          //pulang 
          else if(STAT == "pulang") {
            mp3_play(8);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Tap Pulang");
            lcd.setCursor(0, 1);
            lcd.print("diterima");;
            delay(2000);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("ID: ");
            lcd.print(IDtag);
            lcd.setCursor(0, 1);
            lcd.print("Jam: ");
            lcd.print(Jam);
            delay(3000);
            lcd.clear();
            startdisplay();
          }

          //bolos 
          else if(STAT == "bolos") {
            mp3_play(9);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("ID: ");
            lcd.print(IDtag); 
            lcd.setCursor(0, 1);
            lcd.print("dinyatakan Bolos");
            delay(3000);
            lcd.clear();
            startdisplay();
          }

           //alfa 
          else if(STAT == "alfa") {
            mp3_play(10);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("ID: ");
            lcd.print(IDtag); 
            lcd.setCursor(0, 1);
            lcd.print("dinyatakan Alfa");
            delay(3000);
            lcd.clear();
            startdisplay();
          }

          //locked 
          else if(STAT == "locked") {
            mp3_play(11);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Sistem Telah");
            lcd.setCursor(0, 1);
            lcd.print("Terkunci!!!");
            delay(3000);
            lcd.clear();
            startdisplay();
          }

          //libur 
          else if(STAT == "libur") {
            mp3_play(12);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Hari Ini Libur");
            lcd.setCursor(0, 1);
            lcd.print("Apa Anda Lupa?");
            delay(3000);
            lcd.clear();
            startdisplay();
          }
          
           else if(Auth == "Auth Rejected!!!") {
            mp3_play(13);
            Serial.print("WARNING...");
            Serial.println(Auth);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print(Auth);
            lcd.setCursor(0, 1);
            lcd.print("Key API invalid!");
            delay(3000);
            lcd.clear();
            startdisplay();
          }

           //ID tidak terdaftar 
          else {
            mp3_play(14);
            Serial.println("ID Tidak Terdaftar!!!");
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("ID: ");
            lcd.print(ID); 
            lcd.setCursor(0, 1);
            lcd.print("Tidak Terdaftar!!!");
            delay(3000);
            lcd.clear();
            startdisplay();
          }
          
    }
    else{
      Serial.println("Koneksi ke Server Gagal!!!");
      Serial.println(http.errorToString(httpCode));
      Serial.println("");
      mp3_play(15);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Koneksi ke Server");
            lcd.setCursor(0, 1);
            lcd.print("Gagal!!!");
            delay(2000);
            lcd.clear();
            lcd.print(http.errorToString(httpCode));
            delay(3000);
            lcd.clear();
            startdisplay();
    }

    http.end();

  }
  else {
    Serial.println("Disconnected!!!");
    mp3_play(16);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Cek Koneksi");
    lcd.setCursor(0, 1);
    lcd.print("Internet !!!");
    delay(2000);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("ABSENSI BOSTO");
    lcd.setCursor(0, 1);
    lcd.print("Stat: Disconnect");
  }

}
Posted
Updated 16-Dec-20 20:21pm

1 solution

Quote:
HttpClient http;
The HttpClient class has NO default contructor. See the documentation (i.e. the source code...):
GitHub - amcewen/HttpClient: Arduino HTTP library[^].

Probably you have to pass your client to such a constructor, but it is just a guess.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900