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!
timeClientis 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.