14
14
// limitations under the License.
15
15
//
16
16
17
- // FirebaseStream_ESP8266 is a sample that stream on a firebase child
18
- // node.
17
+ // FirebaseStream_ESP8266 is a sample that stream bitcoin price from a
18
+ // public Firebase and display it on a i2c OLED screen.
19
+
20
+ //
21
+ // Copyright 2015 Google Inc.
22
+ //
23
+ // Licensed under the Apache License, Version 2.0 (the "License");
24
+ // you may not use this file except in compliance with the License.
25
+ // You may obtain a copy of the License at
26
+ //
27
+ // http://www.apache.org/licenses/LICENSE-2.0
28
+ //
29
+ // Unless required by applicable law or agreed to in writing, software
30
+ // distributed under the License is distributed on an "AS IS" BASIS,
31
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
+ // See the License for the specific language governing permissions and
33
+ // limitations under the License.
34
+ //
35
+
36
+ // FirebaseStream_ESP8266 is a sample that stream bitcoin price from a
37
+ // public Firebase and optionally display them on a OLED i2c screen.
19
38
20
39
#include < Firebase.h>
40
+ #include < Adafruit_GFX.h>
41
+ #include < Adafruit_SSD1306.h>
21
42
22
- Firebase fbase = Firebase(" example.firebaseio.com" );
43
+ #define OLED_RESET 10
44
+ Adafruit_SSD1306display (OLED_RESET);
45
+
46
+ Firebase fbase = Firebase(" publicdata-cryptocurrency.firebaseio.com" );
23
47
24
48
void setup () {
25
49
Serial.begin (9600 );
26
50
51
+ display.begin (SSD1306_SWITCHCAPVCC,0x3C );// initialize with the I2C addr 0x3C (for the 128x32)
52
+ display.display ();
53
+
27
54
// connect to wifi.
28
55
WiFi.begin (" SSID" ," PASSWORD" );
29
56
Serial.print (" connecting" );
@@ -35,7 +62,7 @@ void setup() {
35
62
Serial.print (" connected:" );
36
63
Serial.println (WiFi.localIP ());
37
64
38
- fbase.stream (" /chat " );
65
+ fbase.stream (" /bitcoin " );
39
66
}
40
67
41
68
@@ -49,9 +76,17 @@ void loop() {
49
76
auto type = fbase.read (event);
50
77
Serial.print (" event:" );
51
78
Serial.println (type);
52
- if (type != Firebase::Event::UNKNOWN) {
79
+ if (type != Firebase::Event::UNKNOWN) {
53
80
Serial.print (" data:" );
54
81
Serial.println (event);
82
+
83
+ // TODO(proppy): parse JSON object.
84
+ display.clearDisplay ();
85
+ display.setTextSize (1 );
86
+ display.setTextColor (WHITE);
87
+ display.setCursor (0 ,0 );
88
+ display.println (event);
89
+ display.display ();
55
90
}
56
91
}
57
92
}