I'm reading a RFID Card from RC522 and send the data to my computer. My problem is the conversion of byte[] to String or std::string.
#define SIZE_BUFFER 18
#define MAX_SIZE_BLOCK 16
byte buffer[SIZE_BUFFER] = {0};
byte tam = SIZE_BUFFER;
// get data
status = mfrc522.MIFARE_Read(bloco, buffer, &tam);
Serial.print(F("\nDados bloco ["));
Serial.print(F("]: "));
// printing...
for (uint8_t i = 0; i < MAX_SIZE_BLOCK; i++)
{
Serial.write(buffer[i]);
str += String(buffer[i]);
}
OUTPUT:
Dados bloco []: asdas
So, It's ok! But if I try make a string:
String str = "";
for (uint8_t i = 0; i < MAX_SIZE_BLOCK; i++)
{
str += String(buffer[i]);
}
Serial.println(" ");
Serial.println(str);
The output is:
97115100971153232323232323232323232
How is the correctely way to create a string from byte[] ?