#Arduino Help
1 messages · Page 9 of 1
Enum would probably be good if true/false is insufficient
Like having any other password
Could be
I was just saying what's next when we make what we currently have work
Dunno what the actual values that you'd need would be but something vaguely like
enum RFIDPasswordStatus {
UsingCurrentPassword,
UsingFactoryPassword,
GenericErrorCase,
}
Anyway, I'm fairly tired so that's it out me for now; good luck with your work today!
Ok I'm finally free @hallow hinge @coral geyser are you available?
@coral geyser or now?
@old mango are you here?
Because I'm with the code now
And now my problems are different from before
I technically advanced tho
Aight wassup
So
I changed two things
void modoMaestro(){
char password[] = {'c','a','d','3','6','5','\0'};
Serial.println("Ingrese la contraseña");
char user_password[7];
waitForPassword(password, user_password);
byte verificacion = strcmp(password,user_password);
That
The buffer being 7
And
byte bloqueTrailer = sector * 4 + 3;
byte buffer[18];
byte size = sizeof(buffer);
Serial.print(" chau variables");
mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, bloqueTrailer, &keyA, &(mfrc522.uid));
mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, bloqueTrailer, &keyB, &(mfrc522.uid));
Serial.print(" chau autenticacion");
mfrc522.MIFARE_Read(bloqueTrailer, buffer, &size);
Serial.print(" chau read");
if (nuevaKeyA.keyByte != nullptr)
for (byte i = 0; i < MFRC522::MF_KEY_SIZE; i++)
buffer[i] = nuevaKeyA.keyByte[i];
Serial.print(" chau primer null");
if (nuevaKeyB.keyByte != nullptr)
for (byte i = 0; i < MFRC522::MF_KEY_SIZE; i++)
buffer[i + 10] = nuevaKeyB.keyByte[i];
Serial.print(" chau segundo null");
mfrc522.MIFARE_Write(bloqueTrailer, buffer, 16);
Serial.print(" chau escritura");
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
Serial.print(" chau stops");
Serial.println("Proceso Finalizado");
The read that was missing
And now the output goes from
This
To this
¿Quiere acceder al modo maestro u operar normal?
1-Modo Maestro
2-Modo Normal
Ingrese la contraseña
Contraseña correcta, acerque la tarjeta al lector
111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000111111 chau if's chau variables chau autenticacion chau read chau primer null chau segundo null chau escritura chau stopsProceso Finalizado
chau funcion
¿Quiere acceder al modo maestro u operar normal?
1-Modo Maestro
2-Modo Normal
Now all the function is executed
And to see if it did change the password
I had the code that reads the card information for my password
Firmware Version: 0x92 = v2.0
Escanea la tarjeta para ver su UID,SAK, tipo y los bloques de datos...
Card UID: E3 BD CD 1B
Card SAK: 08
PICC type: MIFARE 1KB
Sector Block 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 AccessBits
15 63 00 00 00 00 00 00 FF 07 80 69 E0 E1 E2 E3 E4 E5 [ 0 0 1 ]
62 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
61 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
14 59 PCD_Authenticate() failed: Timeout in communication.
13 55 PCD_Authenticate() failed: Timeout in communication.
12 51 PCD_Authenticate() failed: Timeout in communication.
11 47 PCD_Authenticate() failed: Timeout in communication.
10 43 PCD_Authenticate() failed: Timeout in communication.
9 39 PCD_Authenticate() failed: Timeout in communication.
8 35 PCD_Authenticate() failed: Timeout in communication.
7 31 PCD_Authenticate() failed: Timeout in communication.
6 27 PCD_Authenticate() failed: Timeout in communication.
5 23 PCD_Authenticate() failed: Timeout in communication.
4 19 PCD_Authenticate() failed: Timeout in communication.
3 15 PCD_Authenticate() failed: Timeout in communication.
2 11 PCD_Authenticate() failed: Timeout in communication.
1 7 PCD_Authenticate() failed: Timeout in communication.
0 3 PCD_Authenticate() failed: Timeout in communication.
It verifies sector 15 has now the other password
So far so good.
Now.. The issues
First of all I sometimes encounter inconsistencies for example for executing the master mode code
You see all those 1111111000001111
It's because of the serial print is new card present
In a normal scenario when you enter the password
You will see 11111111
Then you read the card and see the prints
No 0
But sometimes
I put the card and it does
11111111110000000000000
Until I let the card go
Like it's detecting there's a card
But it doesn't Advance
First two times I had to read the card twice
Last time only once
That type of inconsistentencies
But that's the most irrelevant
The other thing is
Ofc the card now works for all the program
Problem
When I changed it password back
It also worked in all the program for some reason
The only place that didn't work was charging money
So I revised it because all was printed but no money was charged which was also weird
Serial.println("Ahora acerque la tarjeta para cargarle plata");
while(!mfrc522.PICC_IsNewCardPresent());
while(!mfrc522.PICC_ReadCardSerial());
mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, bloqueTrailer, &keyA, &(mfrc522.uid));
String plataAEscribir = String(obtenerSaldo() + String(plata).toInt());
plataAEscribir.toCharArray((char*)datosBloque, 16);
mostrarByteArray(datosBloque,16);
mfrc522.MIFARE_Write(numBloque,datosBloque,16);
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
Ok there's an authenticate there
It shouldn't go past it but
At least it doesn't charge money
So I said
Maybe the other functions doesn't have an authenticate
Ahh, is the write failing?
Turns out
Serial.println("Ahora acerque la tarjeta para reaizar su pago");
while(!mfrc522.PICC_IsNewCardPresent());
while(!mfrc522.PICC_ReadCardSerial());
mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, bloqueTrailer, &keyA, &(mfrc522.uid));
int saldo = obtenerSaldo();
Serial.println("Apoye su tarjeta para ver su saldo");
while(!mfrc522.PICC_IsNewCardPresent());
while(!mfrc522.PICC_ReadCardSerial());
mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, bloqueTrailer, &keyA, &(mfrc522.uid));
int saldo = obtenerSaldo();
Serial.print("Su saldo actual es ");
Serial.print(saldo);
They do
So why
Can a card that doesn't have the desired password work
And this even happens in master mode
With cards that already have the password it also executes the function ofc it does nothing but how does it by pass the authenticate
.
So to list the problems
Wait, so, to make it clear
You can read the saldo but when you try to write it, it doesn't do anything?
Or am i misunderstanding
-
inconsistencies in executing
-
master mode executes doesn't matter your password even if it doesn't do anything because itc changes the password to the one you already have it kinda shouldn't
-
excepting charging money the program doesn't care for the card's password and works regardless, all authentications seem worthless
You are because
As I said I changed the password of the card so it's safer and made this code to work only with cards with that password
And that's the point of master mode
Changing the password of the card so you can also use it
Got it so far
But here a non changed password card
Works too in almost all scenarios
It just doesn't charge it money that's the only thing it only works with my card with my password
And even then I don't know why it prints thing beyond the authenticate
What it should print in all this cases
Is this pcd authenticate error message
And I sended the parts of all the functions I'm talking about to show all have authenticate so it doesn't make sense
And well we also have the inconsistencies but idk how to fix that and this is most important
So the problem is that you're authenticating with the wrong password but it's still working?
Yeah like authentication 98% of cases isn't doing anything
For example
This code the original password changer
As you see in this version it expects you to come with my key 0xC and so
As you can see in the declaration of key A
And see what happens when I enter with another password
Acerca la tarjeta al lector para escanear.
Las claves de esta tarjeta deben ser:
Key-A: C0 C1 C2 C3 C4 C5
Key-B: E0 E1 E2 E3 E4 E5
MUY IMPORTANTE: durante el proceso de actualización de las claves
no separes la tarjeta del lector hasta que no termine.
UID de la tarjeta: E3 BD CD 1B
Modificando sector: 15
Fallo en la autenticación Key-A: Timeout in communication.
Claves del sector 15
Key-A: C0 C1 C2 C3 C4 C5
Key-B: E0 E1 E2 E3 E4 E5
Proceso finalizado. Ya puedes retirar la tarjeta del lector RFID
In master mode it says, it's finished thank you
It just executes it anyway
And in the other functions it works just fine no lcd authenticate error nothing
This is one example
This is the other
Basically that's the issue
After solving that
Since master mode finally changes the password at least
Next would be error handling and finally EEPROM
But well ofc this is first
So, to summarize, the issue is that;
When using a card with the wrong password, it's still able to read data?
Yes, and not only that but it by passes all authenticate functions I mean it should go past it but it does
Modo maestro
Is executed all the way
Ofc it doesn't change the password because
It's trying to change to the one I already have
Even if it did
I wouldn't notice
I mean, of course it's going to execute all the way
But yeah charge money doesn't charge it that doesn't discard the fact that it goes through the authentication and prints the messages afterwards
You dont check if the authentication fails
But if it fails
The authentication will not exit the function if it fails
This is showed
It panics
I guess
Or maybe
M
I see the codes and
Ok I show you
You see
The one from the original
Change password
Had error handling
Now the other example
Is from this code
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 5 // Configurable, see typical pin layout above
#define SS_PIN 53 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
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
delay(4); // Optional delay. Some board do need more time after init to be ready, see Readme
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}
void loop() {
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
Well actually other one but
It's just I had to dig in in how dump to serial worked to make it work with my password but
Just as dump to serial
Calls haltA stop crypto
Maybe it has error handling built into it
So maybe
It does
Authentication just gives back something but doesn't panic on it's own
So maybe I just assumed it did
PCD_Authenticate will not do anything except communicate with the chip
Do you know what it returns?
It will return STATUS_OK if it succeeds
No status nooooo
So I was thinking
Couldn't we see in the repository how the error handling is made and copy the behavior? And while we are at it do the error handling I personally wanted to do?
Yep
Honestly, you could derive it from the original code for the key changing
Since I don't know Cpp watching the repository I didn't understand a thing
It's so much verbose-
It would be nice if we could strip the key parts of it
I just want it to say
Hey you don't have the correct card password bro bye and goes back to the beginning
And then well if in master mode you already have the password good it says, hey you are already fine, bye
That's it
I'm not talking about that, but rather the literal mechanism by which i detects/handles errors
What I said is that code it's too much code
To be pasting in all functions
So I had an idea
Well two ideas.
First one.
Create a function with status code, authenticate and all, and in all places there's authenticate call that function
Second idea.
Do all that at the beginning when you start normal mode ask for your card and then you can do as you please but with this method I will have to do like the same code twice because I would need to authenticate in master mode too
whichever you think is more suitable
I think the first one is the one that makes the more sense
Man I miss being in visual Studio and working in modules-
This code is so ugly -
So, now the questions are, what do we all the function, what parameters it receives and which it gives back and then how to implement it looking at the other code's error handling
well, first, describe in precise terms what the functions does
Well it does the error handling regarding authenticate, so if the key is the correct one and there will only be one correct answer the code will just go on everything is fine, if not tell you that the password of your card is incorrect and you can't access and then take you back to the beginning so maybe you can use master mode to solve it if you are the owner
If I would have to guess
It would need to receive the same parameters authentication needs so we can use it inside
I guess
yeah, sounds about right?
Also, before you try to do anything that writes to the saldo block, I'd advise you to read section 8.6.2.1 of that spec
There seems to be a specific way that data needs to be formatted
Looking at how MIFARE_Write on the sector trailer block seems to have failed when the access bits were set incorrectly
I know that the rfid functions need bytes to work with
That could be another failure point
Not just bytes but arranged specifically like this
For what I've seen
I need to declare a variable of status code type
Then
Binding what's given back of doing authenticate to that variable
Since it gives back an status code type also
And then as if it's on
Ok*
If not I can print the error message and return
yep
since it's an authenticate function, you probably want some way to tell the caller that the authentication failed
Ok so in my case my function wouldn't return anything
ah, so it'd loop until authentication succeeds?
No it would just print the message and return to the first menu
So if you are the owner you could use master mode on that card
i'm probably misunderstanding something but if the authentication function doesn't return a value, how does the code calling the authentication function know whether the authentication succeeded or not?
It will call it
And if it fails
It will exit the function and go back to the very beginning
Btw I did this I show you code above to show you where I am, I made status global just in case
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 5
#define SS_PIN 53
MFRC522 mfrc522(SS_PIN, RST_PIN);
MFRC522::MIFARE_Key keyA = {keyByte: {0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5}};
MFRC522::MIFARE_Key keyB = {keyByte: {0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5}};
MFRC522::StatusCode estado;
byte sector = 15;
byte numBloque = 60;
byte bloqueTrailer = 63;
void Authentication(){
estado = mfrc522.PCD_Authenticate(
MFRC522::PICC_CMD_MF_AUTH_KEY_A, bloqueTrailer, antiguaKeyA,
&(mfrc522.uid)
);
if (estado != MFRC522::STATUS_OK) {
Serial.print("Autenticacion fallida, tarjeta rechazada");
Serial.println(mfrc522.GetStatusCodeName(estado));
return;
}
}
Oh
I need to change antigua key a
To key a
Aside from that
Anything else?
so, the caller would be something like
void a_random_function() {
for(;;) {
Authenticate();
if(estado != STATUS_OK)
continue;
/* remainder of the code */
}
}
?
I don't get the question
See here
I use authenticate
Well now I would call my function
That has authenticate with the error handling inside
So, it's the way I made it ok?
Since key A, trailer sector and state are global
It doesn't recieve anything
And since it will just print and go back to the beginning of the program
It doesn't return anything
so, the issue is that, as you currently have it, the following is what'll happen if PCD_Authenticate fails
Authentication() is called
PCD_Authenticate() is called, and returns an error
It prints "Autenticacion fallida, ..."
It returns from Authentication()
And then it continues right on and calls obtenerSaldo()
Which will of course fail because it's not authenticated
And inside I only do authenticate bind it to the variable and ask if it's ok
I don't understand at all what you say is that the return will return to the former function that called it and not the beginning of the program entring in a infinite loop or worse trying to perform the action not being able to?
Well now that I think about it I guess it would work as always
It would say hey you shouldn't do that, you just woups
Would
And that's it
What do I do then? A goto?
return will only return up ONE function
there are probably some languages that are exceptions to this but in any mainstream language i can think of that will be the case
Well
The proper way to do this
Since is way less verbose than I thought
We could just paste the code inside the function everywhere it's only like there more lines, that would be a solution
would be making Authenticate
bool Authenticate() {
// ...
if(status != STATUS_OK) {
// ...
return false;
} else {
return true;
}
}
Unless you think there's a better way to be less verbose and avoid repetition
And then this would be
if(!Authenticate()) {
return false;
}
well
Tho why negate it? Why don't just return false right away?
what do you mean by that?
Like
If it fails shouldn't it return false and return true if it works
Like this
bool Authentication(){
estado = mfrc522.PCD_Authenticate(
MFRC522::PICC_CMD_MF_AUTH_KEY_A, bloqueTrailer, keyA,
&(mfrc522.uid)
);
if (estado != MFRC522::STATUS_OK) {
Serial.print("Autenticacion fallida, tarjeta rechazada");
Serial.println(mfrc522.GetStatusCodeName(estado));
return false;
} else {
return true;
}
}
Function is like this now
Do you agree?
Yeah
still not clear on this
Now I need to understand how would we call it
If you see your message below the if status bla Bla you write false instead of true
Ah wait a Moment
Forget it
Now this
if Authenticate() returns false (because of the !), an error occurred, so the current function should also fail
if(!Authentication()) { return false; }
But my functions currently don't return booleans
If Authentication() is being called in a loop, it may be more appropriate to do continue instead of return false if you want to retry the authentication
No, in all cases I want to return to the beginning because if it doesn't authenticate it will never will the card isn't allowed access
And one important thing to note
There are functions nested
Well, the way to do that is literally just return false all until you're back at the beginning
First you choose between master and normal
Master is the one you saw is only one
Then inside normal you can call the other three
So you say
That aside from authentication
The leer saldo cargar saldo etc also return booleans
And also the normal mode function?
Because ig that would change it's functionality but yes allow me to do what I want to
i mean
Wouldn't*
can leerSaldo cargarSaldo etc fail?
if they can, it's probably better to immediately exit back out than try to continue normally
What I understood is that all functions that have authentication in them and in general can fail should have a boolean and it also would allow me to exit functions and go back to the beginning as I wanted to
that's the foundational principle of error handling
making sure that if something goes wrong, you don't keep doing things as if nothing went wrong
because that could make things even worse
yeap
Ok
I will do it with one to see if I understood how to call and what to do
If it's fine I'll do the same with the others
also, if you need to pass around more information than a simple 'true'/'false', you can do it like MFRC522 and have STATUS_OK and then STATUS_ERROR_<type> variants that you can return
but if all you need to know is "did this work or did this fail" booleans work pretty well
For now yes because the issue now
Is that it only works if the card has the password
After this works I want to treat two other scenarios
But in master mode
bool comprar() {
unsigned char datosBloque[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
Serial.println("Elija un producto");
Serial.println("1-Fernet con Coca 400$");
Serial.println("2-Sex on the beach 250$");
Serial.println("3-Agua 100$");
char input = waitForOption();
int precio = 0;
switch (input) {
case '1':
precio = 400;
break;
case '2':
precio = 250;
break;
case '3':
precio = 100;
break;
default:
Serial.println("Elija una opcion valida");
return;
}
Serial.println("Ahora acerque la tarjeta para reaizar su pago");
while(!mfrc522.PICC_IsNewCardPresent());
while(!mfrc522.PICC_ReadCardSerial());
if(!Authentication()) { return false; }
int saldo = obtenerSaldo();
if(saldo < precio){
Serial.print("Su saldo es insuficiente");
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
return;
}
String plataADescontar = String(obtenerSaldo() - precio);
plataADescontar.toCharArray((char*)datosBloque, 16);
mfrc522.MIFARE_Write(numBloque,datosBloque,16);
Serial.println("Proceso terminado disfrute de su bebida");
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
return;
}
Here in the buy function
I did it
I can show you the original again if you need
To check it's fine and I do the same with the rest
Well, a couple issues with that
Since it's a function with a return type that's not void, you have to return a value from it
So those return; statements won't work
Well that's really problematic
you'd need to change those to return false; or return true;
But
I mean
Originally
If I remember correctly
That would only return me to the normal mode function
So I could chose again
If buy or whatever
But
If this function as a whole returns false
Wouldn't I want normal mode also to return false?
Because
With authentication errors
I want go go all the way back
With this one's, it would be kinda annoying
That would exit the function and go back to the previous ? Then I guess that works
Anything else?
there is also the issue of returning values from functions
for things like obtenerSaldo()
the standard pattern for this is passing a pointer to a buffer to the function
so for example, obtenerSaldo() would become something like
bool obtenerSaldo(int *output) {
// ...
if(status != STATUS_OK) {
return false;
} else {
int saldoActual = /* ... */;
// write saldoActual to whatever is pointed to by `output'
*output = saldoActual;
return true;
}
And then that'd be called like
int saldo;
if(!obtenerSaldo(&saldo)) {
return false; // or whatever the error handling method is here
}
// if obtenerSaldo() returned true, then `saldo' now has the value in it
This is why I wanted to avoid error handling damn ir-
It*
I have to change all my code and how it does stuff when it worked just fine for one feature
Let's go step by step
As for the bigger functions the read, write buy
Now they return booleans
I call my function that way to return false if it fails.
And all returns from before I turn them into return true?
if that works, then sure?
One question.
What will happen if authentication works and returns a true?
Isn't it the same and will it exit the function?
what do you mean by that
You said that all the returns I had
That were intended to end the function and go back to the previous I replace them with return true because it would cause the same effect right?
i don't understand how that relates to authentication returning true
Because if return true exits the function
Wouldn't that mean that authentication would end the function either way?
no?
when you do
if(!Authenticate()) {
return false;
}
that only does something if Authenticate() return false
It can only return false and it's inside an if
Ok
So that solves the big three problem
Now
About normal and master mode that are the bigger functions
if you just had return Authentication(); then yeah, it would work like you were worried about
Ok so now I will change those three functions and show you
If it's fine I will move to the bigger two
And finally the smalles
Smallest*
Ok here I go
bool leerSaldo() {
Serial.println("Apoye su tarjeta para ver su saldo");
while(!mfrc522.PICC_IsNewCardPresent());
while(!mfrc522.PICC_ReadCardSerial());
if(!Authentication()) { return false; }
int saldo = obtenerSaldo();
Serial.print("Su saldo actual es ");
Serial.print(saldo);
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
return true;
}
This one is good?
yeap
bool comprar() {
unsigned char datosBloque[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
Serial.println("Elija un producto");
Serial.println("1-Fernet con Coca 400$");
Serial.println("2-Sex on the beach 250$");
Serial.println("3-Agua 100$");
char input = waitForOption();
int precio = 0;
switch (input) {
case '1':
precio = 400;
break;
case '2':
precio = 250;
break;
case '3':
precio = 100;
break;
default:
Serial.println("Elija una opcion valida");
return;
}
Serial.println("Ahora acerque la tarjeta para reaizar su pago");
while(!mfrc522.PICC_IsNewCardPresent());
while(!mfrc522.PICC_ReadCardSerial());
if(!Authentication()) { return false; }
int saldo = obtenerSaldo();
if(saldo < precio){
Serial.print("Su saldo es insuficiente");
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
return true;
}
String plataADescontar = String(obtenerSaldo() - precio);
plataADescontar.toCharArray((char*)datosBloque, 16);
mfrc522.MIFARE_Write(numBloque,datosBloque,16);
Serial.println("Proceso terminado disfrute de su bebida");
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
return true;
}
This one?
You missed the return in the default of the switch
yeah, looks ok otherwise
and finally
bool cargarSaldo() {
char plata[16];
unsigned char datosBloque[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
Serial.println("ingrese la cantidad de dinero que desea cargar y finalice con cualquier letra");
bool esNumero = obtenerPlata(plata);
if(esNumero == false){
Serial.println("No ingreso un numero");
return true;
}
Serial.println("Ahora acerque la tarjeta para cargarle plata");
while(!mfrc522.PICC_IsNewCardPresent());
while(!mfrc522.PICC_ReadCardSerial());
if(!Authentication()) { return false; }
String plataAEscribir = String(obtenerSaldo() + String(plata).toInt());
plataAEscribir.toCharArray((char*)datosBloque, 16);
mostrarByteArray(datosBloque,16);
mfrc522.MIFARE_Write(numBloque,datosBloque,16);
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
return true;
}
This one?
I mean, I think the MIFARE_Write won't work but yeah, the returns are good
Why?
this
But it worked before
oh, really?
specifically, you've written to blocks that are NOT the trailer and it's worked?
Yes the financial system works since like a month ago
Ok so now
The two biggest functions
First normal mode
bool modoNormal() {
Serial.println("\n¿Quiere cargar plata, comprar o verificar su saldo?");
Serial.println("1-Cargar Plata");
Serial.println("2-Comprar");
Serial.println("3-Ver estado de saldo");
char input = waitForOption();
switch (input) {
case '1':{
cargarSaldo();
return;
}
case '2':{
comprar();
return;}
case '3':{
leerSaldo();
return;}
default:
Serial.println("Elija una opcion valida");
return ;
}
}
How do we do it?
does modoNormal() actually need to return to its caller if an authentication failure occurs?
Yes because you would be stuck otherwise
The password would be wrong
You would return to normal mode
What do you do?
Now if you return to the beginning
i mean it already returns anyway
what is modoNormal() called by?
I change the return type to void then
void loop() {
Serial.println("\n¿Quiere acceder al modo maestro u operar normal?");
Serial.println("1-Modo Maestro");
Serial.println("2-Modo Normal");
char input = waitForOption();
switch (input) {
case '1':{
modoMaestro();
return;
}
case '2':{
modoNormal();
return;
}
default:
Serial.println("Elija una opcion valida");
return;
}
}
Oh, yeah, I think you'd be fine leaving the return type for the modoNormal() as void
Ok now let's move to master then
Let me see what can I do
K
First issue
Here I check both keys
the key is that you only need to return false if the code calling the function would do something bad if it assumed the function succeeded when it really failed
sure?
And I rename my function to authenticationA and this new authenticationB
could always just try doing both in Authentication()?
and if either fails, return false
oh, so this is the only one that also checks keyB?
Yes
That's why
Oh
I could not so a function
Because I won't repeat
Tho
It would look a bit ugly to be honest
One with a function and the other one raw
Yeah I prefer the function one
Then yeah, do that
bool Authentication_B(){
estado = mfrc522.PCD_Authenticate(
MFRC522::PICC_CMD_MF_AUTH_KEY_B, bloqueTrailer, keyB,
&(mfrc522.uid)
);
if (estado != MFRC522::STATUS_OK) {
Serial.print("Autenticacion fallida, tarjeta rechazada");
Serial.println(mfrc522.GetStatusCodeName(estado));
return false;
} else {
return true;
}
}
yea
bool modoMaestro(){
char password[] = {'c','a','d','3','6','5','\0'};
Serial.println("Ingrese la contraseña");
char user_password[7];
waitForPassword(password, user_password);
byte verificacion = strcmp(password,user_password);
if(verificacion == 0){
Serial.println("Contraseña correcta, acerque la tarjeta al lector");
MFRC522::MIFARE_Key keyA = {keyByte : {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}};
MFRC522::MIFARE_Key keyB = {keyByte : {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}};
MFRC522::MIFARE_Key nuevaKeyA = {
keyByte : {0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5}};
MFRC522::MIFARE_Key nuevaKeyB = {
keyByte : {0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5}};
const byte sector = 15;
for(;;){
if (!mfrc522.PICC_IsNewCardPresent()) {
Serial.print(!mfrc522.PICC_IsNewCardPresent());
continue;
}
if (!mfrc522.PICC_ReadCardSerial()) {
Serial.print(!mfrc522.PICC_ReadCardSerial());
continue;
}
Serial.print(" chau if's");
byte bloqueTrailer = sector * 4 + 3;
byte buffer[18];
byte size = sizeof(buffer);
Serial.print(" chau variables");
if(!Authentication_A()) { return false; }
if(!Authentication_B()) { return false; }
Serial.print(" chau autenticacion");
mfrc522.MIFARE_Read(bloqueTrailer, buffer, &size);
Serial.print(" chau read");
if (nuevaKeyA.keyByte != nullptr)
for (byte i = 0; i < MFRC522::MF_KEY_SIZE; i++)
buffer[i] = nuevaKeyA.keyByte[i];
Serial.print(" chau primer null");
if (nuevaKeyB.keyByte != nullptr)
for (byte i = 0; i < MFRC522::MF_KEY_SIZE; i++)
buffer[i + 10] = nuevaKeyB.keyByte[i];
Serial.print(" chau segundo null");
mfrc522.MIFARE_Write(bloqueTrailer, buffer, 16);
Serial.print(" chau escritura");
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
Serial.print(" chau stops");
Serial.println("Proceso Finalizado");
Serial.print(" chau funcion");
break;
}
} else{
Serial.println("Contraseña Incorrecta");
return false;
}
}
Mm
I see an issue
The for inside
If I remember correctly
The only reason I placed that for
like i said here, i think you can just use normal returns without returning a value here
Is that when starting to debug
I didn't put the prints
So I though
New card present and such
Was failing
So instead of everywhere else I used the while here I used if's
Ok so..
Let me re write it then
void modoMaestro(){
char password[] = {'c','a','d','3','6','5','\0'};
Serial.println("Ingrese la contraseña");
char user_password[7];
waitForPassword(password, user_password);
byte verificacion = strcmp(password,user_password);
if(verificacion == 0){
Serial.println("Contraseña correcta, acerque la tarjeta al lector");
MFRC522::MIFARE_Key keyA = {keyByte : {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}};
MFRC522::MIFARE_Key keyB = {keyByte : {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}};
MFRC522::MIFARE_Key nuevaKeyA = {
keyByte : {0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5}};
MFRC522::MIFARE_Key nuevaKeyB = {
keyByte : {0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5}};
const byte sector = 15;
for(;;){
if (!mfrc522.PICC_IsNewCardPresent()) {
Serial.print(!mfrc522.PICC_IsNewCardPresent());
continue;
}
if (!mfrc522.PICC_ReadCardSerial()) {
Serial.print(!mfrc522.PICC_ReadCardSerial());
continue;
}
Serial.print(" chau if's");
byte bloqueTrailer = sector * 4 + 3;
byte buffer[18];
byte size = sizeof(buffer);
Serial.print(" chau variables");
if(!Authentication_A()) { return; }
if(!Authentication_B()) { return; }
Serial.print(" chau autenticacion");
mfrc522.MIFARE_Read(bloqueTrailer, buffer, &size);
Serial.print(" chau read");
if (nuevaKeyA.keyByte != nullptr)
for (byte i = 0; i < MFRC522::MF_KEY_SIZE; i++)
buffer[i] = nuevaKeyA.keyByte[i];
Serial.print(" chau primer null");
if (nuevaKeyB.keyByte != nullptr)
for (byte i = 0; i < MFRC522::MF_KEY_SIZE; i++)
buffer[i + 10] = nuevaKeyB.keyByte[i];
Serial.print(" chau segundo null");
mfrc522.MIFARE_Write(bloqueTrailer, buffer, 16);
Serial.print(" chau escritura");
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
Serial.print(" chau stops");
Serial.println("Proceso Finalizado");
Serial.print(" chau funcion");
break;
}
} else{
Serial.println("Contraseña Incorrecta");
return;
}
}
Like that?
yeah
Ok now what's left are the smaller functions
I will just send them and tell me if any need change
regarding this, it might be easier to debug if you did
bool new_card = mfrc522.PICC_IsNewCardPresent();
if(!new_card) {
Serial.print('n');
continue;
}
bool read_card = mfrc522.PICC_ReadCardSerial();
if(!read_card) {
Serial.print('r');
continue;
}
just a side note
I can't mark down that message
If it keeps causing issues me might do that
char waitForOption(void)
{
while (!Serial.available());
char dato = Serial.read();
while (Serial.read() != 10);
return dato;
}
bool obtenerPlata(char *plata){
int i;
for (i = 0; i < 15; ++i)
{
char input = waitForOption();
if (input >= '0' && input <= '9') {
plata[i] = input;
} else break;
}
plata[i] = '\0';
return i;
}
char* waitForPassword(char* password, char* user_password){
int i;
for(i=0;i<strlen(password);i++){
char input = waitForOption();
user_password[i] = input;
}
user_password[i] = '\0';
return user_password;
}
int obtenerSaldo(){
unsigned char datosBloque[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte arraySize = 18;
mfrc522.MIFARE_Read(numBloque,datosBloque,&arraySize);
String saldo_actual = String((char*)(datosBloque));
int saldoActual = saldo_actual.toInt();
return saldoActual;
}
because if you do
if(!PICC_IsNewCardPresent())
Serial.print(!PICC_IsNewCardPresent());
The two PICC_IsNewCardPresent() calls might not be returning the same value
Here are the rest of the functions
There are two different if's for each other
I don't think change is needed there
no i mean what the serial is saying might not be the same as the result in the if
eh, prolly still fine
Ok let's try it then
If it does what it should
First I would try to use the card that shouldn't work
Then the one that should
Finally with master mode change the password for the one that shouldn't and see if it now does
errors
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino: In function 'bool Authentication_A()':
Prototipo_RFID_Escritura:21:3: error: no matching function for call to 'MFRC522::PCD_Authenticate(MFRC522::PICC_Command, byte&, MFRC522::MIFARE_Key&, MFRC522::Uid*)'
);
^
In file included from C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino:2:0:
C:\Users\fuchi\OneDrive\Documentos\Arduino\libraries\MFRC522\src/MFRC522.h:320:13: note: candidate: MFRC522::StatusCode MFRC522::PCD_Authenticate(byte, byte, MFRC522::MIFARE_Key*, MFRC522::Uid*)
StatusCode PCD_Authenticate(byte command, byte blockAddr, MIFARE_Key *key, Uid *uid);
^~~~~~~
C:\Users\fuchi\OneDrive\Documentos\Arduino\libraries\MFRC522\src/MFRC522.h:320:13: note: no known conversion for argument 3 from 'MFRC522::MIFARE_Key' to 'MFRC522::MIFARE_Key*'
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino: In function 'bool Authentication_B()':
Prototipo_RFID_Escritura:36:3: error: no matching function for call to 'MFRC522::PCD_Authenticate(MFRC522::PICC_Command, byte&, MFRC522::MIFARE_Key&, MFRC522::Uid*)'
);
^
In file included from C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino:2:0:
C:\Users\fuchi\OneDrive\Documentos\Arduino\libraries\MFRC522\src/MFRC522.h:320:13: note: candidate: MFRC522::StatusCode MFRC522::PCD_Authenticate(byte, byte, MFRC522::MIFARE_Key*, MFRC522::Uid*)
StatusCode PCD_Authenticate(byte command, byte blockAddr, MIFARE_Key *key, Uid *uid);
^~~~~~~~~~~~
C:\Users\fuchi\OneDrive\Documentos\Arduino\libraries\MFRC522\src/MFRC522.h:320:13: note: no known conversion for argument 3 from 'MFRC522::MIFARE_Key' to 'MFRC522::MIFARE_Key*'
exit status 1
no matching function for call to 'MFRC522::PCD_Authenticate(MFRC522::PICC_Command, byte&, MFRC522::MIFARE_Key&, MFRC522::Uid*)
ah, try &keyA and &keyB instead of keyA and keyB
Ah, yeah, signature is:
StatusCode PCD_Authenticate(byte command, byte blockAddr, MIFARE_Key *key, Uid *uid);
so it wants a pointer for the key parameter
It was only that it uploaded
So now let's try
It passed the first test
Now let's try the second test
It passed the second test
First failure
So it passed that
Nothing worked and it printed the message and came back where it should
It also passed that
The card with the password worked
It didn't pass in master mode that
Even tho this one already has the password changed
And in the function key A and key B are the default
It still passed
¿Quiere acceder al modo maestro u operar normal?
1-Modo Maestro
2-Modo Normal
Ingrese la contraseña
Contraseña correcta, acerque la tarjeta al lector
11111111111111111111111110000000000000000000011111111111111110000000001111110000011111111111111111111111111111111111111111 chau if's chau variables chau autenticacion chau read chau primer null chau segundo null chau escritura chau stopsProceso Finalizado
chau funcion
Not only that
I had to read the cars like 4 times now
As you'll see by the zero's
But before speaking of fixing it I will do the last test
To see if that's the only problem
The last test is changing the password via master mode and see if it does well now
It failed
It rejected this one, it takes like key A is the global one and it doesn't overwrite it or shadow it the new declaration
¿Quiere acceder al modo maestro u operar normal?
1-Modo Maestro
2-Modo Normal
Ingrese la contraseña
Contraseña correcta, acerque la tarjeta al lector
111111111111111111111111111111 chau if's chau variablesAutenticacion fallida, tarjeta rechazada
¿Quiere acceder al modo maestro u operar normal?
1-Modo Maestro
2-Modo Normal
And speaking of Inconsistencies you see it read the card first try now
I think I will just change the name of the key and not use the global name let's see if that solves all
Issue is that this function checks for the global one 
I mean ofc I could
Literally copy the two functions and change the name but
I'm repeating way too much code
Isn't it a way that it will authenticate the key I pass as a parameter so I don't keep creating new functions that do the same?
yeah
Or a way to reassing in master mode key a and key b to the equivalents I need here
Both work
To shadow
Something like
enum KeyKind {
KEY_A,
KEY_B,
}
bool AuthenticateMIFAREKey(KeyKind kind, MFRC522::MIFARE_KEY *key) {
MFRC522::PICC_Command command;
if(kind == KEY_A) {
command = MFRC522::PICC_CMD_MF_AUTH_KEY_A;
} else if(kind == KEY_B) {
command = MFRC522::PICC_CMD_MF_AUTH_KEY_B;
} else {
return false;
}
estado = mfrc522.PCD_Authenticate(command, bloqueTrailer, key, &(mfrc522.uid));
// ...
}
i don't understand what you mean here
In the global scope
Key a and b are declared
Which is fine for almost everywhere
But in master mode
Key A and Key B are created again or should because here they should be the default
But it seems key a and key b are still taken as the global one
At least
In the function
no?
Maybe that's the thing the function
you can pass in any key as key
I don't talk about this
That seemed complicated
So I went for option number two
Reassing key A and key B
And described what was happening rn
reassing?
Yeah
I want that key A and B have other values in that function
But that doesn't happen
this is actually, like, the easiest way
When I call the function to authenticate them I takes as key a and b are the global ones
then you'd have
bool Authenticate_A() {
return AuthenticateMIFAREKey(KEY_A, &keyA);
}
bool Authenticate_B() {
return AuthenticateMIFAREKey(KEY_B, &keyB);
}
for the normal case
So much re writting I don't know if I should go to sleep or keep going because it's close to being over
I thought the point of that function was to be called everywhere and be passed the key to authenticate why are there still those two functions?
you said it seemed complicated?
I think too much work for today let's finish it tomorrow
More than anything because I work at my bed with my legs crossed and I'm so uncomfortable and I also have this horrifying wire gore and two went out which is annoying
This isn't ok(?
In any case
Tomorrow we finish with this so it works as intended, then we do the other error handling I talked to you about and finally if possible at least start the EEPROM deal so this prototype can be finally finished
Well then there would be moving that functionality that was tested alone with the rest of the project
After that the only thing left are sensors, really easy stuff I already have a code on how the ultra sound ones work
I will be so happy to say bye bye to rfid and hi sensors
Tho I will see rfid back in rust but it will be way more tidy
just a heads up, probably won't be as active in chat tomorrow, since today i've mostly just been sketching out UI stuff
The thing is you went to sleep today if I recall by the time I wake up tomorrow (?
In any case we would work at night again
Maybe tomorrow this can be finished
It's so close
I'm so much looking forward to say it bye bye forever
lol true
even i, sitting on the other side of the screen, want to say goodbye to it already 😔
See? Working with the rfid to this level of deep just raises one's suicidal wishes 
2 months I think by now
Literally
The rest of the project
One week
Lcd, keyboard, relays
This mf
2 months
yeah, i get that
embedded can be such a hole when you get stuck
The primary problem this is my first project when I started it I had starting coding one month ago and I don't know cpp or have that much Arduino experience in any other thing close to null 
I hurts me to ask so much help but I think it's impossible not too in this case so I want to get rid of it to do normal stuff I should be able to do on my own and grow as a programmer
It*
what class are you doing this for, anyway?
I'm in a" technical "(?) School, in last year we have an extra one, for the subject named project, I'm going to be in some months a technician in electronics
Tho with this teacher the subject is basically..
"Good luck, it better don't be bad"
Well more or less
But the REAL problem
Is all the projects and programming knowledge I lost because of the pandemic the two most important years, the only two years were we had programming subjects, started using Arduino, could've built the robot and compited
I would've learned cpp
And I would likely had loved programming and did everything I did this 4 months
I would have two years of experience
So I would be far more prepared
More so because since I loved programming when I got into it for real I would've been digging deep that two years
In this four months I learned C to a decent extent, Arduino, like how to use the serial port and some other stuff, things of cpp not really deep, OOP, python to a really nice extent because of the course I'm doing and got recently into Django, also rust, and when I finish all of this I plan to learn cpp and finally HTML, CSS and JS
Imagine that motivation with two years of time
I would be so prepared or well
I wouldn't blame anyone
And at least if I need help it would be less and I could understand better what they say to me
And from there I will be satisfied and I will start doing projects which is what I really should do to get experience and become a better programmer, prepare for jobs and gain confidence
damn. well, best of luck in your endeavours; hopefully you can get this project finalised speedily and then keep on learning and improving!
Thanks, I want to get rid of it so I can focus in Django
And surprisingly enough I kinda have my first job
Oh awesome
Two classmates want me to do their project (only code)
Lucky for me
89% of their components are the same of my project
The issue is
The one that's now.
Not*
A module for sending messages via sim to a phone
It can be
Or really complicated or really easy.
Anyways aside from django because my course ain't waiting after finishing this project I will focus on the classmate's one and the re writting of this project in rust
After those two finally learn cpp and then you know
I hope with everything I learned from rust, my experience using Arduino, my knowledge of C, and that I am somewhat familiarized to OOP thanks to python, C++ isn't going to be that much of a pair
Pain*
What do you think? Since you know cpp
Actually, sorry, lemme just get this out of the way real quick: are you, as a student working on this assignment, allowed to receive help with debugging this? And are you allowed to help those classmates with their project? Should've asked this at the beginning, to be honest
Ofc as I told you we are by our own meds the only thing that matters is that the project is done at least with this teacher, the subject is just "good luck"
Not like earlier programming subjects were for example we couldn't use libraries
Here we just gotta do it doesn't matter how
@old mango think you will be available tonight?
"own meds"?
And yes, I'm more less available
Again, a bit busier than yesterday tho
Well yes because we aren't teach anything we just have to do it
Anyways I'll be back in 15 minutes
Meanwhile
What do you think of this function to verify any key to solve our problem
bool Authentication(MFRC522::PICC_Command command, MFRC522::MIFARE_KEY *key){
MFRC522::StatusCode estado = mfrc522.PCD_Authenticate(command, bloqueTrailer, key, &(mfrc522.uid));
if (estado != MFRC522::STATUS_OK) {
Serial.print("Autenticacion fallida, tarjeta rechazada");
Serial.println(mfrc522.GetStatusCodeName(estado));
return false;
} else {
return true;
}
}
In case you are wondering
Command is for
Oh, i was just wondering what that meant
PICC_CMD_MF_AUTH_KEY_A or PICC_CMD_MF_AUTH_KEY_B
The only "meds" i know is "medications"
I know that phrase exist but maybe the "meds" I talk about wasn't written like that
Arguments are the only two things that could change when performing an authentication is pretty simple
The key and which of the two
Anyways I'll be back in 15 minutes tell me what you think of that solution
Yeah, from a quick glance that looks fine?
Btw a question I always had of how the code works, why do I have to ask if the passwords are null ptrs when I know that's impossible?
And ofc I back now to try that code and see if it solves the issue and we can move on
In modoMaestro?
You actually dont
If i remember, those were originally from the cambiarKeys, yes?
cambiaraKeys took nuevaKeyA and nuevaKeyB as parameters, so the checking for nullptrs is actually a very normal sanity check
However, in your code, there shouldnt be any issue because nuevaKeyA and nuevaKeyB are declared in the same function and you know that they are non null
No not here there
But new key A and B where also declared
Tho
O thing it checked the old ones I don't remember
When everything works we could try and remove the null ptrs checks
Well time to check this in code
so in the three functions that already worked I implemented it like this
if(!Authentication(PICC_CMD_MF_AUTH_KEY_A, *keyA)) { return false; }```
Now I will in master mode and then try it all
Uh, syntax note:
*, when used on a variable that's already been declared, is the dereference operator
But not in the signature of the function or also there?
It means 'the address of the variable'
Okay, so a variable declared <type> *my_var, is a pointer
Pointing to a value of <type> at some location in memory
To retrieve or set that value, you use the * operator
And if I use my var after declaring it without the *?
And to set that pointer to point at a certain value, you use &
If you declare it without the * it'll just be a normal variable of <type>
So we declare a pointer which is a variable that's a memory adress that points to a value of a certain type and having declare a pointer we read with & and write write *?
I said after declaring it
Ah, misread
with*
Then it'll literally just be a memory address
And I couldn't do anything because it would just be an hexa number?
However, if it's pointing to a struct or class, you can still call methods and access fields on it with the -> operator
I really don't feel secure with pointers yet and I want to badly to understand them
You can, but that's mostly used for arrays and other stuff and can be considered an advanced usage
Gimme a sec to open discord on my desktop; it's too hard to type out code examples on my phone
I copied the errors and it says
-2152
That's why I don't like using Arduino -
I can't even send it god damn it-
so, the stray '\???' in program seems to indicate you have some weird invisible characters after that closing brace—it should probably be possible to try to select them and delete them
But why would I if I didn't change almost anything
There's literally nothing there
I hate this errors messages so much -
i think just delete the line and retype it
Why is that a thing-?
I think you must've accidentally entered some weird characters ~somehow~
Prototipo_RFID_Escritura:45:61: error: 'MFRC522::MIFARE_KEY' has not been declared
bool Authentication(MFRC522::PICC_Command command, MFRC522::MIFARE_KEY *key){
^~~~~~~~~~
Prototipo_RFID_Escritura:45:61: error: 'MFRC522::MIFARE_KEY' has not been declared
bool Authentication(MFRC522::PICC_Command command, MFRC522::MIFARE_KEY *key){
^~~~~~~~~~
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino: In function 'bool Authentication(MFRC522::PICC_Command, int*)':
Prototipo_RFID_Escritura:46💯 error: no matching function for call to 'MFRC522::PCD_Authenticate(MFRC522::PICC_Command&, byte&, int*&, MFRC522::Uid*)'
MFRC522::StatusCode estado = mfrc522.PCD_Authenticate(command, bloqueTrailer, key, &(mfrc522.uid));
^
In file included from C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino:2:0:
C:\Users\fuchi\OneDrive\Documentos\Arduino\libraries\MFRC522\src/MFRC522.h:320:13: note: candidate: MFRC522::StatusCode MFRC522::PCD_Authenticate(byte, byte, MFRC522::MIFARE_Key*, MFRC522::Uid*)
StatusCode PCD_Authenticate(byte command, byte blockAddr, MIFARE_Key *key, Uid *uid);
^~~~~~~~~~~~~~~~
C:\Users\fuchi\OneDrive\Documentos\Arduino\libraries\MFRC522\src/MFRC522.h:320:13: note: no known conversion for argument 3 from 'int*' to 'MFRC522::MIFARE_Key*'
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino: In function 'bool cargarSaldo()':
Prototipo_RFID_Escritura:180:22: error: 'PICC_CMD_MF_AUTH_KEY_A' was not declared in this scope
if(!Authentication(PICC_CMD_MF_AUTH_KEY_A, &keyA)) { return false; }
^~~~~~~~~~~~~~~~~~~~~~
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino: In function 'bool comprar()':
Prototipo_RFID_Escritura:228:26: error: 'PICC_CMD_MF_AUTH_KEY_A' was not declared in this scope
if(!Authentication(PICC_CMD_MF_AUTH_KEY_A, &keyA)) { return false; }
^~~~~~~~~~~~~~~~~~~~~~
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino: In function 'bool leerSaldo()':
Prototipo_RFID_Escritura:259:22: error: 'PICC_CMD_MF_AUTH_KEY_A' was not declared in this scope
if(!Authentication(PICC_CMD_MF_AUTH_KEY_A, &keyA)) { return false; }
^~~~~~~~~~~~~~~~~~~~~~
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino: In function 'void modoMaestro()':
Prototipo_RFID_Escritura:316:24: error: 'PICC_CMD_MF_AUTH_KEY_A' was not declared in this scope
if(!Authentication(PICC_CMD_MF_AUTH_KEY_A, &antiguaKeyA)) { return false; }
^~~~~~~~~~~~~~~~~~~~~~
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino:316:72: warning: return-statement with a value, in function returning 'void' [-fpermissive]
if(!Authentication(PICC_CMD_MF_AUTH_KEY_A, &antiguaKeyA)) { return false; }
^~~~~
Prototipo_RFID_Escritura:317:24: error: 'PICC_CMD_MF_AUTH_KEY_B' was not declared in this scope
if(!Authentication(PICC_CMD_MF_AUTH_KEY_B, &antiguaKeyB)) { return false; }
^~~~~~~~~~~~~~~~~~~~~~
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino:317:72: warning: return-statement with a value, in function returning 'void' [-fpermissive]
if(!Authentication(PICC_CMD_MF_AUTH_KEY_B, &antiguaKeyB)) { return false; }
^~~~~
exit status 1
'MFRC522::MIFARE_KEY' has not been declared
Okay, so most of these errors aren't actually so bad
But Arduino makes it seem that way-
Looking at the first one, it's saying it can't find a type named 'MFRC522::MIFARE_KEY'
yep
What else?
Try a recompile now, and tell me if the next error goes away
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino: In function 'bool cargarSaldo()':
Prototipo_RFID_Escritura:180:22: error: 'PICC_CMD_MF_AUTH_KEY_A' was not declared in this scope
if(!Authentication(PICC_CMD_MF_AUTH_KEY_A, &keyA)) { return false; }
^~~~~~~~~~~~~~~~~~~~~~
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino: In function 'bool comprar()':
Prototipo_RFID_Escritura:228:26: error: 'PICC_CMD_MF_AUTH_KEY_A' was not declared in this scope
if(!Authentication(PICC_CMD_MF_AUTH_KEY_A, &keyA)) { return false; }
^~~~~~~~~~~~~~~~~~~~~~
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino: In function 'bool leerSaldo()':
Prototipo_RFID_Escritura:259:22: error: 'PICC_CMD_MF_AUTH_KEY_A' was not declared in this scope
if(!Authentication(PICC_CMD_MF_AUTH_KEY_A, &keyA)) { return false; }
^~~~~~~~~~~~~~~~~~~~~~
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino: In function 'void modoMaestro()':
Prototipo_RFID_Escritura:316:24: error: 'PICC_CMD_MF_AUTH_KEY_A' was not declared in this scope
if(!Authentication(PICC_CMD_MF_AUTH_KEY_A, &antiguaKeyA)) { return false; }
^~~~~~~~~~~~~~~~~~~~~~
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino:316:72: warning: return-statement with a value, in function returning 'void' [-fpermissive]
if(!Authentication(PICC_CMD_MF_AUTH_KEY_A, &antiguaKeyA)) { return false; }
^~~~~
Prototipo_RFID_Escritura:317:24: error: 'PICC_CMD_MF_AUTH_KEY_B' was not declared in this scope
if(!Authentication(PICC_CMD_MF_AUTH_KEY_B, &antiguaKeyB)) { return false; }
^~~~~~~~~~~~~~~~~~~~~~
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino:317:72: warning: return-statement with a value, in function returning 'void' [-fpermissive]
if(!Authentication(PICC_CMD_MF_AUTH_KEY_B, &antiguaKeyB)) { return false; }
^~~~~
exit status 1
'PICC_CMD_MF_AUTH_KEY_A' was not declared in this scope
Yep!
In case you didn't see, the error
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino: In function 'bool Authentication(MFRC522::PICC_Command, int*)':
Prototipo_RFID_Escritura:46💯 error: no matching function for call to 'MFRC522::PCD_Authenticate(MFRC522::PICC_Command&, byte&, int*&, MFRC522::Uid*)'
MFRC522::StatusCode estado = mfrc522.PCD_Authenticate(command, bloqueTrailer, key, &(mfrc522.uid));
^
In file included from C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino:2:0:
C:\Users\fuchi\OneDrive\Documentos\Arduino\libraries\MFRC522\src/MFRC522.h:320:13: note: candidate: MFRC522::StatusCode MFRC522::PCD_Authenticate(byte, byte, MFRC522::MIFARE_Key*, MFRC522::Uid*)
StatusCode PCD_Authenticate(byte command, byte blockAddr, MIFARE_Key *key, Uid *uid);
went away
this is actually caused by that MIFARE_Key misspelling
If you look at the first line, it says In function 'bool Authentication(MFRC522::PICC_Command, int*)
You declared it as bool Authentication(MFRC522::PICC_Command, MRFC522::MIFARE_KEY *)
But since it couldn't find MIFARE_KEY, it seems to have just assumed it was an int* instead, which led to it getting confused
But I already solved the typo
Oh ok
Now, look at the next message: error: 'PICC_CMD_MF_AUTH_KEY_A' was not declared in this scope
This time the name is highlighted not as before so I don't think it's wrong
I'll give you a hint: in C++, :: is called the scope resolution operator
Why I need it here and not when I used it in the other function
Just like in rust I assume
OH!
I see
What did you see?
That it did have the :: to bring it into scope
Precisely speaking, you need to add MFRC522:: at the beginning
If you just say PICC_CMD_MF_AUTH_KEY_A, it will try to find that name in the global scope
but it only actually exists within the scope of MFRC522
Also, there's still that last warning, that you're doing a return false in a function that returns void
Also, I've got to leave for a bit to cook; be back later
Sure gl
It compiled but I have a warning maybe is that one you talked about
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino: In function 'void modoMaestro()':
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino:316:81: warning: return-statement with a value, in function returning 'void' [-fpermissive]
if(!Authentication(MFRC522::PICC_CMD_MF_AUTH_KEY_A, &antiguaKeyA)) { return false; }
^~~~~
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino:317:81: warning: return-statement with a value, in function returning 'void' [-fpermissive]
if(!Authentication(MFRC522::PICC_CMD_MF_AUTH_KEY_B, &antiguaKeyB)) { return false; }
^~~~~
Yeah it is
Maybe a normal return will do then
Done no more warnings time to test
Well it doesn't work
It doesn't advance with any of the keys
Isn't that just fascinating-
Oh it was just another inconsistency
I tried it again re opening the serial monitor starting the program again
And it passed the same test as the other
Not working with the card without changed password and working with the other
Now, the moment of truth see if it pass the other two test
Yeah it passed all the tests
Problem solved we can move on to the next thing now
When you come back ofc
Unless..
@oblique bridge think you could give a hand?
Hey whats up?
yep good good i havent really being following this thread where we up to?
Well for starters you know nothing about what are we working on?
nah not really sorry ahahahah
Np
Because
Like some days ago someone new said it wanted to help so
I could look to when I give them all the context
And I won't have to do it again (?
Tho I would need to update it a bit but it's fine
yeah algs you can just fill in whenever hahaha im happy to help out where i can if need be, still need to learn so much embedded rust as well
just for now we switched back to normal arduino tho, cpp, so maybe you can help, but do not worry soon enough the rust re writting will continue
that will come in handy
I am looking for the context
Well idk if it's too much to read but.. I think here I were I started explaining them the project and what we were doing, literally all context I could provide, after that not much else happened so I won't have to say much else
oh yep sure ill take a look
Thanks
Español Rioplatense
Shamefully not I recently learned about git and installed it
So neither this nor the rust one have it, which is a huge shame for me it would help so much
wait thats so cool, im learning spanish for school its so difficult ahahaha
yep i think github (or gitlab or whatever) would be a good place to start - once you have version control it makes silly mistakes or errors less impactful, and allows you to easily revert changes or seeks suggestions
From now onwards I'm using git in any new project because my school mail is myself sending the same code to me like "code that does this but with this error" "This code again but it know works" "Ok now fr it works "
I heard so, that it's easier to learn English than Spanish , tho for me it's a shame you learn the Spain version but ig it makes sense (?
I learned the UK version but since all content I watch is likely from the US my English is more American leaning it's inevitable
Or maybe a weird mixture which would also be inevitable
ye, im from new zealand so again different english slang; we tend to learn words for things in any version of spanish but means we end up having some really whack writing that sorta mashes stuff together ahahah
but you'll wana start here; create a github account https://github.com/
then you can push your local repository to github which means your code will be stored online as well as on your computer, so you dont have to worry about loosing it!
I have a github account
oh awesome
With the silliest name I could think of
I really need to think a user name for those places
Tho I get I could upload my rust code but idk my arduino one
In any case I wasn't thinking in making repositories for this
Since they have already started there are a lot of things lost
And using version control on a close to last version
Or maybe it's also because of how much I like pure perfect things
Like I would love this to have been done like this from the beginning and having all the versions
Doing it know would be like doing it halfway through
And I really hate that
all your versions will be uploaded to github when you push, because its stored in your local git history :D
but yep ic what u mean das algs
But the thing is there aren't versions if I keep re writting above only one version
As I said I just recently installed git
Because of the course I'm in I learned it and may use it soon for the first time
yep yep
i digress, i do think venturing into git will def help you in your journey moving forward tho
its a really powerful tool
Ofc that's why I said every project from now own will be in git but this came too late for that
I'm any case, I want to check a thing from another code tho from the same project but I will be alert when you finish reading and so, to add the rest of context
alright i've had a look through, although i havent actually seen the code i think i have a good idea what's going on now :D
Ok now that was from that day
What changed is
The base functionality in rust it's finished
The merging of lcd and keyboard, and the relay logic
That's also that changed from the rust project
But now we are working on the original version
To finish the rfid prototype
Tho there is not well in what stage it was and what were the issues
But if you know the whole project maybe it's enough with saying this
What's next now
Is the error handling for the scenario where you try to change the password with a card that's already fine and then finally the whole EEPROM deal
With that we would finish the rfid prototype and could pass all of that, that worked on it's own to the rest of the project
And finally after that I would have to work with the sensors but that should be the easy part so
Now I passed all the code earlier but ofc it has changed now
@old mango when you come back I have a suggestion for the error handling
Remember how what I wanted to do now
Aight what is it
Is that when you enter master mode with a card that doesn't need to change it's password anymore it returned you to the beginning with the message like "this card it's already fine"?
Well I thought
Yeah, that sounds like it fits your requirements
The card is already rejected and with an error message, if only we could personalize the message for master mode
But the message it's inside the function
It's there a way to do that? Because something as simple as that I think would do
Well, you can add a parameter to the Authenticate function that suppresses printing a message
Suppresses?
In the way i used it: prevent, stop from happening
Like reprimir, i think, if you were adking for the meaning
I know what you mean but not why
Because I want to print a different message just for that scenario, not printing nothing
We could theoretically
And then if Authenticate fails in modoMaestro, you stop it from erroring, check against the new password, and if that works, you can print the custom message
You lost me a little bit there
So, your goal is to print a custom message in modoMaestro if the password is currently set to the new one, yes?
Yes
And the error message is coming from Authenticate
Indeed so it's the default error message
Yeah, so first, you suppress that error message from checking against the default keys
And if it matches the factory defaults, great, continue as normal, but if it doesn't, you detect that, and go into an if, like you already do
Except now, instead of just returning, you need to check whether it failed because the password is the correct one, or if it's some other, unrelated, password
So you do a second Authentication, using the new password; if this works, then you call HaltA and StopCrypto or whatever to un-authenticate, and then print out the custom message before returning to the main menu
If the second check fails, it's an unrelated password altogether, so you just need to not suppress the error (so it gives a correct message), and return back to the main menu
It's certainly hard to explain in the air
There's three behaviours you want to see:
- Card password is factory default -> continue
- Card password is correct current one -> custom message
- Card password is anything else -> normal message
Ok I get that
Ok I think I get it more now
So let's see..
I call authentication in master mode
With the factory keys
If it doesn't fail
Okay nothing needs to be changed it's okay
But if it fails
It won't print the default error message
It would enter in another if
To authenticate to the new password
If it authenticates it prints the custom error messages and if it doesn't the generic one
Did I get it?
Yep!
Ok let's see if I implement it correctly
I don't I do it really long but I will finish it and show you for the feedback-
bool Authentication(MFRC522::PICC_Command command, MFRC522::MIFARE_Key *key){
estado = mfrc522.PCD_Authenticate(command, bloqueTrailer, key, &(mfrc522.uid));
if (estado != MFRC522::STATUS_OK) {
MFRC522::StatusCode estado_A = mfrc522.PCD_Authenticate(command, bloqueTrailer, &nuevaKeyA, &(mfrc522.uid))
MFRC522::StatusCode estado_B = mfrc522.PCD_Authenticate(command, bloqueTrailer, &nuevaKeyB, &(mfrc522.uid))
if ((estado_A && estado_B) != MFRC522::STATUS_OK){
Serial.print("La tarjeta ya forma parte del sistema");
return false;
} else {
Serial.print("Autenticacion fallida, tarjeta rechazada");
return false;
}
} else {
return true;
}
}
Like that?
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino: In function 'bool Authentication(MFRC522::PICC_Command, MFRC522::MIFARE_Key*)':
Prototipo_RFID_Escritura:21:86: error: 'nuevaKeyA' was not declared in this scope
MFRC522::StatusCode estado_A = mfrc522.PCD_Authenticate(command, bloqueTrailer, &nuevaKeyA, &(mfrc522.uid))
^~~~~~~~~
exit status 1
'nuevaKeyA' was not declared in this scope
Though I would have this problem
I will try with key A and B which are global and if I remember correctly are the same
Forgot semi colons
It compiled let's try it
it works wrong-
Well, let me ask quickly: do you want it to do the double authentication every time you call Authenticate?
Or just in modoMaestro?
Just in master mode in any other case I want the behavior it had before
And it's working bad
Even though my card has the wrong password when it fails for example trying to charge money the error message is the one that should show in Modo maestro for the specific scenario
¿Quiere acceder al modo maestro u operar normal?
1-Modo Maestro
2-Modo Normal
¿Quiere cargar plata, comprar o verificar su saldo?
1-Cargar Plata
2-Comprar
3-Ver estado de saldo
Apoye su tarjeta para ver su saldo
La tarjeta ya forma parte del sistema
¿Quiere acceder al modo maestro u operar normal?
1-Modo Maestro
2-Modo Normal
It should say the other error message
Then do you need to have that code inside of Authentication()?
Or is there a way that you can move it out to modoMaestro()?
What I was telling you from the beginning is that if maybe there was a way to change the message only for master mode without bothering the rest of the program
But this solution didn't seem bad I don't know why it isn't working
bool Authentication(MFRC522::PICC_Command command, MFRC522::MIFARE_Key *key){
estado = mfrc522.PCD_Authenticate(command, bloqueTrailer, key, &(mfrc522.uid));
if (estado != MFRC522::STATUS_OK) {
MFRC522::StatusCode estado_A = mfrc522.PCD_Authenticate(command, bloqueTrailer, &keyA, &(mfrc522.uid));
MFRC522::StatusCode estado_B = mfrc522.PCD_Authenticate(command, bloqueTrailer, &keyB, &(mfrc522.uid));
if ((estado_A && estado_B) != MFRC522::STATUS_OK){
Serial.print("La tarjeta ya forma parte del sistema");
return false;
} else {
Serial.print("Autenticacion fallida, tarjeta rechazada");
return false;
}
} else {
return true;
}
}
I don't see the issue
If the first authentication failed why did the second succeed when I'm comparing it to the same key
The only difference
Look at the second if
Is that here I'm checking also key B because master mode does but no other do but it shouldn't check anyways-
What does (a && b) actually do?
I'm saying that both key A and B should be different from status ok
Well, what (a && b) actually does is 'convert a and b to boolean values, and if they're both true, evaluate to true, otherwise evaluate to false
Tho that's a bit uncomfortable it also is the fact that in all case except for that one I'm checking the same keys two times, god damn it master mode being so special-
So I will have to evaluate it separately?
If you're using that approach, yes, but
this is why i suggested adding a parameter to Authentication() to suppress the error message
That way, instead of calling PCD_Authenticate twice inside Authentication(), you can just call Authentication multiple times inside modoMaestro()
Yeah I don't understand that I understanded your other explanation (?
I don't see how not printing the original error messages changes the thing
Because still I need to print a error message and it has to be inside authentication
Because if it fails it returns and it wouldn't achieve the print
Ah! It does not have to be inside Authentication
Because you can check if Authentication returns true or false, and print based on that
Ok but how do we do the message suppression?
Well, normally, what do you do if you only want a piece of code to run under certain conditions?
An if statement
Yup!
But what do we check, that we are in master mode?
That would work; if you want to check that, how would you pass that information into Authentication()?
No clue I don't know how to check if I'm inside an specific function I mean I have an idea but it's horrible
Well, what's that idea
Like having a global boolean variable for if we are or not in master mode, and it will be always false and we set it to true when in the function so the if would ask for that boolean but it seems idk, horrible or "desprolijo" To me
Like not elegant(?
Well, that is very inelegant
See
But i think there's a much simpler way; what's the normal way to pass information to a function?
Well parameters? There's no other way
Why not create a parameter that specifies whether Authentication should print the error or not?
Instead of using a global variable
Yeah like ok we pass that we want or not the message to be printed, then?
Yes
Okay, so looking at how you originally did it inside Authentication, how would you do that in modoMaestro(), using the return value of Authentication() instead of the return value of PCD_Authenticate()?
I didn't get the question
I mean I didn't get it but maybe the answer is
Oh
I see it know.
So
When I do authentication I do an if with the two key as I do now if I get true in both I continue, if I get false from any of the two then check with the other passwords and if I get true from both print the custom error message if not then print the normal one
More or less
Yeah, that sounds about right
Ok I will try it
bool Authentication(MFRC522::PICC_Command command, MFRC522::MIFARE_Key *key, bool print_error_message){
estado = mfrc522.PCD_Authenticate(command, bloqueTrailer, key, &(mfrc522.uid));
if (estado != MFRC522::STATUS_OK) && (print_error_message == true) {
Serial.print("Autenticacion fallida, tarjeta rechazada");
return false;
} else {
return true;
}
}
Oh wait
Forget it
Don't see that
bool Authentication(MFRC522::PICC_Command command, MFRC522::MIFARE_Key *key, bool print_error_message){
estado = mfrc522.PCD_Authenticate(command, bloqueTrailer, key, &(mfrc522.uid));
if (estado != MFRC522::STATUS_OK {
if(print_error_message == true){Serial.print("Autenticacion fallida, tarjeta rechazada")}
return false;
} else {
return true;
}
}
Like this?
and about master mode..
if (Authentication(MFRC522::PICC_CMD_MF_AUTH_KEY_A, &antiguaKeyA, false)) && (Authentication(MFRC522::PICC_CMD_MF_AUTH_KEY_B, &antiguaKeyB, false)) == false {
if (Authentication(MFRC522::PICC_CMD_MF_AUTH_KEY_A, &keyA, false)) && (Authentication(MFRC522::PICC_CMD_MF_AUTH_KEY_B, &keyB, false)) == true {
Serial.print("La tarjeta ya forma parte del sistema");
} else {
Serial.print("Autenticacion fallida, tarjeta rechazada");
}
}
like this?
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino: In function 'void modoMaestro()':
Prototipo_RFID_Escritura:283:82: error: expected identifier before '(' token
if (Authentication(MFRC522::PICC_CMD_MF_AUTH_KEY_A, &antiguaKeyA, false)) && (Authentication(MFRC522::PICC_CMD_MF_AUTH_KEY_B, &antiguaKeyB, false)) == false {
^
exit status 1
expected identifier before '(' token
What's an identifier-
A name of a variable, a type, whatever
Btw I obviously changed every other call to authentication to include a true to print the normal error message
Check your parentheses first
Then why does it expect that it doesn't make sense -
Ok
In the meantime tell me if the change to the function I did and the implementation in master mode are ok
When it says "expected XX", that usually just means there's a syntax error somewhere
Also remember that unlike rust, C++ requires you to have parentheses around the entire condition in the if statement
If I do that it says it expects a primary expression before ==
Idk what the hell it wants know-
In master mode, do you want it fail of BOTH of the keys are not their factory defaults, or if EITHER of the keys are not the factory defaults?
Either ofc that's why I do an and if one of the two passwords isn't correct it should fail I guess
C:\Users\fuchi\OneDrive\Documentos\Arduino\Prototipo_RFID_Escritura\Prototipo_RFID_Escritura.ino: In function 'void modoMaestro()':
Prototipo_RFID_Escritura:283:155: error: expected primary-expression before '==' token
if ((Authentication(MFRC522::PICC_CMD_MF_AUTH_KEY_A, &antiguaKeyA, false)) && (Authentication(MFRC522::PICC_CMD_MF_AUTH_KEY_B, &antiguaKeyB, false))) == false {
^~
exit status 1
expected primary-expression before '==' token
It's like a baby or a dog I don't know what the hell it wants from me-
Like i said before, it wants a parentheses around the entire condition
Before it was this
No, you have parentheses around the Authentication() calls
And a single ) at the end
But there's still the false that needs a parentheses around it too
The false after the == ?
if ((Authentication(MFRC522::PICC_CMD_MF_AUTH_KEY_A, &antiguaKeyA, false)) && (Authentication(MFRC522::PICC_CMD_MF_AUTH_KEY_B, &antiguaKeyB, false))) == (false)
Please god it literally has all the parenthesis I saw them with the highlighting-
When you click a parenthesis it shows you the one that closes it
And it's all closed all good -
What the hell wants from me-
when i say parentheses around the whole condition that means everything between the if and the { is enclosed by a single set of parentheses, like so:
if(
(a && b) == false
)
(note: separated on different lines for emphasis)
.
When I did it started showing this -
.
It has parenthesis for calling the function, for the expression of calling the function
you're missing a ( in that second one
And for the comparison between the two
and the false was still outside
Finally..
I hate you cpp..
So
Are the way I implemented the authentication function in master mode and the new Authentication function good?
i think?
Ok let's try it then..
lemme see the current version rl quick
.
And
if (((Authentication(MFRC522::PICC_CMD_MF_AUTH_KEY_A, &antiguaKeyA, false)) && (Authentication(MFRC522::PICC_CMD_MF_AUTH_KEY_B, &antiguaKeyB, false))) == false) {
if (((Authentication(MFRC522::PICC_CMD_MF_AUTH_KEY_A, &keyA, false)) && (Authentication(MFRC522::PICC_CMD_MF_AUTH_KEY_B, &keyB, false))) == true) {
Serial.print("La tarjeta ya forma parte del sistema");
} else {
Serial.print("Autenticacion fallida, tarjeta rechazada");
}
}
add one more left parentheses at the beginnings
But it compiles already
But it doesn't work correctly