157 lines
3.3 KiB
C++
157 lines
3.3 KiB
C++
#include <SPI.h>
|
|
#include <MFRC522.h>
|
|
#include <ESP8266WiFi.h>
|
|
#include <WiFiClient.h>
|
|
#include <ESP8266WebServer.h>
|
|
#include <ESP8266HTTPClient.h>
|
|
#include <LiquidCrystal_I2C.h>
|
|
#include "CTBot.h"
|
|
|
|
const char *ssid = "Kedai Kopi TEMEJI";
|
|
const char *password = "NEWTEMEJI";
|
|
|
|
String token = "6882219025:AAH8wwvnLPwEnN7GqlpXzkgOP0Fwq6FqJdM";
|
|
|
|
const int RST_PIN = D4;
|
|
const int SS_PIN = D8;
|
|
const int pinBuzz = D0;
|
|
const int pinCamera = D3;
|
|
const int lcdColumns = 16;
|
|
const int lcdRows = 2;
|
|
|
|
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
|
|
CTBot myBot;
|
|
|
|
MFRC522 rfid(SS_PIN, RST_PIN);
|
|
MFRC522::MIFARE_Key key;
|
|
|
|
WiFiClient wifiClient;
|
|
HTTPClient http;
|
|
|
|
void setup() {
|
|
delay(1000);
|
|
Serial.begin(115200);
|
|
|
|
lcd.init();
|
|
lcd.backlight();
|
|
|
|
lcd.setCursor(0, 0);
|
|
lcd.print(" SYSTEM RFID ");
|
|
|
|
lcd.setCursor(0, 1);
|
|
lcd.print("Dengan ESP32 Cam");
|
|
|
|
pinMode(pinCamera, OUTPUT);
|
|
digitalWrite(pinCamera, HIGH);
|
|
|
|
pinMode(pinBuzz, OUTPUT);
|
|
digitalWrite(pinBuzz, HIGH);
|
|
|
|
WiFi.mode(WIFI_OFF);
|
|
delay(1000);
|
|
WiFi.mode(WIFI_STA);
|
|
|
|
WiFi.begin(ssid, password);
|
|
Serial.println("");
|
|
|
|
Serial.print("Connecting");
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
delay(500);
|
|
Serial.print(".");
|
|
}
|
|
|
|
Serial.println("");
|
|
Serial.print("Connected to ");
|
|
Serial.println(ssid);
|
|
Serial.print("IP address: ");
|
|
Serial.println(WiFi.localIP());
|
|
|
|
myBot.wifiConnect(ssid, password);
|
|
myBot.setTelegramToken(token);
|
|
|
|
if (myBot.testConnection())
|
|
Serial.println("\ntestConnection OK");
|
|
else
|
|
Serial.println("\ntestConnection NOK");
|
|
|
|
SPI.begin();
|
|
rfid.PCD_Init();
|
|
digitalWrite(pinBuzz, LOW);
|
|
delay(1000);
|
|
digitalWrite(pinBuzz, HIGH);
|
|
Serial.println("Ready");
|
|
lcd.clear();
|
|
lcd.setCursor(0, 0);
|
|
lcd.print(" TEMPELKAN ");
|
|
|
|
lcd.setCursor(0, 1);
|
|
lcd.print("KARTU ANDA DISINI");
|
|
|
|
myBot.sendMessage(1263710714, "SYSTEM ABSENSI RFID DENGAN CAMERA");
|
|
}
|
|
|
|
void loop() {
|
|
if (!rfid.PICC_IsNewCardPresent())
|
|
return;
|
|
|
|
if (!rfid.PICC_ReadCardSerial())
|
|
return;
|
|
|
|
String content = "";
|
|
|
|
for (byte i = 0; i < 4; i++) {
|
|
content +=
|
|
(rfid.uid.uidByte[i] < 0x10 ? "0" : "") +
|
|
String(rfid.uid.uidByte[i], HEX) +
|
|
(i != rfid.uid.size - 1 ? "" : "");
|
|
}
|
|
content.trim();
|
|
content.toUpperCase();
|
|
|
|
digitalWrite(pinBuzz, LOW);
|
|
delay(500);
|
|
digitalWrite(pinBuzz, HIGH);
|
|
|
|
HTTPClient http;
|
|
|
|
String getData, Link;
|
|
|
|
getData = "?Data='" + content + "'";
|
|
Link = "http://192.168.50.26/rfidcam/esp.php" + getData;
|
|
http.begin(wifiClient, Link);
|
|
|
|
int httpCode = http.GET();
|
|
if (httpCode == 200) {
|
|
Serial.println(content);
|
|
if (content.equals("43ACDA0F")) {
|
|
myBot.sendMessage(1263710714, "Absen Berhasil1");
|
|
} else if (content.equals("93C6B21B")) {
|
|
myBot.sendMessage(1263710714, "Absen Berhasil2");
|
|
} else if (content.equals("E30E4213")) {
|
|
myBot.sendMessage(1263710714, "Absen Berhasil3");
|
|
}else if (content.equals("F344A7AA")) {
|
|
myBot.sendMessage(1263710714, "Absen Berhasil4");
|
|
}
|
|
}
|
|
|
|
lcd.clear();
|
|
lcd.setCursor(0, 0);
|
|
lcd.print(" Absen Berhasil ");
|
|
|
|
digitalWrite(pinCamera, LOW);
|
|
delay(500);
|
|
digitalWrite(pinCamera, HIGH);
|
|
|
|
delay(2000);
|
|
http.end();
|
|
|
|
rfid.PICC_HaltA();
|
|
rfid.PCD_StopCrypto1();
|
|
Serial.println("Ready");
|
|
lcd.setCursor(0, 0);
|
|
lcd.print(" SCAN ");
|
|
|
|
lcd.setCursor(0, 1);
|
|
lcd.print(" YOUR CARD ");
|
|
}
|