#include <ESP8266WiFi.h> // Atau library yang sesuai untuk ESP32
const char* ssid = "yourSSID";
const char* password = "yourPASSWORD";
const char* apiURL = "http://your.api.endpoint";
void setup() {
Serial.begin(115200);
// Inisialisasi koneksi WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Connected to WiFi");
}
void loop() {
// Baca data dari barcode scanner
if (Serial.available() > 0) {
String barcode = Serial.readString();
// Kirim barcode ke API
HTTPClient http;
http.begin(apiURL);
http.addHeader("Content-Type", "application/json");
int httpResponseCode = http.POST("{\"barcode\":\"" + barcode + "\"}");
if (httpResponseCode > 0) {
String response = http.getString();
// Proses respon dari API
// Contoh: jika response mengandung "authorized": true, buka turnstile
}
http.end(); //Tutup koneksi
}
delay(1000); //Delay untuk loop
}