Skip to content

Commit

Permalink
Merge pull request #356 from kotl/master
Browse files Browse the repository at this point in the history
Update suggested versions and manually merge connection error check
  • Loading branch information
proppy authored Jun 21, 2018
2 parents 0c1b046 + 9dcf205 commit 26a87d4
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions contrib/test/dummies/FirebaseHttpClient_dummy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}

Expand Down
5 changes: 5 additions & 0 deletions src/FirebaseArduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions src/FirebaseError.h
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/FirebaseHttpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
4 changes: 4 additions & 0 deletions src/FirebaseHttpClient_Esp8266.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class FirebaseHttpClientEsp8266 : public FirebaseHttpClient {
return HTTPClient::errorToString(error_code).c_str();
}

bool connected() override {
return http_.connected();
}

private:
ForceReuseHTTPClient http_;
};
Expand Down

0 comments on commit 26a87d4

Please sign in to comment.