diff --git a/Firebase.cpp b/Firebase.cpp index 6752811a..b6e7810b 100644 --- a/Firebase.cpp +++ b/Firebase.cpp @@ -61,8 +61,8 @@ FirebaseStream Firebase::stream(const String& path) { // FirebaseCall FirebaseCall::FirebaseCall(const String& host, const String& auth, - const char* method, const String& path, - const String& data, HTTPClient* http) : http_(http) { + const char* method, const String& path, + const String& data, HTTPClient* http) : http_(http) { String url = makeFirebaseURL(path, auth); http_->setReuse(true); http_->begin(host, kFirebasePort, url, true, kFirebaseFingerprint); @@ -105,8 +105,8 @@ FirebaseCall::FirebaseCall(const String& host, const String& auth, // FirebaseGet FirebaseGet::FirebaseGet(const String& host, const String& auth, - const String& path, - HTTPClient* http) + const String& path, + HTTPClient* http) : FirebaseCall(host, auth, "GET", path, "", http) { if (!error()) { @@ -117,8 +117,8 @@ FirebaseGet::FirebaseGet(const String& host, const String& auth, // FirebasePush FirebasePush::FirebasePush(const String& host, const String& auth, - const String& path, const String& value, - HTTPClient* http) + const String& path, const String& value, + HTTPClient* http) : FirebaseCall(host, auth, "POST", path, value, http) { if (!error()) { // TODO: parse name @@ -128,15 +128,15 @@ FirebasePush::FirebasePush(const String& host, const String& auth, // FirebasePush FirebaseRemove::FirebaseRemove(const String& host, const String& auth, - const String& path, - HTTPClient* http) + const String& path, + HTTPClient* http) : FirebaseCall(host, auth, "DELETE", path, "", http) { } // FirebaseStream FirebaseStream::FirebaseStream(const String& host, const String& auth, - const String& path, - HTTPClient* http) + const String& path, + HTTPClient* http) : FirebaseCall(host, auth, "STREAM", path, "", http) { } diff --git a/Firebase.h b/Firebase.h index aac4e86c..b1af092d 100644 --- a/Firebase.h +++ b/Firebase.h @@ -73,9 +73,9 @@ class FirebaseCall { public: FirebaseCall() {} FirebaseCall(const String& host, const String& auth, - const char* method, const String& path, - const String& data = "", - HTTPClient* http = NULL); + const char* method, const String& path, + const String& data = "", + HTTPClient* http = NULL); const FirebaseError& error() const { return error_; } @@ -92,7 +92,7 @@ class FirebaseGet : public FirebaseCall { public: FirebaseGet() {} FirebaseGet(const String& host, const String& auth, - const String& path, HTTPClient* http = NULL); + const String& path, HTTPClient* http = NULL); const String& json() const { return json_; @@ -106,7 +106,7 @@ class FirebasePush : public FirebaseCall { public: FirebasePush() {} FirebasePush(const String& host, const String& auth, - const String& path, const String& value, HTTPClient* http = NULL); + const String& path, const String& value, HTTPClient* http = NULL); const String& name() const { return name_; @@ -120,7 +120,7 @@ class FirebaseRemove : public FirebaseCall { public: FirebaseRemove() {} FirebaseRemove(const String& host, const String& auth, - const String& path, HTTPClient* http = NULL); + const String& path, HTTPClient* http = NULL); }; @@ -128,7 +128,7 @@ class FirebaseStream : public FirebaseCall { public: FirebaseStream() {} FirebaseStream(const String& host, const String& auth, - const String& path, HTTPClient* http = NULL); + const String& path, HTTPClient* http = NULL); // True if there is an event available. bool available(); diff --git a/examples/FirebaseStream_ESP8266/FirebaseStream_ESP8266.ino b/examples/FirebaseStream_ESP8266/FirebaseStream_ESP8266.ino index 73b17149..e4f10e64 100644 --- a/examples/FirebaseStream_ESP8266/FirebaseStream_ESP8266.ino +++ b/examples/FirebaseStream_ESP8266/FirebaseStream_ESP8266.ino @@ -20,6 +20,7 @@ #include #include #include +#include #define OLED_RESET 10 Adafruit_SSD1306 display(OLED_RESET); @@ -47,7 +48,7 @@ void setup() { } -void loop() { +void loop() { if (stream.error()) { Serial.println("streaming error"); Serial.println(stream.error().message()); @@ -58,16 +59,21 @@ void loop() { auto type = stream.read(event); Serial.print("event: "); Serial.println(type); - if (type != FirebaseStream::Event::UNKNOWN) { + if (type == FirebaseStream::Event::PUT) { + StaticJsonBuffer<200> buf; Serial.print("data: "); Serial.println(event); + JsonObject& json = buf.parseObject((char*)event.c_str()); + String path = json["path"]; + float data = json["data"]; // TODO(proppy): parse JSON object. display.clearDisplay(); - display.setTextSize(1); + display.setTextSize(2); display.setTextColor(WHITE); display.setCursor(0,0); - display.println(event); + display.println(path.c_str()+1); + display.println(data); display.display(); } }