简体   繁体   中英

ESP8266 with Firebase (firebase-arduino-master) adds unique key

I have a problem with saving data in Firebase realtime and sending from ESP8266. I use firebase-arduino-master library. I want to send the soil moisture information from ESP8266 to Firebase periodically. Connecting works, data is being transferred, but in the database I can see an automatically added prefix - a unique key. enter image description here

My code:

    void setup() 
{
  Serial.begin(9600);
  delay(1000);                    
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);                               
  Serial.print("Connecting to ");
  Serial.print(WIFI_SSID);
  while (WiFi.status() != WL_CONNECTED) 
  {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.print("Connected to ");
  Serial.println(WIFI_SSID);
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());                               //prints local IP address
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);                 // connect to firebase
  Serial.println(Firebase.success());
  Serial.println("OK");
  timeClient.begin();
  delay(2000);
}

void loop() {
  timeClient.update();
  float moisture_percentage;

  moisture_percentage = map(analogRead(sensor_pin), 696, 328, 0, 100);

  unsigned long epochTime = timeClient.getEpochTime();

//Get a time structure
  struct tm *ptm = gmtime ((time_t *)&epochTime); 
  int monthDay = ptm->tm_mday;
  int currentMonth = ptm->tm_mon+1;
  int currentYear = ptm->tm_year+1900;
  //Print complete date:
  String currentDate = String(currentYear) + "-" + String(currentMonth) + "-" + String(monthDay);
  Serial.print(currentDate);
  Serial.print(" ");
  Serial.print(timeClient.getFormattedTime());
  Serial.print(" - ");
  Serial.print(moisture_percentage);
  Serial.println("%");
  float m = moisture_percentage;
  String fireMoist = String(currentDate) + String(" ") + String(timeClient.getFormattedTime()) + String(" ") + String(moisture_percentage) + String("%");                  //Moisture integer to string conversion
  Firebase.pushString("MOIST", fireMoist);                                   //setup path to send Moisture readings
 
  delay(2000);
}

I want to know how remove the prefix, unique key. Thanks for helping!

This "prefix" is the document's ID, automatically generated by Firebase. You don't get rid of it. It's integral to how the database works - every document has a unique identifier. Why do you think it's a problem?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM