1

I would like to connect via the esp8266 card to my firebase database. I tried to use the demo code that provides the firebase library for Arduino, but it does not work. I correctly enter my wi-fi data and I can establish a connection, but when I try to connect to the database the Arduino console I get the following error: setting/number failed:

enter image description here Code:

#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>

// Set these to run example.
#define FIREBASE_HOST "-.firebaseio.com"
#define FIREBASE_AUTH "----"
#define WIFI_SSID "----"
#define WIFI_PASSWORD "----"

void setup() {
  Serial.begin(9600);

  // connect to wifi.
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("connecting");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.print("connected: ");
  Serial.println(WiFi.localIP());

  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}

int n = 0;

void loop() {
  // set value
  Firebase.setFloat("number", 42.0);
  // handle error
  if (Firebase.failed()) {
      Serial.print("setting /number failed:");
      Serial.println(Firebase.error());  
      return;
  }
  delay(1000);

  // update value
  Firebase.setFloat("number", 43.0);
  // handle error
  if (Firebase.failed()) {
      Serial.print("setting /number failed:");
      Serial.println(Firebase.error());  
      return;
  }
  delay(1000);

  // get value 
  Serial.print("number: ");
  Serial.println(Firebase.getFloat("number"));
  delay(1000);

  // remove value
  Firebase.remove("number");
  delay(1000);

  // set string value
  Firebase.setString("message", "hello world");
  // handle error
  if (Firebase.failed()) {
      Serial.print("setting /message failed:");
      Serial.println(Firebase.error());  
      return;
  }
  delay(1000);

  // set bool value
  Firebase.setBool("truth", false);
  // handle error
  if (Firebase.failed()) {
      Serial.print("setting /truth failed:");
      Serial.println(Firebase.error());  
      return;
  }
  delay(1000);

  // append a new value to /logs
  String name = Firebase.pushInt("logs", n++);
  // handle error
  if (Firebase.failed()) {
      Serial.print("pushing /logs failed:");
      Serial.println(Firebase.error());  
      return;
  }
  Serial.print("pushed: /logs/");
  Serial.println(name);
  delay(1000);
}

I would like to establish a connection with my firebase database.

  • Most likely you don't have permission to write to the database. By default on new databases only administrators can write. To change this, see https://stackoverflow.com/questions/37403747/firebase-permission-denied – Frank van Puffelen Dec 28 '18 at 15:41
  • @FrankvanPuffelen I've enabled both writing and reading the database: { "rules": { ".read": true, ".write": true } } – Salvatore Raccardi Dec 28 '18 at 15:47
  • @FrankvanPuffelen the error persists the same, it is as if esp8266 can not connect to the db, but I have entered the data correctly several times even by modifying the database. I can not understand what the problem is. – Salvatore Raccardi Dec 28 '18 at 15:49
  • Surely there's some way to check the connection status, maybe a return value for the connect method? Trying to write with no other checks means you'll have no idea what specifically is wrong if it doesn't work. **The fact that your code is a sample shipped with the library doesn't change the fact that it's poorly thought through** – Chris Stratton Dec 29 '18 at 18:26
  • ou could see if the `const String &error()const` method gives you anything interesting, allegedly it will give you an error message. But it's also possible that it does not, in which case the library is as bad as its example. – Chris Stratton Dec 29 '18 at 18:30
  • Thanks for your comment, but I solved the problem. I had badly configured the database. – Salvatore Raccardi Dec 30 '18 at 15:46

1 Answers1

1

This can occur if the version of FirebaseArduino has an outdated fingerprint.

Check that the fingerprint in your installed FirebaseHttpClient.h corresponds to the current fingerprint.

See https://stackoverflow.com/a/54552554/1373856

Ben T
  • 4,656
  • 3
  • 22
  • 22