#define CAYENNE_DEBUG #define CAYENNE_PRINT Serial //#include // WiFi network info. char ssid[] = "xxxx"; char wifiPassword[] = "xxxxx"; // Cayenne authentication info. This should be obtained from the Cayenne Dashboard. char username[] = "xxxxx"; char password[] = "xxxxx"; char clientID[] = "xxxxxx"; #include #include #define RST_PIN 9 // Configurable, see typical pin layout above #define SS_PIN 10 // Configurable, see typical pin layout above MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. String read_rfid; String ok_rfid_1 = "d9b89455"; String ok_rfid_2 = "97c7251b"; String ok_rfid_3 = "a733f41c"; String ok_rfid_4 = "559acd65"; //String ok_rfid_2="ffffffff"; //add as many as you need. unsigned long lastMillis = 0; int a; int b; int c; int d; void setup() { Serial.begin(9600); /*EEPROM.begin(32); 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 a = EEPROM.get(EEaddress0, a); Serial.println(a); b = EEPROM.get(EEaddress2, b); Serial.println(b); c = EEPROM.get(EEaddress4, c); Serial.println(c); d = EEPROM.get(EEaddress6, d); Serial.println(d); Cayenne.begin(username, password, clientID, ssid, wifiPassword); Serial.println("connected");*/ //pinMode(D4, OUTPUT); } /* 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() { //digitalWrite(D4, HIGH); //Cayenne.loop(); //Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval. /*if (millis() - lastMillis > 10000) { lastMillis = millis(); //Write data to Cayenne here. This example just sends the current uptime in milliseconds. Cayenne.virtualWrite(0, a); Cayenne.virtualWrite(1, b); Cayenne.virtualWrite(2, c); Cayenne.virtualWrite(3, d); //Some examples of other functions you can use to send data. //Cayenne.celsiusWrite(1, 22.0); //Cayenne.luxWrite(2, 700); //Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER); // }*/ Serial.println("reading"); // 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); if (read_rfid == ok_rfid_1) { Serial.println("detected card"); //check1(); } if (read_rfid == ok_rfid_2) { Serial.println("detected card"); //check2(); } if (read_rfid == ok_rfid_3) { Serial.println("detected card"); // check3(); } if (read_rfid == ok_rfid_4) { Serial.println("detected card"); //check4(); } }