#include #include #include #include #define SS_PIN 4 #define RST_PIN 2 Servo myservo; WiFiClient client; MFRC522 rfid(SS_PIN, RST_PIN); int sensorPin = A0; int sensorValue = 0; // int buzzerPin = 6; // D8 String verified = "INSERT YOUR RFID CARD ID"; String id; // COMIO functions void botSetup(const char* ssid, const char* password) { WiFi.begin(ssid, password); Serial.print("Connecting to "); Serial.println(ssid); Serial.print("Connecting "); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("-"); } Serial.println(""); Serial.println("Success!"); Serial.print("Your IP: "); Serial.println(WiFi.localIP()); Serial.println("Setup success."); Serial.println(""); } void botSend(String email, String token, String data) { String result = ""; String x = "ml=" + email + "&tk=" + token + "&dt=" + data; if (client.connect("comio.fionix.net", 80)) { // starts client connection, checks for connection Serial.println(" Server connected."); client.println("POST /send.php HTTP/1.1"); client.println("Host: comio.fionix.net"); client.println("Cache-Control: no-cache"); client.println("Content-Type: application/x-www-form-urlencoded"); client.print("Content-Length: "); client.println(x.length()); client.println(); client.println(x); Serial.print(" Data: "); Serial.println(data); Serial.println(" Data sent."); } else { Serial.println(" Connection failed."); } while (client.connected() && !client.available()) delay(1); while (client.connected() || client.available()) { char c = client.read(); result = result + c; if (result.endsWith("Content-Type: text/html")) result = ""; } } void setup() { Serial.begin(9600); SPI.begin(); rfid.PCD_Init(); myservo.attach(2); // pinMode(buzzerPin, OUTPUT); botSetup("SSID", "PASSWORD"); } void loop() { // check for sensor sensorValue = analogRead(sensorPin); if (sensorValue > 300) { Serial.print("["); Serial.print(sensorValue); Serial.println("] Your safety box is tampered."); // digitalWrite(buzzerPin, HIGH); delay(1000); botSend("EMAIL", "TOKEN", "Warning! Your safety box is tempered"); } else { Serial.print("["); Serial.print(sensorValue); Serial.println("] Your safety box is secure."); botSend("EMAIL", "TOKEN", "Your safety box is secure."); // digitalWrite(buzzerPin, LOW); delay(1000); if (rfid.PICC_IsNewCardPresent() && rfid.PICC_ReadCardSerial()) { // Main code id = String(rfid.uid.uidByte[0]) + String(rfid.uid.uidByte[1]) + String(rfid.uid.uidByte[2]) + String(rfid.uid.uidByte[3]); if (id == verified) { botSend("EMAIL", "TOKEN", "ID scanned: " + id); delay(500); myservo.write(0); delay(5000); Check(); } else { Serial.println("Invalid card scanned!"); botSend("EMAIL", "TOKEN", "Invalid card scanned!"); } } // Halt PICC rfid.PICC_HaltA(); // Stop encryption on PCD rfid.PCD_StopCrypto1(); } } void Check() { sensorValue = analogRead(sensorPin); // gelap if (sensorValue > 300) { Serial.println(" Please close the safety box door"); botSend("EMAIL", "TOKEN", "Please close the safety box door"); Serial.println(sensorValue); delay(5000); Check(); } else { myservo.write(90); delay (5000); exit; } }