Koding Sistem Absensi
Koding Sistem Absensi
h>
#include <ESP8266WiFi.h>
#include <SPI.h>
#include <MFRC522.h>
#include <HTTPSRedirect.h>
#include<Wire.h>
#include<LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Enter command (insert_row or append_row) and your Google Sheets sheet name
(default is Sheet1):
String payload_base =
"{\"command\": \"insert_row\", \"sheet_name\": \"Sheet1\", \"values\": ";
String payload = "";
int blockNum = 2;
byte bufferLen = 18;
byte readBlockData[18];
void setup() {
Serial.begin(9600);
delay(10);
Serial.println('\n');
SPI.begin();
pinMode(BUZZER, OUTPUT);
digitalWrite(BUZZER, LOW);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0); //col=0 row=0
lcd.print("Connecting to");
lcd.setCursor(0,1); //col=0 row=0
lcd.print("WiFi...");
// Connect to WiFi
WiFi.begin(ssid, password);
Serial.print("Connecting to ");
Serial.print(ssid); Serial.println(" ...");
lcd.clear();
lcd.setCursor(0,0); //col=0 row=0
lcd.print("Connecting to");
lcd.setCursor(0,1); //col=0 row=0
lcd.print("Google ");
delay(3000);
Serial.print("Connecting to ");
Serial.println(host);
else
Serial.println("Connection failed. Retrying...");
if (!flag){
lcd.clear();
lcd.setCursor(0,0); //col=0 row=0
lcd.print("Connection fail");
Serial.print("Could not connect to server: ");
Serial.println(host);
delay(3000);
return;
}
delete client;
client = nullptr;
void loop() {
static bool flag = false;
if (!flag){
client = new HTTPSRedirect(httpsPort);
client->setInsecure();
flag = true;
client->setPrintResponseBody(true);
client->setContentTypeHeader("application/json");
}
if (client != nullptr){
if (!client->connected())
{client->connect(host, httpsPort);}
}
else{Serial.println("Error creating client object!");}
lcd.clear();
lcd.setCursor(0,0); //col=0 row=0
lcd.print("Scan your Tag");
mfrc522.PCD_Init();
if ( ! mfrc522.PICC_IsNewCardPresent()) {return;}
if ( ! mfrc522.PICC_ReadCardSerial()) {return;}
/* Read data from the same block */
Serial.println();
Serial.println(F("Reading last data from RFID..."));
else{
data = String((char*)readBlockData);
data.trim();
values += data + ",";
}
}
digitalWrite(BUZZER, HIGH);
delay(100);
digitalWrite(BUZZER, LOW);
delay(100);
digitalWrite(BUZZER, HIGH);
delay(100);
digitalWrite(BUZZER, LOW);
delay(100);
else{
// do stuff here if publish was not successful
Serial.println("Error while connecting");
lcd.clear();
lcd.setCursor(0,0); //col=0 row=0
lcd.print("Failed.");
lcd.setCursor(0,1); //col=0 row=0
lcd.print("Try Again");
}
/* Authenticating the desired data block for Read access using Key A */
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, blockNum,
&key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK){
Serial.print("Authentication failed for Read: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else {
Serial.println("Authentication success");
}
else {
readBlockData[16] = ' ';
readBlockData[17] = ' ';
Serial.println("Block was read successfully");
}