This repository was archived by the owner on Mar 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 492
Firebase serial #71
Open
proppy
wants to merge
3
commits into
FirebaseExtended:master
Choose a base branch
from
proppy:firebase-serial
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Firebase serial #71
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// Copyright 2015 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
#include "FirebaseSerial.h" | ||
|
||
FirebaseSerialESP8266 FirebaseSerial; | ||
|
||
void FirebaseSerialESP8266::begin(const String& host, const String& auth, const String& path) { | ||
host_ = host; | ||
auth_ = auth; | ||
path_ = path; | ||
stream_.begin(host, auth, path, &httpStream_); | ||
} | ||
|
||
bool FirebaseSerialESP8266::connected() { | ||
return httpStream_.connected(); | ||
} | ||
|
||
bool FirebaseSerialESP8266::available() { | ||
return httpStream_.getStreamPtr()->available(); | ||
} | ||
|
||
String FirebaseSerialESP8266::read() { | ||
String event; | ||
auto type = stream_.read(event); | ||
return event; | ||
} | ||
|
||
void FirebaseSerialESP8266::println(String data) { | ||
push_.begin(host_, auth_, path_, data, &httpPush_); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// Copyright 2015 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
#ifndef firebase_serial_h | ||
#define firebase_serial_h | ||
|
||
#include "Firebase.h" | ||
|
||
class FirebaseSerialESP8266 { | ||
public: | ||
FirebaseSerialESP8266() {} | ||
void begin(const String& host, const String& auth = "", const String& path = "/"); | ||
bool connected(); | ||
bool available(); | ||
String read(); | ||
void println(String data); | ||
|
||
private: | ||
String host_; | ||
String auth_; | ||
String path_; | ||
HTTPClient httpStream_; | ||
FirebaseStream stream_; | ||
HTTPClient httpPush_; | ||
FirebasePush push_; | ||
}; | ||
|
||
extern FirebaseSerialESP8266 FirebaseSerial; | ||
|
||
#endif // firebase_serial_h |
53 changes: 53 additions & 0 deletions
53
examples/FirebaseSerial_ESP8266/FirebaseSerial_ESP8266.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// Copyright 2016 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
// FirebaseStream_ESP8266 is a sample that stream bitcoin price from a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment needs updating. |
||
// public Firebase and optionally display them on a OLED i2c screen. | ||
|
||
#include <FirebaseSerial.h> | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
|
||
// connect to wifi. | ||
WiFi.begin("SSID", "PASSWORD"); | ||
Serial.print("connecting to wifi"); | ||
while (WiFi.status() != WL_CONNECTED) { | ||
Serial.print("."); | ||
delay(500); | ||
} | ||
Serial.println(); | ||
Serial.print("connected: "); | ||
Serial.println(WiFi.localIP()); | ||
|
||
FirebaseSerial.begin("example.firebaseio.com", "secret"); | ||
Serial.print("connecting to firebase"); | ||
while (!FirebaseSerial.connected()) { | ||
Serial.print("."); | ||
delay(500); | ||
} | ||
Serial.println(); | ||
Serial.println("connected"); | ||
} | ||
|
||
|
||
void loop() { | ||
if (FirebaseSerial.available()) { | ||
Serial.println(FirebaseSerial.read()); | ||
} | ||
delay(1000); | ||
FirebaseSerial.println("{\".sv\": \"timestamp\"}"); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the push a member and not just on the stack? We don't need it around from what I see.
Also how do we report if there is an error sending? We could return bytes written and -1 for error maybe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, it could be on the stack, and I wouldn't have to add the weird-looking
.begin
interface.