#define CAYENNE_DEBUG // Uncomment to show debug messages #define CAYENNE_PRINT Serial // Comment this out to disable prints and save space #include "CayenneDefines.h" #include "BlynkSimpleEsp8266.h" #include "CayenneWiFiClient.h" #include #include char token[] = "cayenne_token"; // Your network name and password. char ssid[] = ""; char password[] = ""; #define RST_PIN D3 // Configurable, see typical pin layout above #define SS_PIN D8 // Configurable, see typical pin layout above MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. String read_rfid; String ok_rfid_1 = "UID"; String ok_rfid_2 = "UID"; String ok_rfid_3 = "UID"; String ok_rfid_4 = "UID"; //String ok_rfid_5="ffffffff"; //add as many as you need. /* Initialize. */ void setup() { Serial.begin(9600); // Initialize serial communications with the PC while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4) SPI.begin(); // Init SPI bus mfrc522.PCD_Init(); // Init MFRC522 card Cayenne.begin(token, ssid, password); } /* Helper routine to dump a byte array as hex values to Serial. */ void dump_byte_array(byte *buffer, byte bufferSize) { read_rfid = ""; for (byte i = 0; i < bufferSize; i++) { read_rfid = read_rfid + String(buffer[i], HEX); } } void loop() { Cayenne.run(); // Look for new cards if ( ! mfrc522.PICC_IsNewCardPresent()) return; // Select one of the cards if ( ! mfrc522.PICC_ReadCardSerial()) return; dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size); } CAYENNE_OUT(V1) { if (read_rfid == ok_rfid_1) { Cayenne.virtualWrite(V1, "1"); } else { Cayenne.virtualWrite(V1, "0"); } } CAYENNE_OUT(V2) { if (read_rfid == ok_rfid_2) { Cayenne.virtualWrite(V2, "1"); } else { Cayenne.virtualWrite(V2, "0"); } } CAYENNE_OUT(V3) { if (read_rfid == ok_rfid_3) { Cayenne.virtualWrite(V3, "1"); } else { Cayenne.virtualWrite(V3, "0"); } } CAYENNE_OUT(V4) { if (read_rfid == ok_rfid_4) { Cayenne.virtualWrite(V4, "1"); } else { Cayenne.virtualWrite(V4, "0"); } }