Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Update suggested versions and manually merge connection error check #356

Merged
merged 5 commits into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion examples/FirebaseRoom_ESP8266/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ sensor data to Firebase, and trigger actuators from Firebase.
- Add Grove modules to modules interactions.
- Connect other Grove modules to the room and submit new [PRs](https://github.com/googlesamples/firebase-arduino/pulls)
- Reduce the number of Firebase API calls using `FirebaseObject` or `FirebaseStream`.
- Watch or star the [GitHub repo repo](https://github.com/googlesamples/firebase-arduino)
- Watch or star the [GitHub repo](https://github.com/googlesamples/firebase-arduino)
- Give [feedback](https://gitter.im/googlesamples/firebase-arduino)
- Report [bugs](https://github.com/googlesamples/firebase-arduino/issues/new)
- [Fork](https://github.com/googlesamples/firebase-arduino#fork-destination-box) and [contribute](https://github.com/googlesamples/firebase-arduino/blob/master/CONTRIBUTING.md)
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