我正在将rfid卡读入content.substring(1)。并且我已经将其设置为变量uidrf,但是我不能在我的firebase.set函数中将该变量用作值
当前我已经尝试了以下代码,但无法使其正常工作
//Show UID on serial monitor
Serial.print("UID tag :");
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++) // this reads the id of the card
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], DEC);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], DEC));
}
String uidrf = content.substring(1); //this sets the card id to a variable
Serial.println();
Serial.print("! Signing into space - Timer Started !");
content.toUpperCase();
if (content.substring(1) == (Firebase.getString("Users/UID1")) || // this checks if the userid matches the database and the card.
content.substring(1) == (Firebase.getString("Users/UID2")) ||
content.substring(1) == (Firebase.getString("Users/UID3")) ||
content.substring(1) == (Firebase.getString("Users/UID4"))||
content.substring(1) == (Firebase.getString("Users/UID5"))) //change
here the UID of the card/cards that you want to give access
{
if (Firebase.getString("SpaceState/Space1") == "0"){
Serial.println(" Parked sp1 ");
Firebase.set("UsersInSpace/Space1" , uidrf); // here is where i want to set the value to the variable so in the database it can show what uid is in the space.
Firebase.set("SpaceState/Space1" , "1");
digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(4 , LOW); // turn the LED off by making the voltage LOW
delay(1000);
}
答案 0 :(得分:1)
您在3个不同的位置使用uidrf
。
String uidrf;
content.substring(1) = uidrf;
Firebase.set("UsersInSpace/Space1" , uidrf);
首先,您声明变量,但未为其分配值(默认初始化)。
将content.substring(1)
的值更改为uidrf将导致不确定的行为。我假设调用Firebase.set("UsersInSpace/Space1" , uidrf)
时也会发生同样的情况。
您可能想做:
uidrf = content.substring(1);
但是您的问题目前尚不清楚。