I have a function that reads an RFID card and returns the RFID string. The function reads the string well but I am using the ArduinoJson library to generate JSON.
This is the function that I am using to read RFID cards:
String rfidOku() {
String kartid= "";
if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
for (byte i = 0; i < mfrc522.uid.size; i++) {
kartid.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
kartid.concat(String(mfrc522.uid.uidByte[i], HEX));
}
kartid.toUpperCase();
//Serial.println(kartid);
}
kartid.trim();
return kartid;
}
And in the loop function, if a button is pressed I am getting an RFID and I am creating json using it.
const size_t capacity = JSON_OBJECT_SIZE(4);
DynamicJsonDocument doc(capacity);
const String str_rfid = rfidOku();
doc["id"] = odeme.id;
doc["fiyat"] = odeme.fiyat;
doc["rfid"] = str_rfid;
serializeJson(doc, Serial);
When I look at serial monitor the RFID field is null. Why does this happen? I tried to write another string there, and it works well with the other string. Why doesn't it work with str_rfid?
I also printed the value of str_rfid using Serial.print, str_rfid is getting the RFID card id from the function well.