i try to make project arduino uno + ethernet shield with RFID
can someone help me
What I have tried:
<pre>
#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
LiquidCrystal_I2C lcd(0x27, 16, 2);
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; const size_t MAX_CONTENT_SIZE = 512;
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";
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();
mp3_set_serial (Serial); delay(1); 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);
DynamicJsonDocument doc(JSON_OBJECT_SIZE(15));
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("");
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();
}
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();
}
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();
}
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();
}
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();
}
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();
}
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();
}
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();
}
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();
}
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();
}
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");
}
}