138 lines
3.2 KiB
C++
138 lines
3.2 KiB
C++
#include <WiFi.h>
|
|
#include <HTTPClient.h>
|
|
#include <SPI.h>
|
|
#include <MFRC522.h>
|
|
#include <LiquidCrystal_I2C.h>
|
|
|
|
const char* ssid = "amriiiii.02";
|
|
const char* password = "123sampai10";
|
|
|
|
const char* serverName = "http://192.168.92.176/playground_api/process_wahana_scan.php";
|
|
|
|
const char* namaWahana = "Virtual";
|
|
|
|
#define SS_PIN 5
|
|
#define RST_PIN 15
|
|
|
|
MFRC522 rfid(SS_PIN, RST_PIN);
|
|
LiquidCrystal_I2C lcd(0x27, 16, 2);
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
|
|
lcd.init();
|
|
lcd.backlight();
|
|
|
|
SPI.begin();
|
|
rfid.PCD_Init();
|
|
|
|
lcd.setCursor(0, 0);
|
|
lcd.print("Menghubungkan...");
|
|
WiFi.begin(ssid, password);
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
delay(500);
|
|
Serial.print(".");
|
|
lcd.setCursor(0, 1);
|
|
lcd.print("WiFi Connecting..");
|
|
}
|
|
|
|
lcd.clear();
|
|
lcd.setCursor(0, 0);
|
|
lcd.print("WiFi Tersambung");
|
|
Serial.println("WiFi Tersambung!");
|
|
Serial.print("IP Address: ");
|
|
Serial.println(WiFi.localIP());
|
|
delay(1000);
|
|
lcd.clear();
|
|
|
|
lcd.setCursor(0, 0);
|
|
lcd.print("SISTEM PEMANTAU");
|
|
lcd.setCursor(0, 1);
|
|
lcd.print("ANAK PLAYGROUND");
|
|
delay(2000);
|
|
lcd.clear();
|
|
lcd.setCursor(0, 0);
|
|
lcd.print("TEMPELKAN GELANG");
|
|
lcd.setCursor(0, 1);
|
|
lcd.print(" UNTUK MASUK ");
|
|
Serial.println("Sistem siap. Tempelkan gelang RFID.");
|
|
}
|
|
|
|
void loop() {
|
|
if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) {
|
|
delay(50);
|
|
return;
|
|
}
|
|
|
|
String uidStr = "";
|
|
for (byte i = 0; i < rfid.uid.size; i++) {
|
|
if (rfid.uid.uidByte[i] < 0x10) uidStr += "0";
|
|
uidStr += String(rfid.uid.uidByte[i], HEX);
|
|
}
|
|
uidStr.toUpperCase();
|
|
|
|
Serial.print("UID Gelang Terbaca: ");
|
|
Serial.println(uidStr);
|
|
|
|
lcd.clear();
|
|
lcd.setCursor(0, 0);
|
|
lcd.print("GELANG TERBACA");
|
|
lcd.setCursor(0, 1);
|
|
lcd.print(uidStr);
|
|
delay(1000);
|
|
|
|
if (WiFi.status() == WL_CONNECTED) {
|
|
HTTPClient http;
|
|
http.begin(serverName);
|
|
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
|
|
String httpRequestData = "kode_gelang=" + uidStr + "&wahana=" + String(namaWahana);
|
|
|
|
Serial.print("Mengirim data: ");
|
|
Serial.println(httpRequestData);
|
|
|
|
int httpResponseCode = http.POST(httpRequestData);
|
|
|
|
lcd.clear();
|
|
lcd.setCursor(0, 0);
|
|
|
|
if (httpResponseCode > 0) {
|
|
String response = http.getString();
|
|
Serial.print("HTTP Response Code: ");
|
|
Serial.println(httpResponseCode);
|
|
Serial.print("Server Response: ");
|
|
Serial.println(response);
|
|
|
|
lcd.print("Data Dikirim OK");
|
|
lcd.setCursor(0, 1);
|
|
lcd.print("Status: ");
|
|
lcd.print(httpResponseCode);
|
|
} else {
|
|
Serial.print("Error Mengirim Data. HTTP Response Code: ");
|
|
Serial.println(httpResponseCode);
|
|
|
|
lcd.print("Gagal Kirim");
|
|
lcd.setCursor(0, 1);
|
|
lcd.print("Kode: ");
|
|
lcd.print(httpResponseCode);
|
|
}
|
|
|
|
http.end();
|
|
} else {
|
|
lcd.clear();
|
|
lcd.setCursor(0, 0);
|
|
lcd.print("WiFi Terputus!");
|
|
lcd.setCursor(0, 1);
|
|
lcd.print("Reconnecting...");
|
|
Serial.println("WiFi Terputus, mencoba menyambungkan ulang...");
|
|
WiFi.reconnect();
|
|
delay(2000);
|
|
}
|
|
|
|
delay(2000);
|
|
lcd.clear();
|
|
lcd.setCursor(0, 0);
|
|
lcd.print("TEMPELKAN GELANG");
|
|
lcd.setCursor(0, 1);
|
|
lcd.print(" UNTUK MASUK ");
|
|
} |