Project Assignment-CPS-Review - Arindam
Project Assignment-CPS-Review - Arindam
Hardware:
1. Arduino
2. NodeMCU
3. RFID Sensor & Tag
4. Jump wires
Software:
1. Library MFRC522 - https://github.com/miguelbalboa/rfid
2. Library “DSC Keybus Interface” - https://github.com/miguelbalboa/rfid
3. Arduino IDE
Diagram:
Logical Connections:
Flow Summary:
4. NodeMCU establishes connection to thinkspeak portal; and sends the ID using http POST
method.
5. NodeMCU reads the code returned by POST method to identify whether data is successfully
saved on thinkspeak or not.
a) Establishes connection to Twilio portal, and sends SMS to student’s mobile phone
number confirming attendance record.
b) Establishes connection to google SMTP server, and sends email to principal confirming
attendance record.
Code - Arduino:
#include <SPI.h>
#include <MFRC522.h>
#include <SoftwareSerial.h>
//
**************************************************************
***************************//
void setup() {
Serial.begin(9600);
// Initialize serial communications with the PC
SPI.begin();
// Init SPI bus
mfrc522.PCD_Init();
// Init MFRC522 card
Serial.println(F("Read personal data on a MIFARE PICC:"));
//shows in serial that it is ready to read
ard.begin (9600);
}
//
**************************************************************
***************************//
void loop()
{
// Prepare key - all keys are set to FFFFFFFFFFFFh at chip
delivery from the factory.
MFRC522::MIFARE_Key key;
for (byte i = 0; i < 6; i++)
{
key.keyByte[i] = 0xFF;
}
//Serial.println(F("**Card Detected:**"));
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
if (ard.available() > 0)
{
for (byte i = 0; i < mfrc522.uid.size; i++) {
ard.write(card_ID[i]);}
}
}
Code - NodeMCU
#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include "base64.h"
HTTPClient http;
int httpCode = 0;
WiFiClient client;
// Initialize components
X509List twilioCert(twilioCertificateRoot);
WiFiClientSecure ipSMSClient, ipMailClient;
char twilioAuth[128];
size_t twilioAuthLength = 128;
char encodedTwilioAuth[128], encodedMessagePrefix[128],
encodedMessageContent[480];
void setup()
{
esp.begin (9600);
//Serial.begin (9600);
Serial.begin(115200);
delay(10);
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);
ipSMSClient.setTrustAnchors(&twilioCert);
Serial.print(F("NTP time...."));
configTime(0, 0, "pool.ntp.org");
time_t now = time(nullptr);
while (now < 24 * 3600)
{
Serial.print(".");
delay(2000);
now = time(nullptr);
}
Serial.println(F("synchronized."));
base64::encode(String(twilioAuth)).toCharArray(encodedTwilioAu
th, 128);
encodeURL(messagePrefix, encodedMessagePrefix);
}
void loop(){
if (esp.available() > 0){
data = esp.read();
//Serial.println ("Receiving data...");
//Serial.println (data, HEX);
if (strdata.length() != 0)
{
strdata += " ";
}
char tempstr[2];
sprintf(tempstr, "%02X", data);
strdata += tempstr;
}
if (strdata.length() == 11)
{
String postStr = "api_key=";
postStr += apiKey;
postStr +="&field1=";
postStr += strdata;
int n = newstr.length();
char msgContent[n+1];
strcpy(msgContent, newstr.c_str());
Serial.printf("messageContent: %s\n", msgContent);
//Send SMS
sendMessage(msgContent);
//Send Mail
Serial.print(F("Email...."));
if (sendMailMessage(msgContent))
Serial.println(F("connected and sent."));
else
Serial.println(F("connection error."));
}
}
else {
Serial.printf("[HTTP] POST... failed, error: %s\n",
http.errorToString(httpCode).c_str());
}
bool smtpValidResponse() {
Serial Output :
Displays – Card ID, HTTP POST return code & email status.
Email Notification:
Gmail SMTP server has been used here to send email to admin mail id. Following screenshot was
captured as part of this project execution:
SMS Notification:
Twilio online messaging service has been used here to send text message to student’s
mobile phone number. Following screenshot was captured as part of this project execution:
VIDEO Recording :
https://drive.google.com/file/d/1Nf3xU2S3dvbLxpMHRtq_rc6rdxAsEBh7/view?usp=sharing