diff --git a/README.md b/README.md index dc9420f8..827cf7ec 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,9 @@ The Arduino library is [under heavy development](https://github.com/googlesample - [FirebaseArduino API Reference](http://firebase-arduino.readthedocs.io/) ## Dependencies -- FirebaseArduino now depends on [ArduinoJson library](https://github.com/bblanchon/ArduinoJson) instead of containing it's own version of it. Please either use Library Manager or download specific version of the library from github. +- FirebaseArduino now depends on [ArduinoJson library](https://github.com/bblanchon/ArduinoJson) instead of containing it's own version of it. Please either use Library Manager or download specific version of the library from github. We recommend that ArduinoJson is at least version [5.13.1](https://github.com/bblanchon/ArduinoJson/tree/v5.13.1) + +- ESP8266 Core SDK. We recommend using officially tagged releases and it should be at least [2.4.1](https://github.com/esp8266/Arduino/tree/2.4.1) ## Disclaimer diff --git a/contrib/test/dummies/FirebaseHttpClient_dummy.cpp b/contrib/test/dummies/FirebaseHttpClient_dummy.cpp index 571fa842..2a89ff90 100644 --- a/contrib/test/dummies/FirebaseHttpClient_dummy.cpp +++ b/contrib/test/dummies/FirebaseHttpClient_dummy.cpp @@ -23,6 +23,10 @@ class FirebaseHttpClientDummy : public FirebaseHttpClient { void addHeader(const std::string& UNUSED_ARG(name), const std::string& UNUSED_ARG(value)) override { } + bool connected() override { + return true; + } + void collectHeaders(const char* UNUSED_ARG(header_keys[]), const int UNUSED_ARG(count)) override { } diff --git a/src/FirebaseArduino.cpp b/src/FirebaseArduino.cpp index 4ab93f0e..0e7ae87d 100644 --- a/src/FirebaseArduino.cpp +++ b/src/FirebaseArduino.cpp @@ -156,6 +156,11 @@ void FirebaseArduino::stream(const String& path) { bool FirebaseArduino::available() { if (stream_http_.get() == nullptr) { + error_ = FirebaseError(FIREBASE_ERROR_CODES::STREAM_NOT_INITIALIZED, "HTTP stream is not initialized"); + return 0; + } + if (!stream_http_.get()->connected()) { + error_ = FirebaseError(FIREBASE_ERROR_CODES::HTTP_CONNECTION_LOST, "Connection Lost"); return 0; } auto client = stream_http_.get()->getStreamPtr(); diff --git a/src/FirebaseError.h b/src/FirebaseError.h index 2a088aa9..422f9193 100644 --- a/src/FirebaseError.h +++ b/src/FirebaseError.h @@ -1,6 +1,14 @@ #ifndef firebase_error_h #define firebase_error_h + +// These error codes are used in addition to regular HTTP error codes. +// Same error space is shared between HTTP errors and these values. +enum FIREBASE_ERROR_CODES { + HTTP_CONNECTION_LOST = -5, + STREAM_NOT_INITIALIZED = -6 +}; + class FirebaseError { public: // Make it explicit that the empty constructor mean no error. diff --git a/src/FirebaseHttpClient.h b/src/FirebaseHttpClient.h index 055699c7..300c3d28 100644 --- a/src/FirebaseHttpClient.h +++ b/src/FirebaseHttpClient.h @@ -33,6 +33,8 @@ class FirebaseHttpClient { virtual std::string errorToString(int error_code) = 0; + virtual bool connected() = 0; + protected: static const uint16_t kFirebasePort = 443; }; diff --git a/src/FirebaseHttpClient_Esp8266.cpp b/src/FirebaseHttpClient_Esp8266.cpp index 92dbe92d..c78590dc 100644 --- a/src/FirebaseHttpClient_Esp8266.cpp +++ b/src/FirebaseHttpClient_Esp8266.cpp @@ -83,6 +83,10 @@ class FirebaseHttpClientEsp8266 : public FirebaseHttpClient { return HTTPClient::errorToString(error_code).c_str(); } + bool connected() override { + return http_.connected(); + } + private: ForceReuseHTTPClient http_; };