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

Commit 62c18a0

Browse files
committed
Merge remote-tracking branch 'upstream/master' into modem-example
2 parents 8622277 + 34f51e6 commit 62c18a0

File tree

90 files changed

+896
-254
lines changed

Some content is hidden

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

90 files changed

+896
-254
lines changed

.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
language: c
2+
sudo: false
3+
addons:
4+
apt:
5+
sources:
6+
- ubuntu-toolchain-r-test
7+
packages:
8+
- g++-4.8
9+
env:
10+
- ARDUINO_VERSION=1.6.8 ARDUINO_ESP8266_VERSION=2.1.0 GCC_VERSION=4.8 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino CXX=g++-${GCC_VERSION}
11+
- ARDUINO_VERSION=1.6.8 ARDUINO_ESP8266_VERSION=2.2.0-rc1 GCC_VERSION=4.8 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino CXX=g++-${GCC_VERSION}
12+
- ARDUINO_VERSION=nightly ARDUINO_ESP8266_VERSION=master GCC_VERSION=4.8 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino CXX=g++-${GCC_VERSION}
13+
install:
14+
- ( cd ${HOME} && curl -O https://downloads.arduino.cc/arduino-${ARDUINO_VERSION}-linux64.tar.xz && tar xvf arduino-${ARDUINO_VERSION}-linux64.tar.xz )
15+
- git clone --branch ${ARDUINO_ESP8266_VERSION} https://github.com/esp8266/Arduino.git ${ARDUINO_ESP8266_ROOT}
16+
- ( cd ${ARDUINO_ESP8266_ROOT}/tools && python get.py )
17+
before_script:
18+
- mkdir -p ${ARDUINO_HOME}/libraries
19+
- ( cd ${ARDUINO_HOME}/libraries && ln -s ${TRAVIS_BUILD_DIR} firebase-arduino && ln -s ${TRAVIS_BUILD_DIR}/src/third-party/arduino-json-5.2 ArduinoJson )
20+
script:
21+
- ${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
22+
- cd test && make check
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
// FirebaseDemo_ESP8266 is a sample that demo the different functions
18+
// of the FirebaseArduino API.
19+
20+
#include <ESP8266WiFi.h>
21+
#include <FirebaseArduino.h>
22+
23+
void setup() {
24+
Serial.begin(9600);
25+
26+
// connect to wifi.
27+
WiFi.begin("SSID", "PASSWORD");
28+
Serial.print("connecting");
29+
while (WiFi.status() != WL_CONNECTED) {
30+
Serial.print(".");
31+
delay(500);
32+
}
33+
Serial.println();
34+
Serial.print("connected: ");
35+
Serial.println(WiFi.localIP());
36+
37+
Firebase.begin("example.firebaseio.com", "token_or_secret");
38+
}
39+
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());
49+
return;
50+
}
51+
delay(1000);
52+
53+
// update value
54+
Firebase.set("number", 43.0);
55+
delay(1000);
56+
57+
// get value
58+
Serial.print("number: ");
59+
Serial.println((float)Firebase.get("number"));
60+
delay(1000);
61+
62+
// remove value
63+
Firebase.remove("number");
64+
delay(1000);
65+
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);
78+
}

examples/FirebasePush_ESP8266/FirebasePush_ESP8266.ino

Lines changed: 0 additions & 63 deletions
This file was deleted.

examples/FirebaseStream_ESP8266/FirebaseStream_ESP8266.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// public Firebase and optionally display them on a OLED i2c screen.
1919

2020
#include <Firebase.h>
21+
#include <ESP8266WiFi.h>
2122
#include <Adafruit_GFX.h>
2223
#include <Adafruit_SSD1306.h>
2324
#include <ArduinoJson.h>

examples/Firebase_ESP8266_LEDs/Firebase_ESP8266_Neopixel/Firebase_ESP8266_Neopixel.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// to set pixel data using a firebase stream.
1919
#include <Firebase.h>
2020
#include <ArduinoJson.h>
21+
#include <ESP8266WiFi.h>
2122

2223
#include <Adafruit_NeoPixel.h>
2324
#include "colors_ext.h"

src/Firebase.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,12 @@ String makeFirebaseURL(const String& path, const String& auth) {
3232

3333
} // namespace
3434

35-
Firebase::Firebase(const String& host) : host_(host) {
35+
Firebase::Firebase(const String& host, const String& auth) : host_(host), auth_(auth) {
3636
http_.reset(FirebaseHttpClient::create());
3737
http_->setReuseConnection(true);
3838
}
3939

40-
Firebase& Firebase::auth(const String& auth) {
41-
auth_ = auth;
42-
return *this;
43-
}
44-
45-
const String& Firebase::auth() {
40+
const String& Firebase::auth() const {
4641
return auth_;
4742
}
4843

@@ -168,7 +163,7 @@ FirebasePush::FirebasePush(const String& host, const String& auth,
168163
FirebaseHttpClient* http)
169164
: FirebaseCall(host, auth, "POST", path, value, http) {
170165
if (!error()) {
171-
//name_ = json()["name"].as<const char*>();
166+
name_ = json()["name"].as<const char*>();
172167
}
173168
}
174169

src/Firebase.h

Lines changed: 3 additions & 8 deletions
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;
@@ -37,14 +37,9 @@ class FirebaseStream;
3737
// Firebase REST API client.
3838
class Firebase {
3939
public:
40-
explicit Firebase(const String& host);
41-
Firebase& auth(const String& auth);
42-
virtual ~Firebase() = default;
40+
Firebase(const String& host, const String& auth = "");
4341

44-
Firebase(const Firebase&) = delete;
45-
46-
// Fetch auth string back.
47-
const String& auth();
42+
const String& auth() const;
4843

4944
// Fetch json encoded `value` at `path`.
5045
FirebaseGet get(const String& path);

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

0 commit comments

Comments
 (0)