Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

FirebaseStream could not detect changes from cloud and Firebase set() and get() got fail result. #167

Closed
loka17 opened this issue May 26, 2016 · 5 comments

Comments

@loka17
Copy link

loka17 commented May 26, 2016

I tried the following sketch, it worked fine at the beginning.

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

#define FIREBASE_HOST ""
#define NODE_LINK ""
#define FIREBASE_AUTH ""
#define WIFI_SSID ""
#define WIFI_PASSWORD ""

FirebaseArduino FirebaseStream;

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);
  FirebaseStream.begin(FIREBASE_HOST, FIREBASE_AUTH);
  FirebaseStream.stream(NODE_LINK);
}

int n = 0;
int m = 0;
void loop() {
  Serial.println("loop");
  Firebase.setInt("/testing/testing2/loopTimes", n++);
  if (Firebase.failed()) {
    Serial.println(Firebase.error());
  }
  int data = Firebase.getInt("/testing/testing2/loopTimes");
  if (Firebase.failed()) {
    Serial.println(Firebase.error());
  }
  Serial.print("data: ");
  Serial.println(data);
  Serial.print("heap: ");
  if (FirebaseStream.failed()) {
    Serial.println("ERROR: streaming error");
    Serial.println(FirebaseStream.error());
  }
  if (FirebaseStream.available()) {
    FirebaseObject event = FirebaseStream.readEvent();
    Serial.print("event: ");
    Serial.println(event.getString("event"));
    Serial.print("path: ");
    Serial.println(event.getString("path"));
    Serial.print("data: ");
    Serial.println(event.getString("data"));

    Firebase.setInt("/testing/testing1/pushTimes", m++);
    if (Firebase.failed()) {
      Serial.println(Firebase.error());
    }
  } else {
    Serial.println("stream is not available");
  }
  Serial.println(ESP.getFreeHeap());
  delay(4000);
}

However after a period of time (in my case, after a night) it did not work as expected. I listed two points that I thinks the issues.

  1. I changed data on cloud, but the code did not pass FirebaseStream.available() check.
  2. Firebase get and set have always received unsuccessful results due to "connection refused" error. Though I could access to cloud using PC.
    The output in Debug level "HTTP Client + SSL" is as below.

[HTTP-Client][begin] host: < FIREBASE_HOST > port: 443 url: /testing/testing1/loopTimes.json httpsFingerprint: 7A 54 06 9B DC 7A 25 B3 86 8D 66 53 48 2C 0B 96 42 C7 B3 0A
[HTTP-Client] failed connect to < FIREBASE_HOST >:443
[HTTP-Client][returnError] error(-1): connection refused
[HTTP-Client][returnError] error(-4): not connected
PUT /testing/testing1/loopTimes.json: -1
[HTTP-Client][begin] host: < FIREBASE_HOST > port: 443 url: /testing/testing1/loopTimes.json httpsFingerprint: 7A 54 06 9B DC 7A 25 B3 86 8D 66 53 48 2C 0B 96 42 C7 B3 0A
[HTTP-Client] failed connect to < FIREBASE_HOST >:443
[HTTP-Client][returnError] error(-1): connection refused
[HTTP-Client][returnError] error(-4): not connected
GET /testing/testing1/loopTimes.json: -1

I am using

Does anyone experience the same issues.
Any help would be appreciated.

@loka17 loka17 changed the title FirebaseStream could not detect changes from cloud and Firebase set and get always got fail result. FirebaseStream could not detect changes from cloud and Firebase set and get got fail result. May 26, 2016
@ed7coyne
Copy link
Collaborator

Did you try checking the WiFi.status() when you are getting failures? (Similar to what you do in setup())

Maybe you re losing wifi for some reason.

@loka17
Copy link
Author

loka17 commented May 28, 2016

@ed7coyne : thanks for your reply.
After adding wifi checking into loop() (I added checking statement Wifi.status(), in false branch reset the device); Firebase's get and set work correctly now, but FirebaseStream does not.
After a long time of running, FirebaseStream.available() always returns false even after the database was changed. I think if this is a network connection problem then the statement FirebaseStream.failed() should return true, but in my case it returns false.

@loka17 loka17 changed the title FirebaseStream could not detect changes from cloud and Firebase set and get got fail result. FirebaseStream could not detect changes from cloud and Firebase set and got fail result. May 28, 2016
@proppy proppy added the core label May 29, 2016
@loka17 loka17 changed the title FirebaseStream could not detect changes from cloud and Firebase set and got fail result. FirebaseStream could not detect changes from cloud and Firebase set() and get() got fail result. May 31, 2016
@ed7coyne
Copy link
Collaborator

ed7coyne commented May 31, 2016

The stream depends currently on a open TCP connection. Once you lose wifi it will close and not reconnect itself.

It seems a little heavy handed but it may be easiest to just reset the device when you notice the wifi is dropped. That way you will do the same setup() initialization again. Otherwise you can also reopen the stream yourself when you reset the wifi.

However FirebaseStream.failed() should be returning true when the stream fails. That sounds like a bug we will need to address. I opened #177 to track it.

@tabvn
Copy link

tabvn commented Jul 1, 2016

Same issue at me #185 can not call set during stream

@proppy
Copy link
Contributor

proppy commented Oct 4, 2016

Merging with #48 and #177

@proppy proppy closed this as completed Oct 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants