17
17
// FirebaseStream_ESP8266 is a sample that stream bitcoin price from a
18
18
// public Firebase and optionally display them on a OLED i2c screen.
19
19
20
- #include < Firebase .h>
20
+ #include < FirebaseArduino .h>
21
21
#include < ESP8266WiFi.h>
22
22
#include < Adafruit_GFX.h>
23
23
#include < Adafruit_SSD1306.h>
24
24
25
25
#define OLED_RESET 3
26
26
Adafruit_SSD1306display (OLED_RESET);
27
27
28
- Firebasefbase (" publicdata-cryptocurrency.firebaseio.com" );
29
- FirebaseStream stream;
30
-
31
28
void setup () {
32
29
Serial.begin (9600 );
33
30
@@ -44,30 +41,31 @@ void setup() {
44
41
Serial.println ();
45
42
Serial.print (" connected:" );
46
43
Serial.println (WiFi.localIP ());
47
- stream = fbase.stream (" /bitcoin/last" );
44
+
45
+ Firebase.begin (" publicdata-cryptocurrency.firebaseio.com" );
46
+ Firebase.stream (" /bitcoin/last" );
48
47
}
49
48
50
49
51
50
void loop () {
52
- if (stream. error ()) {
51
+ if (Firebase. failed ()) {
53
52
Serial.println (" streaming error" );
54
- Serial.println (stream .error (). message ());
53
+ Serial.println (Firebase .error ());
55
54
}
56
55
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
+
60
61
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" ) {
64
64
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" ][" data" ];
69
68
70
- // TODO(proppy): parse JSON object.
71
69
display.clearDisplay ();
72
70
display.setTextSize (2 );
73
71
display.setTextColor (WHITE);