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

Simple streaming API proposal #159

Open
proppy opened this issue May 19, 2016 · 6 comments
Open

Simple streaming API proposal #159

proppy opened this issue May 19, 2016 · 6 comments

Comments

@proppy
Copy link
Contributor

proppy commented May 19, 2016

I'd like to propose a simple way to handle streaming, instead of having explicit stream methods, it could just an option of begin(), a different variant beginStream or even a FirebaseStream global object.

stream an int value

void setup() {
    FirebaseStream.begin("example.firebaseio.com", "token_or_secret");
}

void loop() {
   if (FirebaseStream.available()) {
     Serial.print("value changed:");
     Serial.println(FirebaseStream.getInt('/path/to/int'));
   }
}

stream a more complex object

void setup() {
    FirebaseStream.begin("example.firebaseio.com", "token_or_secret");
}

void loop() {
  if (FirebaseStream.available()) {
    FirebaseObject obj = FirebaseStream.get('/path/to/object')
    Serial.print("value changed:");
    Serial.println(obj.getFloat("/subpath/to/float););
  }
}

This could also mix well with #160 to stream from a specific path.

void setup() {
    FirebaseStream.begin("example.firebaseio.com", "token_or_secret", '/path/to/object');
}

void loop() {
  if (FirebaseStream.available()) {
    Serial.print("value changed:");
    Serial.println(FirebaseStream.getFloat("/subpath/to/float););
  }
}
@proppy
Copy link
Contributor Author

proppy commented May 31, 2016

We should also add method to check for other type of event:
child_added child_changed child_removed child_moved

@Aylali
Copy link

Aylali commented Mar 28, 2017

Hi I am curios, did this really easy way of streaming incoming value worked out?

@proppy
Copy link
Contributor Author

proppy commented Jun 26, 2018

I think we want something like this:

void setup() {
    Firebase.begin();
}

void loop() {
    Firebase.stream('/foo'); # consume one event from the stream
    if (Firebase.error()) { # check for erros
       // ...
    }
    if (Firebase.changed(/'bar')) { # check if /foo/bar changed
        int foo = Firebase.getInt('/bar'); # get foo/bar updated value
    }
}

@adamrabbani
Copy link

adamrabbani commented Jun 26, 2018

@proppy
if (Firebase.changed(/'bar')) { # check if /foo/bar changed
int foo = Firebase.getInt('/bar'); # get foo/bar updated value
}
what different size data between .changed and .get ?? same download or not ?
Thanks

@proppy
Copy link
Contributor Author

proppy commented Jun 26, 2018

@adamrabbani .changed would just return a bool, .get would actually return the data. The event actually get consumed on the .stream call.

@adamrabbani
Copy link

@proppy ohh.. i see.. good

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

3 participants