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

Include ArduinoJson directly in our library and parse json. #79

Merged
merged 4 commits into from
Apr 15, 2016
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
8 changes: 4 additions & 4 deletions examples/FirebasePush_ESP8266/FirebasePush_ESP8266.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
// create firebase client.
Firebase fbase = Firebase("example.firebaseio.com")
.auth("secret_or_token");

void setup() {
Serial.begin(9600);

Expand All @@ -46,7 +45,7 @@ void setup() {
}

// print key.
Serial.println(push.name());
Serial.println("Name: " + push.name());

// get all entries.
FirebaseGet get = fbase.get("/logs");
Expand All @@ -55,8 +54,9 @@ void setup() {
Serial.println(push.error().message());
return;
}
// print json.
Serial.println(get.json());
// Print written timestamp.
String data = get.json()[push.name()];
Serial.println("Timestamp:" + data);
}

void loop() {
Expand Down
9 changes: 9 additions & 0 deletions library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=firebase-arduino
version=0.4
author=
maintainer=
sentence=Fill in later
paragraph=Fill in later
category=Communication
url=http://example.com/
architectures=esp8266
14 changes: 8 additions & 6 deletions Firebase.cpp → src/Firebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,18 @@ FirebaseCall::FirebaseCall(const String& host, const String& auth,
}
}

const JsonObject& FirebaseCall::json() {
//TODO(edcoyne): This is not efficient, we should do something smarter with
//the buffers.
buffer_ = DynamicJsonBuffer();
return buffer_.parseObject(response());
}

// FirebaseGet
FirebaseGet::FirebaseGet(const String& host, const String& auth,
const String& path,
HTTPClient* http)
: FirebaseCall(host, auth, "GET", path, "", http) {
if (!error()) {
// TODO: parse json
json_ = response();
}
}

// FirebaseSet
Expand All @@ -145,8 +148,7 @@ FirebasePush::FirebasePush(const String& host, const String& auth,
HTTPClient* http)
: FirebaseCall(host, auth, "POST", path, value, http) {
if (!error()) {
// TODO: parse name
name_ = response();
name_ = json()["name"].as<const char*>();
}
}

Expand Down
18 changes: 8 additions & 10 deletions Firebase.h → src/Firebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ESP8266HTTPClient.h>
#include "third-party/arduino-json-5.1.1/include/ArduinoJson.h"

class FirebaseGet;
class FirebaseSet;
Expand Down Expand Up @@ -81,24 +82,25 @@ class FirebaseCall {
const FirebaseError& error() const {
return error_;
}

const String& response() {
return response_;
}

const JsonObject& json();

protected:
HTTPClient* http_;
FirebaseError error_;
String response_;
DynamicJsonBuffer buffer_;
};

class FirebaseGet : public FirebaseCall {
public:
FirebaseGet() {}
FirebaseGet(const String& host, const String& auth,
const String& path, HTTPClient* http = NULL);

const String& json() const {
return json_;
}

private:
String json_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove that field now :)

Expand All @@ -110,10 +112,6 @@ class FirebaseSet: public FirebaseCall {
FirebaseSet(const String& host, const String& auth,
const String& path, const String& value, HTTPClient* http = NULL);

const String& json() const {
return json_;
}

private:
String json_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove that field :)

};
Expand Down Expand Up @@ -145,7 +143,7 @@ class FirebaseStream : public FirebaseCall {
FirebaseStream() {}
FirebaseStream(const String& host, const String& auth,
const String& path, HTTPClient* http = NULL);

// Return if there is any event available to read.
bool available();

Expand All @@ -162,7 +160,7 @@ class FirebaseStream : public FirebaseCall {
const FirebaseError& error() const {
return _error;
}

private:
FirebaseError _error;
};
Expand Down
2 changes: 2 additions & 0 deletions src/third-party/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
These are packages that we depend upon. They may need to be trimmed, all .cpp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use a submodule? or subtree to track this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we need a subset of the repo, if we include the whole thing arduino will try to compile their tests too. I cannot find a way to submodule or subtree only part of a repo.

Also since they do actual releases it may be nicer to stay synced to actual releases.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a submodule w/ symlinks in src/?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered that too but from what I gather symlinks in git don't work very well on windows machines.

files in them will be compiled by the arduino IDE.
244 changes: 244 additions & 0 deletions src/third-party/arduino-json-5.1.1/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
ArduinoJson: change log
=======================

v5.1.1
------

* Removed `String` duplication when one replaces a value in a `JsonObject` (PR #232 by @ulion)

v5.1.0
------

* Added support of `long long` (issue #171)
* Moved all build settings to `ArduinoJson/Configuration.hpp`

**BREAKING CHANGE**:
If you defined `ARDUINOJSON_ENABLE_STD_STREAM`, you now need to define it to `1`.

v5.0.8
------

* Made the library compatible with [PlatformIO](http://platformio.org/) (issue #181)
* Fixed `JsonVariant::is<bool>()` that was incorrectly returning false (issue #214)

v5.0.7
------

* Made library easier to use from a CMake project: simply `add_subdirectory(ArduinoJson/src)`
* Changed `String` to be a `typedef` of `std::string` (issues #142 and #161)

**BREAKING CHANGES**:
- `JsonVariant(true).as<String>()` now returns `"true"` instead of `"1"`
- `JsonVariant(false).as<String>()` now returns `"false"` instead of `"0"`

v5.0.6
------

* Added parameter to `DynamicJsonBuffer` constructor to set initial size (issue #152)
* Fixed warning about library category in Arduino 1.6.6 (issue #147)
* Examples: Added a loop to wait for serial port to be ready (issue #156)

v5.0.5
------

* Added overload `JsonObjectSuscript::set(value, decimals)` (issue #143)
* Use `float` instead of `double` to reduce the size of `JsonVariant` (issue #134)

v5.0.4
------

* Fixed ambiguous overload with `JsonArraySubscript` and `JsonObjectSubscript` (issue #122)

v5.0.3
------

* Fixed `printTo(String)` which wrote numbers instead of strings (issue #120)
* Fixed return type of `JsonArray::is<T>()` and some others (issue #121)

v5.0.2
------

* Fixed segmentation fault in `parseObject(String)` and `parseArray(String)`, when the
`StaticJsonBuffer` is too small to hold a copy of the string
* Fixed Clang warning "register specifier is deprecated" (issue #102)
* Fixed GCC warning "declaration shadows a member" (issue #103)
* Fixed memory alignment, which made ESP8266 crash (issue #104)
* Fixed compilation on Visual Studio 2010 and 2012 (issue #107)

v5.0.1
------

* Fixed compilation with Arduino 1.0.6 (issue #99)

v5.0.0
------

* Added support of `String` class (issues #55, #56, #70, #77)
* Added `JsonBuffer::strdup()` to make a copy of a string (issues #10, #57)
* Implicitly call `strdup()` for `String` but not for `char*` (issues #84, #87)
* Added support of non standard JSON input (issue #44)
* Added support of comments in JSON input (issue #88)
* Added implicit cast between numerical types (issues #64, #69, #93)
* Added ability to read number values as string (issue #90)
* Redesigned `JsonVariant` to leverage converting constructors instead of assignment operators (issue #66)
* Switched to new the library layout (requires Arduino 1.0.6 or above)

**BREAKING CHANGES**:
- `JsonObject::add()` was renamed to `set()`
- `JsonArray::at()` and `JsonObject::at()` were renamed to `get()`
- Number of digits of floating point value are now set with `double_with_n_digits()`

**Personal note about the `String` class**:
Support of the `String` class has been added to the library because many people use it in their programs.
However, you should not see this as an invitation to use the `String` class.
The `String` class is **bad** because it uses dynamic memory allocation.
Compared to static allocation, it compiles to a bigger, slower program, and is less predictable.
You certainly don't want that in an embedded environment!

v4.6
----

* Fixed segmentation fault in `DynamicJsonBuffer` when memory allocation fails (issue #92)

v4.5
----

* Fixed buffer overflow when input contains a backslash followed by a terminator (issue #81)

**Upgrading is recommended** since previous versions contain a potential security risk.

Special thanks to [Giancarlo Canales Barreto](https://github.com/gcanalesb) for finding this nasty bug.

v4.4
----

* Added `JsonArray::measureLength()` and `JsonObject::measureLength()` (issue #75)

v4.3
----

* Added `JsonArray::removeAt()` to remove an element of an array (issue #58)
* Fixed stack-overflow in `DynamicJsonBuffer` when parsing huge JSON files (issue #65)
* Fixed wrong return value of `parseArray()` and `parseObject()` when allocation fails (issue #68)

v4.2
----

* Switched back to old library layout (issues #39, #43 and #45)
* Removed global new operator overload (issue #40, #45 and #46)
* Added an example with EthernetServer

v4.1
----

* Added DynamicJsonBuffer (issue #19)

v4.0
----

* Unified parser and generator API (issue #23)
* Updated library layout, now requires Arduino 1.0.6 or newer

**BREAKING CHANGE**: API changed significantly, see [Migrating code to the new API](https://github.com/bblanchon/ArduinoJson/wiki/Migrating-code-to-the-new-API).


v3.4
----

* Fixed escaped char parsing (issue #16)


v3.3
----

* Added indented output for the JSON generator (issue #11), see example bellow.
* Added `IndentedPrint`, a decorator for `Print` to allow indented output

Example:

JsonOject<2> json;
json["key"] = "value";
json.prettyPrintTo(Serial);

v3.2
----

* Fixed a bug when adding nested object in `JsonArray` (bug introduced in v3.1).

v3.1
----

* Calling `Generator::JsonObject::add()` twice with the same `key` now replaces the `value`
* Added `Generator::JsonObject::operator[]`, see bellow the new API
* Added `Generator::JsonObject::remove()` (issue #9)

Old generator API:

JsonObject<3> root;
root.add("sensor", "gps");
root.add("time", 1351824120);
root.add("data", array);

New generator API:

JsonObject<3> root;
root["sensor"] = "gps";
root["time"] = 1351824120;
root["data"] = array;

v3.0
----

* New parser API, see bellow
* Renamed `JsonHashTable` into `JsonObject`
* Added iterators for `JsonArray` and `JsonObject` (issue #4)

Old parser API:

JsonHashTable root = parser.parseHashTable(json);

char* sensor = root.getString("sensor");
long time = root.getLong("time");
double latitude = root.getArray("data").getDouble(0);
double longitude = root.getArray("data").getDouble(1);

New parser API:

JsonObject root = parser.parse(json);

char* sensor = root["sensor"];
long time = root["time"];
double latitude = root["data"][0];
double longitude = root["data"][1];

v2.1
----

* Fixed case `#include "jsmn.cpp"` which caused an error in Linux (issue #6)
* Fixed a buffer overrun in JSON Parser (issue #5)

v2.0
----

* Added JSON encoding (issue #2)
* Renamed the library `ArduinoJsonParser` becomes `ArduinoJson`

**Breaking change**: you need to add the following line at the top of your program.

using namespace ArduinoJson::Parser;

v1.2
----

* Fixed error in JSON parser example (issue #1)

v1.1
----

* Example: changed `char* json` into `char[] json` so that the bytes are not write protected
* Fixed parsing bug when the JSON contains multi-dimensional arrays

v1.0
----

Initial release
10 changes: 10 additions & 0 deletions src/third-party/arduino-json-5.1.1/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
The MIT License (MIT)
---------------------

Copyright © 2014-2016 Benoit BLANCHON

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Loading