#define CAYENNE_PRINT Serial #include #include #include #include #include #include LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7); // 0x27 is the I2C bus address for an unmodified module #define SDA_PIN 7 #define RST_PIN 6 MFRC522 rfid(SDA_PIN, RST_PIN); // WiFi network info. char ssid[] = "ssid"; char wifiPassword[] = "wifipassword"; // Cayenne authentication info. This should be obtained from the Cayenne Dashboard. char username[] = "username"; char password[] = "password"; char clientID[] = "clientID"; unsigned long lastMillis = 0; int people1=LOW; int people2=LOW; int door = 5; void setup() { Serial.begin(9600); Cayenne.begin(username, password, clientID, ssid, wifiPassword); SPI.begin(); rfid.PCD_Init(); lcd.setBacklightPin(3,POSITIVE); lcd.setBacklight(HIGH); // NOTE: You can turn the backlight off by setting it to LOW instead of HIGH lcd.begin(16, 2); lcd.clear(); pinMode(door, OUTPUT); } void loop() { Cayenne.loop(); //Publish data every 1 seconds (1000 milliseconds). Change this value to publish at a different interval. if (millis() - lastMillis > 1000) { lastMillis = millis(); //Write data to Cayenne here. This example just sends the current uptime in milliseconds. Cayenne.virtualWrite(0, lastMillis); lcd.setCursor(0,0); lcd.print("Attach a chip"); lcd.setCursor(0,1); lcd.print("or card"); if ( ! rfid.PICC_IsNewCardPresent()) return; if ( ! rfid.PICC_ReadCardSerial()) return; People(); rfid.PICC_HaltA(); rfid.PCD_StopCrypto1(); } } void People() { David(); Ben(); } /*-----------People-----------*/ void David() { if(rfid.uid.uidByte[0] == 0x04 & rfid.uid.uidByte[1] == 0xA0 & rfid.uid.uidByte[2] == 0xB2 & rfid.uid.uidByte[3] == 0xAB && people1==LOW) { people1=HIGH; Cayenne.virtualWrite(5, "1", UNIT_DIGITAL); Serial.println("David came"); lcd.clear(); lcd.setCursor(0,0); lcd.print("Welcome David"); lcd.setCursor(0,1); lcd.print("Opening the door"); digitalWrite(door, HIGH); delay(3000); digitalWrite(door, LOW); lcd.clear(); } else if(rfid.uid.uidByte[0] == 0x04 & rfid.uid.uidByte[1] == 0xA0 & rfid.uid.uidByte[2] == 0xB2 & rfid.uid.uidByte[3] == 0xAB && people1==HIGH) { people1=LOW; Cayenne.virtualWrite(5, "0", UNIT_DIGITAL); Serial.println("David went out"); lcd.clear(); lcd.setCursor(0,0); lcd.print("Goodbye David"); lcd.setCursor(0,1); lcd.print("Opening the door"); digitalWrite(door, HIGH); delay(3000); digitalWrite(door, LOW); lcd.clear(); } else { } } void Ben() { if(rfid.uid.uidByte[0] == 0x20 & rfid.uid.uidByte[1] == 0x71 & rfid.uid.uidByte[2] == 0x18 & rfid.uid.uidByte[3] == 0x4B && people2==LOW) { people2=HIGH; Cayenne.virtualWrite(6, "1", UNIT_DIGITAL); Serial.println("Ben came"); lcd.clear(); lcd.setCursor(0,0); lcd.print("Welcome Ben"); lcd.setCursor(0,1); lcd.print("Opening the door"); digitalWrite(door, HIGH); delay(3000); digitalWrite(door, LOW); lcd.clear(); } else if(rfid.uid.uidByte[0] == 0x20 & rfid.uid.uidByte[1] == 0x71 & rfid.uid.uidByte[2] == 0x18 & rfid.uid.uidByte[3] == 0x4B && people2==HIGH) { people2=LOW; Cayenne.virtualWrite(6, "0", UNIT_DIGITAL); Serial.println("Ben went out"); lcd.clear(); lcd.setCursor(0,0); lcd.print("Goodbye Ben"); lcd.setCursor(0,1); lcd.print("Opening the door"); digitalWrite(door, HIGH); delay(3000); digitalWrite(door, LOW); lcd.clear(); } else { } } //Default function for processing actuator commands from the Cayenne Dashboard. //You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands. CAYENNE_IN_DEFAULT() { CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString()); //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message"); }