Inspiration
What it does
How I built it
Challenges I ran into
Accomplishments that I'm proud of
What I learned
What's next for Two Factor Authencation
include
include
include
include
RFID rfid(D8, D2); //create RFID object, D8 = SS, D2 = SDA
// EDIT: Change the 'ssid' and 'password' to match your network
const char* ssid = "shywifi"; // wireless network name const char* password = "shy4ever21"; // wireless password
WiFiClient client; //information to be sent via wifi
// EDIT: 'Server' address to match your domain // This could also be 192.168.1.18 or www.domain.com
// This is the data that will be passed into your POST and matches your mysql column String asStringdata; //data from arduino, concatenated UID String yourdatacolumn = "temp1= "; //sends column name String yourdata; //arduinodata + yourdatacolumn
const int output5 = D5; const int output4 = D4;
void setup() {
Serial.begin(115200); pinMode(output5, OUTPUT); pinMode(output4, OUTPUT); digitalWrite(output5, LOW); digitalWrite(output4, LOW);
Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); //attempt connection while (WiFi.status() != WL_CONNECTED) { //while not connected, print dots delay(500); Serial.print("."); } // You're connected now, so print out the status // Print the SSID of the network you're attached to Serial.print("SSID: "); Serial.println(WiFi.SSID());
// Print your WiFi shield's IP address IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip);
// Print the received signal strength long rssi = WiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm");
//Initializing RFID Card Serial.print("Initializing card...\n"); SPI.begin(); rfid.init(); }
void loop() {
digitalWrite(output5, HIGH); digitalWrite(output5, LOW); if (rfid.isCard()) { //if card is read
if (rfid.readCardSerial()) {
Serial.print(rfid.serNum[0]);
Serial.print(" ");
Serial.print(rfid.serNum[1]);
Serial.print(" ");
Serial.print(rfid.serNum[2]);
Serial.print(" ");
Serial.print(rfid.serNum[3]);
Serial.print(" ");
Serial.print(rfid.serNum[4]);
Serial.println("");
digitalWrite(output5, LOW);
digitalWrite(output4, HIGH);
//send POST request to server
for (int i = 0; i < sizeof(rfid.serNum); i++ ) { //combine UID as one string
asStringdata = asStringdata + String(rfid.serNum[i]);
}
yourdata = yourdatacolumn + asStringdata;
// Combine yourdatacolumn header (yourdata=) with the data recorded from your arduino
// (yourarduinodata) and package them into the String yourdata which is what will be
// sent in your POST request
if (client.connect("192.168.43.94",8888)) { // REPLACE WITH YOUR SERVER ADDRESS client.println("POST /add.php HTTP/1.1"); client.println("Host: 192.168.43.94"); // SERVER ADDRESS HERE TOO client.println("Content-Type: application/x-www-form-urlencoded"); client.print("Content-Length: "); client.println(yourdata.length()); client.println(); client.print(yourdata); } delay(500); //delay can be changed for how long till next card read } rfid.halt(); digitalWrite(output4, LOW); } }
Log in or sign up for Devpost to join the conversation.