2

This is the code I upload to the ESP8266 to connect to firebase.

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

 #define FIREBASE_HOST "*******.firebaseio.com"
 #define FIREBASE_AUTH "68GM**************m4k0IPLXF4G1"
 #define WIFI_SSID "IDR"
 #define WIFI_PASSWORD "****"

 #define LED 2

 void setup() {
    pinMode(LED,OUTPUT);
    digitalWrite(LED,0);
    digitalWrite(LED,0);
    Serial.begin(9600);
    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);
    Firebase.setInt("LEDStatus",0);
 }   

 void loop() {
    if(Firebase.getInt("LEDStatus"))
    {                            
       digitalWrite(LED,HIGH);
    }
    else
    {
       digitalWrite(LED,LOW);
    }
    delay(1000);
 }

With this code, my NodeMCU can connect to the internet without any issue.
The problem is that the LEDStatus does not update in the firebase database.

Is there something wrong with my FirebaseArduino.h reference library?

Any help would be appreciated.

littletof
  • 30
  • 6

5 Answers5

1

Google Firebase Database Secrets are deprecated right now. So you need to continue with Firebase Admin SDK.enter image description here see this.

1

Try doing this

  Firebase.setInt("LEDStatus",0); 
     if (Firebase.failed()) {
     Serial.print("failed:");
     Serial.println(Firebase.error());  
     return;
  }

If it prints 'failed' on the serial monitor, double check the 'FIREBASE_HOST' and 'FIREBASE_AUTH'

For me, doing these didn't help. What helped was changing the fingerprint in "static const char kFirebaseFingerprint[]" inside "FirebaseHttpClient.h" file from "C:\Users\xxxxxxxx\Documents\Arduino\libraries\firebase-arduino-master\src"

You can find fingerprint for yours one form "https://www.grc.com/fingerprints.htm" by putting your FIREBASE_HOST ( ie https://xxxxxxx.firebaseio.com/)

PS. Don't put ( : ) in the fingerprint

Arsam
  • 368
  • 4
  • 4
1
  1. First check whether you have given the access to write in database rules.
  2. Or change FirebaseFingerPrint according to https://github.com/FirebaseExtended/firebase-arduino/issues/236 this fixed my issues.
  3. (optinal) Use 6 digit SSID,PASSWORD but not too long strings. Sometimes I had issues making softAp due to improper naming conventions.

IN.

1

I answered a similar question here.

Basically, as the database secrets are depracated (as it was pointed out in a previus answer), and I couldn't find an Arduino library, that supports the new Firebase Admin SDK, I used Firebase Cloud Functions, with http triggers to store and retrive data from the realtime database.

You can see an example for the Arduino sketch and the cloud function in the linked answer.

littletof
  • 30
  • 6
0

thanks to @Isuru Nuwanthilaka i get the job done and my nodeMcu is successfully sending data to firebase although database secrets are deprecated. so i searched for an alternative way to send data to firebase and i came across REST witch is easier and available for any device support https request.

with REST (witch is just an https requests) you can use your firebase by just sending https request. no SDK required and no cloud functions. in your case you will just #include <ESP8266WiFi.h> and other library that support HTTPS client. no need for firebaseSDK on node:cu