Esp32 Proj (4) Rfid
Esp32 Proj (4) Rfid
function doGet(e) {
Logger.log(JSON.stringify(e));
if (e.parameter == 'undefined') {
return ContentService.createTextOutput("Received data is undefined");
}
sheet.getRange("A" + nextRow).setValue(name);
sheet.getRange("B" + nextRow).setValue(Curr_Date);
sheet.getRange("C" + nextRow).setValue(Curr_Time);
function stripQuotes(value) {
return value.toString().replace(/^["']|['"]$/g, "");
}
function doPost(e) {
var val = e.parameter.value;
MFRC522::StatusCode status;
void setup() {
Serial.begin(115200);
SPI.begin();
mfrc522.PCD_Init();
Serial.println("Scan a MIFARE 1K Tag to write data...");
}
void loop() {
if (!mfrc522.PICC_IsNewCardPresent()) return;
if (!mfrc522.PICC_ReadCardSerial()) return;
Serial.println("\n**Card Detected**");
Serial.print("Card UID:");
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.print("\nPICC Type: ");
MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
Serial.println(mfrc522.PICC_GetTypeName(piccType));
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
}
#define RST_PIN 22
#define SS_PIN 21
#define BUZZER 15
int blockNum = 2;
String card_holder_name;
const String sheet_url = "URLgoogle script?name=";
void setup() {
Serial.begin(115200);
Serial.println();
Serial.print("Connecting to AP");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(200);
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println();
pinMode(BUZZER, OUTPUT);
SPI.begin();
}
void loop() {
mfrc522.PCD_Init();
if (!mfrc522.PICC_IsNewCardPresent()) { return; }
if (!mfrc522.PICC_ReadCardSerial()) { return; }
Serial.println();
Serial.println(F("Reading last data from RFID..."));
ReadDataFromBlock(blockNum, readBlockData);
Serial.println();
Serial.print(F("Last data in RFID:"));
Serial.print(blockNum);
Serial.print(F(" --> "));
for (int j = 0; j < 16; j++) {
Serial.write(readBlockData[j]);
}
Serial.println();
digitalWrite(BUZZER, HIGH);
delay(200);
digitalWrite(BUZZER, LOW);
delay(200);
digitalWrite(BUZZER, HIGH);
delay(200);
digitalWrite(BUZZER, LOW);
if (WiFi.status() == WL_CONNECTED) {
WiFiClientSecure client;
client.setInsecure();
card_holder_name = sheet_url + String((char*)readBlockData);
card_holder_name.trim();
Serial.println(card_holder_name);
HTTPClient https;
Serial.print(F("[HTTPS] begin...\n"));
if (https.begin(client, (String)card_holder_name)) {
Serial.print(F("[HTTPS] GET...\n"));
int httpCode = https.GET();
if (httpCode > 0) {
Serial.printf("[HTTPS] GET... code: %d\n", httpCode);
} else {
Serial.printf("[HTTPS] GET... failed, error: %s\n",
https.errorToString(httpCode).c_str());
}
https.end();
delay(1000);
} else {
Serial.printf("[HTTPS] Unable to connect\n");
}
}
}
(If you don't see this option, follow the installation steps below)