im using esp32, mfrc522 and lcd for attendance system.
At first, its all working fine.
Now its not working suddenly, like i havent change anything
#include <SPI.h>
#include <MFRC522.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <driver/adc.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define SS_PIN 15
#define RST_PIN 13
#define DOOR_PIN 2
#define TERMINAL_NAME "basement"
// SCRIPT LINK MUST BE LIKE THIS "https://script.google.com/macros/s/AKfycbzBCsPz3ZDVUkdP7mloaX1AAKI1mC_NxM802hvDNRwyE4vw4oo/exec"
const char *mainLinkForSpr = "https://script.google.com/macros/s/AKfycbwLmlPHYmb4Ro9pPK30Nf_pU1RnEd9V9h6Ccw2wgkp4wG3RjvwMT6JDQlXp1fCJ8v4U/exec";
const char *ssid = "Zarulmiqhail";
const char *password = "password";
LiquidCrystal_I2C lcd(0x27, 20, 4);
MFRC522 mfrc522(SS_PIN, RST_PIN);
MFRC522::StatusCode status;
uint64_t clearDisplayTimer = 0;
bool needDisplayUpdate = true;
const char *root_ca =
"-----BEGIN CERTIFICATE-----\n" \
"MIIFVzCCAz+gAwIBAgINAgPlk28xsBNJiGuiFzANBgkqhkiG9w0BAQwFADBHMQsw\n" \
"CQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExMQzEU\n" \
"MBIGA1UEAxMLR1RTIFJvb3QgUjEwHhcNMTYwNjIyMDAwMDAwWhcNMzYwNjIyMDAw\n" \
"MDAwWjBHMQswCQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZp\n" \
"Y2VzIExMQzEUMBIGA1UEAxMLR1RTIFJvb3QgUjEwggIiMA0GCSqGSIb3DQEBAQUA\n" \
"A4ICDwAwggIKAoICAQC2EQKLHuOhd5s73L+UPreVp0A8of2C+X0yBoJx9vaMf/vo\n" \
"27xqLpeXo4xL+Sv2sfnOhB2x+cWX3u+58qPpvBKJ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9y8J\n" \
"ZgfIPxz88NtFMN9iiMG1D53Dn0reWVlHxYciNuaCp+0KueIHoI17eko8cdLiA6Ef\n" \
"MgfdG+RCzgwARWGAtQsgWSl4vflVy2PFPEz0tv/bal8xa5meLMFrUKTX5hgUvYU/\n" \
"Z6tGn6D/Qqc6f1zLXbBwHSs09dR2CQzreExZBfMzQsNhFRAbd03OIozUhfJFfbdT\n" \
"6u9AWpQKXCBfTkBdYiJ23//OYb2MI3jSNwLgjt7RETeJ9r/tSQdirpLsQBqvFAnZ\n" \
"0E6yove+7u7Y/9waLd64NnHi/Hm3lCXRSHNboTXns5lndcEZOitHTtNCjv0xyBZm\n" \
"2tIMPNuzjsmhDYAPexZ3FL//2wmUspO8IFgV6dtxQ/PeEMMA3KgqlbbC1j+Qa3bb\n" \
"bP6MvPJwNQzcmRk13NfIRmPVNnGuV/u3gm3c\n" \
"-----END CERTIFICATE-----\n";
// Helper function for LCD and Serial display
void dualPrint(const __FlashStringHelper* text)
{
lcd.print(text);
Serial.println(text);
}
// Function to open the door
void openDoor()
{
digitalWrite(DOOR_PIN, HIGH);
delay(2000);
digitalWrite(DOOR_PIN, LOW);
}
void setup()
{
pinMode(DOOR_PIN, OUTPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Connecting wifi");
lcd.setCursor(0, 1);
Serial.begin(115200); // Initialize serial communications with the PC
while (!Serial);
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
WiFi.begin(ssid, password);
Serial.println(F("Connecting wifi"));
byte printedDots = 0;
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
if (printedDots++ > 15)
{
for (; printedDots >= 1; printedDots--)
{
lcd.setCursor(printedDots, 1);
lcd.print(' ');
}
lcd.setCursor(1, 1);
printedDots = 1;
}
else
lcd.print(".");
}
lcd.clear();
lcd.setCursor(0, 0);
Serial.println("");
dualPrint(F("WiFi connected"));
lcd.setCursor(0, 1);
Serial.println(WiFi.localIP());
#ifdef OTA
ArduinoOTA.begin();
#endif
lcd.print("Ready");
}
void clearDisplayIn(int mSec = 5000)
{
clearDisplayTimer = millis() + mSec;
needDisplayUpdate = true;
}
void handleDataFromGoogle(String data) {
int colonIndex1 = data.indexOf(":");
String access = data.substring(0, colonIndex1);
int colonIndex2 = data.indexOf(":", colonIndex1 + 1);
String name = data.substring(colonIndex1 + 1, colonIndex2);
int colonIndex3 = data.indexOf(":", colonIndex2 + 1);
String text = data.substring(colonIndex2 + 1, colonIndex3);
int colonIndex4 = data.indexOf(":", colonIndex3 + 1);
String origin = data.substring(colonIndex3 + 1, colonIndex4);
int colonIndex5 = data.indexOf(":", colonIndex4 + 1);
String destination = data.substring(colonIndex4 + 1, colonIndex5);
String carousel = data.substring(colonIndex5 + 1);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(name);
lcd.setCursor(17, 0);
lcd.print(carousel);
lcd.setCursor(0,1);
lcd.print(access);
lcd.setCursor(0, 2);
lcd.print(origin);
lcd.print(" - ");
lcd.print(destination);
lcd.setCursor(0, 3);
lcd.print(text);
}
void getGoogleData()
{
HTTPClient http;
String data;
lcd.clear();
uint64_t time = esp_timer_get_time();
char url[150];
int pointerShift = sprintf(url, "%s?uid=", mainLinkForSpr);
for (size_t i = 0; i < mfrc522.uid.size; i++)
{
pointerShift += sprintf(url + pointerShift, "%X", mfrc522.uid.uidByte[i]);
}
#ifdef TERMINAL_NAME
pointerShift += sprintf(url + pointerShift, "&terminal=%s", TERMINAL_NAME);
#endif
Serial.println(url);
Serial.println(F("Connecting to google"));
lcd.print(F("Connecting to"));
lcd.setCursor(7, 1);
lcd.print(F("Google"));
http.begin(url, root_ca);
const char *location = "Location";
const char *headerKeys[] = {location};
http.collectHeaders(headerKeys, 1);
int code = http.GET();
Serial.printf("code %d\n", code);
if (code == 302)
{
String newUrl = http.header(location);
http.end();
Serial.println(newUrl);
http.begin(newUrl, root_ca);
code = http.GET();
Serial.printf("status code %d\n", code);
data = http.getString();
Serial.println(data);
lcd.clear();
lcd.setCursor(0, 0);
lcd.setCursor(0, 1);
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(code);
if (code == 403 || code == -1)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Err open terminl"));
lcd.setCursor(0, 1);
lcd.print("for help");
if (code == -1)
{
Serial.println(F("If it says something like start_ssl_client error"));
Serial.print(F("try to update the ssl CERTIFICATE"));
}
else
{
Serial.print(F("Open this link in any browser "));
Serial.println(url);
Serial.println(F("If it says Authorization is ...."));
Serial.println(F("Open the google script and republish it"));
}
}
else
{
lcd.print(F("Something wrong"));
lcd.setCursor(0, 1);
}
}
if (!data.isEmpty() && data.length() > 1)
{
handleDataFromGoogle(data);
}
Serial.printf("time=%d\n", esp_timer_get_time() - time);
clearDisplayIn();
}
void loop()
{
if (needDisplayUpdate && millis() > clearDisplayTimer)
{
lcd.clear();
lcd.setCursor(1, 1);
lcd.print("Ready To Scan");
needDisplayUpdate = false;
lcd.noBacklight();
}
#ifdef OTA
ArduinoOTA.handle();
#endif
if (!mfrc522.PICC_IsNewCardPresent())
{
return;
}
if (!mfrc522.PICC_ReadCardSerial())
{
return;
}
lcd.backlight();
for (size_t i = 0; i < mfrc522.uid.size; i++)
{
Serial.printf("%X", mfrc522.uid.uidByte[i]);
}
getGoogleData();
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
}
it just show ready to scan but as i scan the card, nothing happens