Reputation: 21
I was coding a while when I noticed that arduino when it print data to "console", it print it perfectly, but, when I try to copy it, only copyes part of string. Is like there are invisible characters.
I can't paste the output because when I try to copy it, it don't copy full.
What I was trying to do is to get data from a Mifare card and make an json format to print it to console to comunicate with other program. All go well, until it print data.
Arduino code
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_B, block, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
return false;
}
status = mfrc522.MIFARE_Read(block, buffer1, &len);
if (status != MFRC522::STATUS_OK) {
return false;
}
String user;
for (char c : buffer1) {
if (c != '^') {
user += c;
} else break;
}
block = 2;
len = 18;
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_B, block, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
return false;
}
status = mfrc522.MIFARE_Read(block, buffer1, &len);
if (status != MFRC522::STATUS_OK) {
return false;
}
String unicID;
for (char c : buffer1) {
if (c != '^') {
unicID += c;
} else break;
}
String dataSend = "{\"u\":\"" + String(user) + "\",\"i\":\"" + String(unicID) + "\"}º";
Serial.println (dataSend);
dataSend.replace("\n","");dataSend.replace("\t","");dataSend.replace("\r","");dataSend.replace(" ","");
Serial.println (dataSend);
if (dataSend.length() > 20) {
for (int x = 0; x < ((dataSend.length() / 20) +3); x++) {
Serial.println(String(x*20) + " ---- "+ String((x+1)*20));
Serial.println(String(dataSend.substring(x*20,(x+1)*20)));
delay(100);
}
} else {
Serial.println( dataSend);
}
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
The output should be this splited every 20 characters:
{"u":"teoDinqtepfhtpefhtpe4b","i":"qwertyuiopasdfgBp"}º
But I get:
0 ---- 20
{"u":"teoDinqtepfhtp
20 ---- 40
e
40 ---- 60
pasdfg
60 ---- 80
80 ---- 100
Is like there are magical characters or something similar. Here is an image because I can't copy the first full output after or before trying to format it to solve problem.
Upvotes: 0
Views: 232
Reputation: 21
Mifare cards have a limitation of 16 bytes x block and you can't write on protected blocks like 0, 3, 6 etc.. The error was that I was writing 17 bytes instead of 16 bytes and that returns invisible / error charaters that can't be displayed
Upvotes: 1