I'll admit to being in a frustration spiral of failure, the more I dive into what it takes to satisfy one error, the further down the rabbit hole I go. I've started to understand more of why the errors are occurring (can't be an char if it's HEX, can't convert String to Const char..), but holy cow. >:( I did not imagine I would struggle so badly with reading a UID, checking a list for go/no go, and then reading another UID that cannot be equal to the first, but still on the go/no go list. Newbies....lol
Here's the current work in progress:
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 20 // Reset pin, Configurable
#define SS_PIN 2 // SS / SDA pin, Configurable
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
#define Relay 10 //Relay pin
#define BlueLed 15 //Blue LED pin
#define GreenLed 0 //Green LED pin
#define RedLed 3 //Red LED pin
String read_rfid;
//String ok_rfid_0="13522623058";
//String ok_rfid_1="37165244194";
//String ok_rfid_2="715021058";
//String ok_rfid_3="1992622758";
//String ok_rfid_4="719122558";
//String ok_rfid_5="23113322658";
//String ok_rfid_6="8716120958";
//String ok_rfid_7="3914222358";
//String ok_rfid_8="231721958";
//String ok_rfid_9="11914620158";
//String ok_rfid_10="10324221958"; //add as many as you need.
//int myArray[11]={13522623058, 37165244194, 715021058, 1992622758, 719122558, 23113322658, 8716120958, 3914222358, 231721958, 11914620158, 10324221958};
String okrfid="13522623058, 37165244194, 715021058, 1992622758, 719122558, 23113322658, 8716120958, 3914222358, 231721958, 11914620158, 10324221958";
//String okrfid="87e2e63a, 25a5f4c2, 4732d23a, c71ae33a, 475be13a, e785e23a, 57a1d13a, 278edf3a, e77db3a, 7792c93a, 67f2db3a";
int cardcount = 11;
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
pinMode(Relay, OUTPUT); //Set relay pin mode
digitalWrite(Relay, HIGH); //Set relay pin mode high/low depending on model of relay
pinMode(BlueLed, OUTPUT); //Set led pin mode
pinMode(GreenLed, OUTPUT); //Set led pin mode
pinMode(RedLed, OUTPUT); //Set led pin mode
digitalWrite(RedLed, HIGH); //Set red led pin mode high
}
/*
* 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], DEC); //or HEX
}
}
void no_good(){ //Bad read or id not in list
digitalWrite(Relay, HIGH);
digitalWrite(RedLed, HIGH);
digitalWrite(BlueLed, LOW);
digitalWrite(GreenLed, LOW);
Serial.println("Nope!");
}
void scan_one() { //First scan good, goto second scan
digitalWrite(RedLed, LOW);
digitalWrite(BlueLed, HIGH);
digitalWrite(GreenLed, LOW);
digitalWrite(Relay, HIGH);
Serial.println("Looks Good");
delay(5000); //testing mode reset delay
digitalWrite(Relay, HIGH); //testing mode reset relay
digitalWrite(BlueLed, LOW); //testing mode reset led
digitalWrite(GreenLed, LOW); //testing mode reset led
digitalWrite(RedLed, HIGH); //testing mode reset led
}
void close_relay() { //Relay close, normally open contacts
digitalWrite(Relay, LOW);
digitalWrite(GreenLed, HIGH);
digitalWrite(BlueLed, LOW);
digitalWrite(RedLed, LOW);
delay(5000); //testing mode reset delay
digitalWrite(Relay, HIGH); //testing mode reset relay
digitalWrite(GreenLed, LOW); //testing mode reset led
digitalWrite(RedLed, HIGH); //testing mode reset led
}
void loop() {
// 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);
// Serial.println(read_rfid);
for(int i=0; i < cardcount; i++){
if(strcmp(read_rfid,okrfid)==0){
scan_one();
}
}
// if (read_rfid==ok_rfid_0 || ok_rfid_1 || ok_rfid_2 || ok_rfid_3 || ok_rfid_4 || ok_rfid_5 || ok_rfid_6 || ok_rfid_7 || ok_rfid_8 || ok_rfid_9 || ok_rfid_10){
// scan_one(); //Valid rfid, wait for scan two
// }
// if (read_rfid==ok_rfid_3){
// close_relay(); //Valid rfid, ready to close relay contacts
// }
// else not needed. Anything else is not ok, and will not open the door...
}