#include <WiFi.h>
#include <HTTPClient.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
// Paste EXACT web app URL here (no spaces or comments on this line)
String SCRIPT_URL = "https://script.google.com/macros/s/AKfycbzLEeCUOEpxtO8K5HOEu9izVCmW793W_AdY269AFeKMs6DcWwvaX6xaZran6p0K55mfIw/exec";
LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte ROWS = 4, COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {13, 12, 14, 27};
byte colPins[COLS] = {26, 25, 33, 32};
Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
#define GROUP_BTN 2
#define ASSET_BTN 0
#define BUZZER 4
String groupUID = "";
String assetUID = "";
String mode = "";
int qty = 0;
void setup() {
Serial.begin(115200);
pinMode(GROUP_BTN, INPUT_PULLUP);
pinMode(ASSET_BTN, INPUT_PULLUP);
pinMode(BUZZER, OUTPUT);
lcd.init();
lcd.backlight();
lcd.print("RFID Lab Init...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("WiFi OK: " + WiFi.localIP().toString());
lcd.clear();
lcd.print("WiFi Ready");
delay(1500);
lcd.clear();
lcd.print("Scan + Enter");
}
void loop() {
char key = kpd.getKey();
if (key == 'A') {
mode = "Issue";
lcd.setCursor(0, 1);
lcd.print("Mode:Issue ");
} else if (key == 'B') {
mode = "Return";
lcd.setCursor(0, 1);
lcd.print("Mode:Return ");
} else if (key >= '0' && key <= '9') {
qty = (qty * 10) + (key - '0');
lcd.setCursor(0, 1);
lcd.print("Qty:");
lcd.print(qty);
lcd.print(" ");
}
if (digitalRead(GROUP_BTN) == LOW) {
groupUID = "GROUP_LEADER_01";
Serial.println("Group UID: " + groupUID);
beep(1000, 200);
delay(300);
}
if (digitalRead(ASSET_BTN) == LOW) {
assetUID = "ASSET_OSCILLOSCOPE";
Serial.println("Asset UID: " + assetUID);
beep(1500, 200);
delay(300);
}
if (!groupUID.isEmpty() && !assetUID.isEmpty() && !mode.isEmpty() && qty > 0) {
sendToSheets();
resetVars();
}
delay(100);
}
void sendToSheets() {
String uidCombined = groupUID + "_" + assetUID;
String url = SCRIPT_URL;
url += "?uid=" + uidCombined;
url += "&mode=" + mode;
url += "&qty=" + String(qty);
url += "&group=ETC_Group5";
Serial.println("Request URL: " + url);
HTTPClient http;
http.begin(url);
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
int httpCode = http.GET();
Serial.println("HTTP code: " + String(httpCode));
http.end();
lcd.clear();
lcd.print("Logged: " + mode);
beep(2000, 400);
}
void resetVars() {
groupUID = "";
assetUID = "";
mode = "";
qty = 0;
lcd.clear();
lcd.print("Scan + Enter");
}
void beep(int freq, int dur) {
tone(BUZZER, freq, dur);
}
Button: 1
Button:2