0

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!

dykuman
  • 11
  • 3
  • You didn't include enough code to be sure but if `timeClient` is an NTP client, please do not call it during every loop iteration. That's an extremely hostile way to use NTP. The ESP32 has a built in real time clock which doesn't need to be synced constantly with NTP. – romkey Feb 03 '22 at 21:51

1 Answers1

0

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?

romkey
  • 6,218
  • 3
  • 16
  • 12
  • OK I understand. This is problem because when I export a database to process it, the prefix causes extra work. – dykuman Feb 04 '22 at 11:41
  • It should be trivial to write a script to strip the field from the export. Or just import the key into the new database. Either way, it’s not optional in Firebase. – romkey Feb 04 '22 at 18:40