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

Commit ae4fdf3

Browse files
committed
merged upstream
2 parents aaadbc2 + 34f51e6 commit ae4fdf3

File tree

85 files changed

+836
-210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+836
-210
lines changed

.travis.yml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
language: c++
22
sudo: false
3-
compiler:
4-
- gcc
3+
addons:
4+
apt:
5+
sources:
6+
- ubuntu-toolchain-r-test
7+
packages:
8+
- g++-4.8
59
env:
610
- ARDUINO_VERSION=1.6.8 ARDUINO_ESP8266_VERSION=2.1.0 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino
711
- ARDUINO_VERSION=1.6.8 ARDUINO_ESP8266_VERSION=2.2.0-rc1 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino
812
- ARDUINO_VERSION=nightly ARDUINO_ESP8266_VERSION=master ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino
913
install:
10-
- if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi
1114
- ( cd ${HOME} && curl -O https://downloads.arduino.cc/arduino-${ARDUINO_VERSION}-linux64.tar.xz && tar xvf arduino-${ARDUINO_VERSION}-linux64.tar.xz )
1215
- git clone --branch ${ARDUINO_ESP8266_VERSION} https://github.com/esp8266/Arduino.git ${ARDUINO_ESP8266_ROOT}
1316
- git submodule init && git submodule update
1417
- ( cd ${ARDUINO_ESP8266_ROOT}/tools && python get.py )
1518
before_script:
1619
- mkdir -p ${ARDUINO_HOME}/libraries
17-
- ( cd ${ARDUINO_HOME}/libraries && ln -s ${TRAVIS_BUILD_DIR} firebase-arduino && ln -s ${TRAVIS_BUILD_DIR}/src/third-party/arduino-json-5.1.1 ArduinoJson )
20+
- ( cd ${ARDUINO_HOME}/libraries && ln -s ${TRAVIS_BUILD_DIR} firebase-arduino && ln -s ${TRAVIS_BUILD_DIR}/src/third-party/arduino-json-5.2 ArduinoJson )
1821
script:
19-
- ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M examples/FirebasePush_ESP8266/FirebasePush_ESP8266.ino
22+
- ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M examples/FirebaseDemo_ESP8266/FirebaseDemo_ESP8266.ino
23+
- (cd test && make check)
2024
- (cd test/modem/ && make test)
21-
addons:
22-
apt:
23-
sources:
24-
- ubuntu-toolchain-r-test
25-
packages:
26-
- gcc-4.8
27-
- g++-4.8

examples/FirebasePush_ESP8266/FirebasePush_ESP8266.ino renamed to examples/FirebaseDemo_ESP8266/FirebaseDemo_ESP8266.ino

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@
1414
// limitations under the License.
1515
//
1616

17-
// FirebasePush_ESP8266 is a sample that push a new timestamp to firebase
18-
// on each reset.
17+
// FirebaseDemo_ESP8266 is a sample that demo the different functions
18+
// of the FirebaseArduino API.
1919

2020
#include <ESP8266WiFi.h>
21-
22-
#include <Firebase.h>
23-
24-
// create firebase client.
25-
Firebase fbase("example.firebaseio.com", "secret_or_token");
21+
#include <FirebaseArduino.h>
2622

2723
void setup() {
2824
Serial.begin(9600);
@@ -37,29 +33,46 @@ void setup() {
3733
Serial.println();
3834
Serial.print("connected: ");
3935
Serial.println(WiFi.localIP());
36+
37+
Firebase.begin("example.firebaseio.com", "token_or_secret");
38+
}
4039

41-
// add a new entry.
42-
FirebasePush push = fbase.push("/logs", "{\".sv\": \"timestamp\"}");
43-
if (push.error()) {
44-
Serial.println("Firebase push failed");
45-
Serial.println(push.error().message());
40+
int n = 0;
41+
42+
void loop() {
43+
// set value
44+
Firebase.set("number", 42.0);
45+
// handle error
46+
if (Firebase.failed()) {
47+
Serial.print("setting /number failed:");
48+
Serial.println(Firebase.error());
4649
return;
4750
}
51+
delay(1000);
52+
53+
// update value
54+
Firebase.set("number", 43.0);
55+
delay(1000);
4856

49-
// print key.
50-
Serial.println("Name: " + push.name());
57+
// get value
58+
Serial.print("number: ");
59+
Serial.println((float)Firebase.get("number"));
60+
delay(1000);
5161

52-
// get all entries.
53-
FirebaseGet get = fbase.get("/logs");
54-
if (get.error()) {
55-
Serial.println("Firebase get failed");
56-
Serial.println(push.error().message());
57-
return;
58-
}
59-
// Print written timestamp.
60-
String data = get.json()[push.name()];
61-
Serial.println("Timestamp:" + data);
62-
}
62+
// remove value
63+
Firebase.remove("number");
64+
delay(1000);
6365

64-
void loop() {
66+
// set string value
67+
Firebase.set("message", "hello world");
68+
delay(1000);
69+
// set bool value
70+
Firebase.set("truth", false);
71+
delay(1000);
72+
73+
// append a new value to /logs
74+
String name = Firebase.push("logs", n++);
75+
Serial.print("pushed: /logs/");
76+
Serial.println(name);
77+
delay(1000);
6578
}

src/Firebase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// TODO(edcoyne): move this into our mock_arduino fork where we actually do the
2727
// override.
2828
#define ARDUINO_STRING_OVERRIDE
29-
#include "third-party/arduino-json-5.1.1/include/ArduinoJson.h"
29+
#include "third-party/arduino-json-5.2/include/ArduinoJson.h"
3030

3131
class FirebaseGet;
3232
class FirebaseSet;

src/FirebaseArduino.cpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//
2+
// Copyright 2016 Google Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
#include "FirebaseArduino.h"
18+
19+
void FirebaseArduino::begin(const char* host, const char* auth) {
20+
http_.reset(FirebaseHttpClient::create());
21+
http_->setReuseConnection(true);
22+
host_ = host;
23+
auth_ = auth;
24+
}
25+
26+
String FirebaseArduino::FirebaseArduino::push(const String& path, const JsonVariant& value) {
27+
String buf;
28+
value.printTo(buf);
29+
auto push = FirebasePush(host_, auth_, path, buf, http_.get());
30+
error_ = push.error();
31+
return push.name();
32+
}
33+
34+
void FirebaseArduino::set(const String& path, const JsonVariant& value) {
35+
String buf;
36+
value.printTo(buf);
37+
auto set = FirebaseSet(host_, auth_, path, buf, http_.get());
38+
error_ = set.error();
39+
}
40+
41+
FirebaseObject FirebaseArduino::get(const char* path) {
42+
auto get = FirebaseGet(host_, auth_, path, http_.get());
43+
error_ = get.error();
44+
if (failed()) {
45+
return FirebaseObject{""};
46+
}
47+
return FirebaseObject(get.response());
48+
}
49+
50+
void FirebaseArduino::remove(const char* path) {
51+
auto remove = FirebaseRemove(host_, auth_, path, http_.get());
52+
error_ = remove.error();
53+
}
54+
55+
void FirebaseArduino::stream(const char* path) {
56+
auto stream = FirebaseStream(host_, auth_, path, http_.get());
57+
error_ = stream.error();
58+
}
59+
60+
bool FirebaseArduino::available() {
61+
return http_->getStreamPtr()->available();
62+
}
63+
64+
FirebaseObject FirebaseArduino::readEvent() {
65+
auto client = http_->getStreamPtr();
66+
String type = client->readStringUntil('\n').substring(7);;
67+
String event = client->readStringUntil('\n').substring(6);
68+
client->readStringUntil('\n'); // consume separator
69+
FirebaseObject obj = FirebaseObject(event);
70+
obj["type"] = type;
71+
return obj;
72+
}
73+
74+
bool FirebaseArduino::success() {
75+
return error_.code() == 0;
76+
}
77+
78+
bool FirebaseArduino::failed() {
79+
return error_.code() != 0;
80+
}
81+
82+
const String& FirebaseArduino::error() {
83+
return error_.message();
84+
}
85+
86+
FirebaseArduino Firebase;

src/FirebaseArduino.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// Copyright 2016 Google Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
#ifndef FIREBASE_ARDUINO_H
18+
#define FIREBASE_ARDUINO_H
19+
20+
#include "Firebase.h"
21+
#include "FirebaseObject.h"
22+
23+
#ifndef FIREBASE_JSONBUFFER_SIZE
24+
#define FIREBASE_JSONBUFFER_SIZE 200
25+
#endif // FIREBASE_JSONBUFFER_SIZE
26+
27+
class FirebaseArduino {
28+
public:
29+
void begin(const char* host, const char* auth = "");
30+
String push(const String& path, const JsonVariant& value);
31+
void set(const String& path, const JsonVariant& value);
32+
FirebaseObject get(const char* path);
33+
void remove(const char* path);
34+
void stream(const char* path);
35+
bool available();
36+
FirebaseObject readEvent();
37+
bool success();
38+
bool failed();
39+
const String& error();
40+
private:
41+
String host_;
42+
String auth_;
43+
FirebaseError error_;
44+
std::unique_ptr<FirebaseHttpClient> http_;
45+
};
46+
47+
extern FirebaseArduino Firebase;
48+
49+
#endif // FIREBASE_ARDUINO_H

src/FirebaseObject.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//
2+
// Copyright 2016 Google Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
#include "FirebaseObject.h"
18+
19+
namespace {
20+
template<typename T>
21+
T decodeJsonLiteral(const String& json) {
22+
return JsonVariant{ArduinoJson::RawJson{json.c_str()}};
23+
}
24+
25+
// ugly workaround to https://github.com/bblanchon/ArduinoJson/issues/265
26+
template<>
27+
String decodeJsonLiteral<String>(const String& json) {
28+
StaticJsonBuffer<JSON_ARRAY_SIZE(1)> buf;
29+
String array = "[" + json + "]";
30+
return buf.parseArray(&array[0])[0];
31+
}
32+
} // namespace
33+
34+
FirebaseObject::FirebaseObject(const String& data) : data_{data} {
35+
if (data_[0] == '{') {
36+
json_ = &buffer_.parseObject(&data_[0]);
37+
} else if (data_[0] == '"') {
38+
data_ = decodeJsonLiteral<String>(data_);
39+
}
40+
}
41+
42+
FirebaseObject::operator bool() {
43+
return decodeJsonLiteral<bool>(data_);
44+
}
45+
46+
FirebaseObject::operator int() {
47+
return decodeJsonLiteral<int>(data_);
48+
}
49+
50+
FirebaseObject::operator float() {
51+
return decodeJsonLiteral<float>(data_);
52+
}
53+
54+
FirebaseObject::operator const String&() {
55+
return data_;
56+
}
57+
58+
FirebaseObject::operator const JsonObject&() {
59+
return *json_;
60+
}
61+
62+
JsonObjectSubscript<const char*> FirebaseObject::operator[](const char* key) {
63+
return json_->operator[](key);
64+
}
65+
66+
JsonObjectSubscript<const String&> FirebaseObject::operator[](const String& key) {
67+
return json_->operator[](key);
68+
}
69+
70+
JsonVariant FirebaseObject::operator[](JsonObjectKey key) const {
71+
return json_->operator[](key);
72+
}

src/FirebaseObject.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// Copyright 2015 Google Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
#ifndef FIREBASE_OBJECT_H
18+
#define FIREBASE_OBJECT_H
19+
20+
#include "third-party/arduino-json-5.2/include/ArduinoJson.h"
21+
22+
#define FIREBASE_JSONBUFFER_SIZE 200
23+
24+
class FirebaseObject {
25+
public:
26+
FirebaseObject(const String& data);
27+
operator bool();
28+
operator int();
29+
operator float();
30+
operator const String&();
31+
operator const JsonObject&();
32+
JsonObjectSubscript<const char*> operator[](const char* key);
33+
JsonObjectSubscript<const String&> operator[](const String& key);
34+
JsonVariant operator[](JsonObjectKey key) const;
35+
private:
36+
String data_;
37+
StaticJsonBuffer<FIREBASE_JSONBUFFER_SIZE> buffer_;
38+
JsonObject* json_;
39+
};
40+
41+
#endif // FIREBASE_OBJECT_H

0 commit comments

Comments
 (0)