1717// FirebaseStream_ESP8266 is a sample that stream bitcoin price from a
1818// public Firebase and optionally display them on a OLED i2c screen.
1919
20- #include < Firebase .h>
20+ #include < FirebaseArduino .h>
2121#include < ESP8266WiFi.h>
2222#include < Adafruit_GFX.h>
2323#include < Adafruit_SSD1306.h>
2424
2525#define OLED_RESET 3
2626Adafruit_SSD1306 display (OLED_RESET);
2727
28- Firebase fbase (" publicdata-cryptocurrency.firebaseio.com" );
29- FirebaseStream stream;
30-
3128void setup () {
3229 Serial.begin (9600 );
3330
@@ -44,30 +41,31 @@ void setup() {
4441 Serial.println ();
4542 Serial.print (" connected: " );
4643 Serial.println (WiFi.localIP ());
47- stream = fbase.stream (" /bitcoin/last" );
44+
45+ Firebase.begin (" publicdata-cryptocurrency.firebaseio.com" );
46+ Firebase.stream (" /bitcoin/last" );
4847}
4948
5049
5150void loop () {
52- if (stream. error ()) {
51+ if (Firebase. failed ()) {
5352 Serial.println (" streaming error" );
54- Serial.println (stream .error (). message ());
53+ Serial.println (Firebase .error ());
5554 }
5655
57- if (stream.available ()) {
58- String event;
59- auto type = stream.read (event);
56+ if (Firebase.available ()) {
57+ FirebaseObject event = Firebase.readEvent ();
58+ String event_type = event[" type" ];
59+ event_type.toLowerCase ();
60+
6061 Serial.print (" event: " );
61- Serial.println (type);
62- if (type == FirebaseStream::Event::PUT) {
63- StaticJsonBuffer<200 > buf;
62+ Serial.println (event_type);
63+ if (event_type == " put" ) {
6464 Serial.print (" data: " );
65- Serial.println (event);
66- JsonObject& json = buf.parseObject ((char *)event.c_str ());
67- String path = json[" path" ];
68- float data = json[" data" ];
65+ Serial.println (event[" data" ].asString ());
66+ String path = event[" path" ];
67+ float data = event[" data" ];
6968
70- // TODO(proppy): parse JSON object.
7169 display.clearDisplay ();
7270 display.setTextSize (2 );
7371 display.setTextColor (WHITE);
0 commit comments