Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit59f773c

Browse files
committed
merge
2 parents2ba6fea +7d476b8 commit59f773c

File tree

10 files changed

+343
-117
lines changed

10 files changed

+343
-117
lines changed

‎examples/FirebaseDemo_ESP8266/FirebaseDemo_ESP8266.ino‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void loop() {
5656

5757
// get value
5858
Serial.print("number:");
59-
Serial.println((float)Firebase.get("number"));
59+
Serial.println(Firebase.getFloat("number"));
6060
delay(1000);
6161

6262
// remove value

‎examples/FirebaseRoom_ESP8266/FirebaseRoom_ESP8266.ino‎

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,24 @@
2020
#include<ESP8266WiFi.h>
2121
#include<FirebaseArduino.h>
2222

23+
constint grovePowerPin =15;
24+
constint vibratorPin =5;
25+
constint lightSensorPin = A0;
26+
constint ledPin =12;
27+
constint buttonPin =14;
28+
constint fanPin =13;
29+
2330
voidsetup() {
2431
Serial.begin(9600);
2532

26-
// power grove connector
27-
pinMode(15, OUTPUT);
28-
digitalWrite(15, HIGH);
33+
pinMode(grovePowerPin, OUTPUT);
34+
digitalWrite(grovePowerPin, HIGH);
2935

30-
// pin 5 is connected to a vibrator motor.
31-
pinMode(5, OUTPUT);
32-
// pin A0 is connected to a light sensor.
33-
pinMode(A0, INPUT);
34-
// pin 12 is connected to a red LED.
35-
pinMode(12, OUTPUT);
36-
// pin 14 is connected to a push button.
37-
pinMode(14, INPUT);
38-
// pin 13 is connected to a fan.
39-
pinMode(13, OUTPUT);
36+
pinMode(vibratorPin, OUTPUT);
37+
pinMode(lightSensorPin, INPUT);
38+
pinMode(ledPin, OUTPUT);
39+
pinMode(buttonPin, INPUT);
40+
pinMode(fanPin, OUTPUT);
4041

4142
// connect to wifi.
4243
WiFi.begin("SSID","PASSWORD");
@@ -48,23 +49,28 @@ void setup() {
4849
Serial.println();
4950
Serial.print("connected:");
5051
Serial.println(WiFi.localIP());
51-
52+
5253
Firebase.begin("example.firebaseio.com","secret_or_token");
54+
Firebase.set("pushbutton",0);
55+
Firebase.set("sunlight",0);
56+
Firebase.set("redlight",0);
57+
Firebase.set("cooldown",0);
58+
Firebase.set("brrr",0);
5359
}
5460

5561
int button =0;
5662
float light =0.0;
5763

5864
voidloop() {
59-
digitalWrite(12, (int)Firebase.get("redlight"));
60-
digitalWrite(13, (int)Firebase.get("cooldown"));
61-
digitalWrite(5, (int)Firebase.get("brrr"));
62-
int newButton =digitalRead(14);
65+
digitalWrite(ledPin,Firebase.getInt("redlight"));
66+
digitalWrite(fanPin,Firebase.getInt("cooldown"));
67+
digitalWrite(vibratorPin,Firebase.getInt("brrr"));
68+
int newButton =digitalRead(buttonPin);
6369
if (newButton != button) {
6470
button = newButton;
6571
Firebase.set("pushbutton", button);
6672
}
67-
float newLight =analogRead(A0);
73+
float newLight =analogRead(lightSensorPin);
6874
if (abs(newLight - light) >100) {
6975
light = newLight;
7076
Firebase.set("sunlight", light);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#Firebase Room
2+
3+
##Software setup
4+
5+
1. Install[Arduino 1.6.9](https://www.arduino.cc/en/Main/Software)
6+
1. Install[Arduino ESP8266 core](https://github.com/esp8266/Arduino#installing-with-boards-manager)
7+
1. Download[FirebaseArduino library](https://github.com/googlesamples/firebase-arduino/archive/master.zip)
8+
1. Start Arduino
9+
1. Click`Sketch > Include Library > Add .ZIP Library...`
10+
1. Choose`firebase-arduino-master.zip` downloaded in step`3.`
11+
12+
##Hardware setup
13+
14+
1. Get a[Wio Link](http://www.seeedstudio.com/wiki/Wio_Link)
15+
1. Connect:
16+
- a[Grove - Vibration Motor](http://www.seeedstudio.com/wiki/Grove_-_Vibration_Motor) on`pin 5`
17+
- a[Grove - Light Sensor](http://www.seeedstudio.com/wiki/Grove_-_Light_Sensor) on`pin A0`
18+
- a[Grove - Red LED](http://www.seeedstudio.com/wiki/Grove_-_Red_LED) on`pin 12`
19+
- a[Grove - Button](http://www.seeedstudio.com/wiki/Grove_-_Button) on`pin 14`
20+
- a[Grove - Mini Fan](http://www.seeedstudio.com/wiki/Grove_-_Mini_Fan) on`pin 13`
21+
22+
##Configuration
23+
24+
1. Go tohttps://www.firebase.com/ and create a new Firebase
25+
1. Copy the`Firebase Hostname`
26+
1. Go to`Secrets`
27+
1. Click`Firebase Secrets > Shows`
28+
1. Copy the`Firebase Secret`
29+
1. Start Arduino
30+
1. Click`File > Examples > firebase-arduino > FirebaseRoom_ESP8266`
31+
1. Replace`example.firebaseio.com` with the`Firebase Hostname` from step`2.`
32+
1. Replace`secret_or_token` with`Firebase Secret` from step`5.`
33+
1. Click`Sketch > Upload`
34+
35+
##Play
36+
37+
1. Go to the Firebase console`Data` section
38+
1. Set`redlight` to`1` then`0`
39+
1. Watch the Red LED turn on and off in the room
40+
1. Same for`cooldown` and`brrr`
41+
1. Press the push button in the room
42+
1. Watch the`pushbutton` value change in the Firebase console
43+
1. Put your hand on the light sensor
44+
1. Watch the`sunlight` value change in the Firebase console
45+
46+
##Homeworks
47+
48+
- Build a[Firebase web app](https://www.firebase.com/docs/web/) that interacts with the room.
49+
- Connect other Grove modules to the room and submit new[PRs](https://github.com/googlesamples/firebase-arduino/pulls)
50+
- Reduce the number of Firebase API calls using`FirebaseObject` or`FirebaseStream`.
51+
- Watch or star the[GitHub repo repo](https://github.com/googlesamples/firebase-arduino)
52+
- Give[feedback](gitter.im/googlesamples/firebase-arduino)
53+
- Report[bugs](https://github.com/googlesamples/firebase-arduino/issues/new)
54+
-[Fork](https://github.com/googlesamples/firebase-arduino#fork-destination-box) and[contribute](https://github.com/googlesamples/firebase-arduino/blob/master/CONTRIBUTING.md)

‎examples/FirebaseStream_ESP8266/FirebaseStream_ESP8266.ino‎

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@
1717
// FirebaseStream_ESP8266 is a sample that stream bitcoin price from a
1818
// public Firebase and optionally display them on a OLED i2c screen.
1919

20-
#include<Firebase.h>
20+
#include<FirebaseArduino.h>
2121
#include<ESP8266WiFi.h>
2222
#include<Adafruit_GFX.h>
2323
#include<Adafruit_SSD1306.h>
2424

2525
#defineOLED_RESET3
2626
Adafruit_SSD1306display(OLED_RESET);
2727

28-
Firebasefbase("publicdata-cryptocurrency.firebaseio.com");
29-
FirebaseStream stream;
30-
3128
voidsetup() {
3229
Serial.begin(9600);
3330

@@ -44,30 +41,31 @@ void setup() {
4441
Serial.println();
4542
Serial.print("connected:");
4643
Serial.println(WiFi.localIP());
47-
stream = fbase.stream("/bitcoin/last");
44+
45+
Firebase.begin("publicdata-cryptocurrency.firebaseio.com");
46+
Firebase.stream("/bitcoin/last");
4847
}
4948

5049

5150
voidloop() {
52-
if (stream.error()) {
51+
if (Firebase.failed()) {
5352
Serial.println("streaming error");
54-
Serial.println(stream.error().message());
53+
Serial.println(Firebase.error());
5554
}
5655

57-
if (stream.available()) {
58-
String event;
59-
auto type = stream.read(event);
56+
if (Firebase.available()) {
57+
FirebaseObject event = Firebase.readEvent();
58+
String eventType = event.getString("type");
59+
eventType.toLowerCase();
60+
6061
Serial.print("event:");
61-
Serial.println(type);
62-
if (type == FirebaseStream::Event::PUT) {
63-
StaticJsonBuffer<200> buf;
62+
Serial.println(eventType);
63+
if (eventType =="put") {
6464
Serial.print("data:");
65-
Serial.println(event);
66-
JsonObject& json = buf.parseObject((char*)event.c_str());
67-
String path = json["path"];
68-
float data = json["data"];
65+
Serial.println(event.getString("data"));
66+
String path = event.getString("path");
67+
float data = event.getFloat("data");
6968

70-
// TODO(proppy): parse JSON object.
7169
display.clearDisplay();
7270
display.setTextSize(2);
7371
display.setTextColor(WHITE);

‎library.properties‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name=firebase-arduino
2-
version=0.4
1+
name=FirebaseArduino
2+
version=0.1
33
author=
44
maintainer=
5-
sentence=Fill in later
6-
paragraph=Fill in later
5+
sentence=Library for communicating with Firebase.
6+
paragraph=This library simplifies the process of communicating with Firebase. It hides the complexity of authentication and json parsing.
77
category=Communication
8-
url=http://example.com/
8+
url=https://github.com/googlesamples/firebase-arduino
99
architectures=esp8266

‎src/FirebaseArduino.cpp‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,42 @@ FirebaseObject FirebaseArduino::get(const String& path) {
4747
returnFirebaseObject(get.response());
4848
}
4949

50+
intFirebaseArduino::getInt(constchar* path) {
51+
auto get =FirebaseGet(host_, auth_, path, http_.get());
52+
error_ = get.error();
53+
if (failed()) {
54+
return0;
55+
}
56+
returnFirebaseObject(get.response()).getInt();
57+
}
58+
59+
60+
floatFirebaseArduino::getFloat(constchar* path) {
61+
auto get =FirebaseGet(host_, auth_, path, http_.get());
62+
error_ = get.error();
63+
if (failed()) {
64+
return0.0f;
65+
}
66+
returnFirebaseObject(get.response()).getFloat();
67+
}
68+
69+
StringFirebaseArduino::getString(constchar* path) {
70+
auto get =FirebaseGet(host_, auth_, path, http_.get());
71+
error_ = get.error();
72+
if (failed()) {
73+
return"";
74+
}
75+
returnFirebaseObject(get.response()).getString();
76+
}
77+
78+
boolFirebaseArduino::getBool(constchar* path) {
79+
auto get =FirebaseGet(host_, auth_, path, http_.get());
80+
error_ = get.error();
81+
if (failed()) {
82+
return"";
83+
}
84+
returnFirebaseObject(get.response()).getBool();
85+
}
5086
voidFirebaseArduino::remove(const String& path) {
5187
auto remove =FirebaseRemove(host_, auth_, path, http_.get());
5288
error_ = remove.error();
@@ -67,7 +103,7 @@ FirebaseObject FirebaseArduino::readEvent() {
67103
String event = client->readStringUntil('\n').substring(6);
68104
client->readStringUntil('\n');// consume separator
69105
FirebaseObject obj =FirebaseObject(event);
70-
obj["type"] = type;
106+
obj.getJsonVariant().asObject()["type"] = type;
71107
return obj;
72108
}
73109

‎src/FirebaseArduino.h‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,42 @@ class FirebaseArduino {
5858

5959

6060
/**
61-
* Gets the value located at path.
61+
* Gets theintegervalue located at path.
6262
* You should check success() after calling.
6363
* \param path The path to the node you wish to retrieve.
64-
* \return The data located at that path. This may either be a single element
65-
* or it may be a json structure. Will only be populated if success() is true.
64+
* \return The integer value located at that path. Will only be populated if success() is true.
65+
*/
66+
intgetInt(constchar* path);
67+
68+
/**
69+
* Gets the float value located at path.
70+
* You should check success() after calling.
71+
* \param path The path to the node you wish to retrieve.
72+
* \return The float value located at that path. Will only be populated if success() is true.
73+
*/
74+
floatgetFloat(constchar* path);
75+
76+
/**
77+
* Gets the string value located at path.
78+
* You should check success() after calling.
79+
* \param path The path to the node you wish to retrieve.
80+
* \return The string value located at that path. Will only be populated if success() is true.
81+
*/
82+
StringgetString(constchar* path);
83+
84+
/**
85+
* Gets the boolean value located at path.
86+
* You should check success() after calling.
87+
* \param path The path to the node you wish to retrieve.
88+
* \return The boolean value located at that path. Will only be populated if success() is true.
89+
*/
90+
boolgetBool(constchar* path);
91+
92+
/**
93+
* Gets the json object value located at path.
94+
* You should check success() after calling.
95+
* \param path The path to the node you wish to retrieve.
96+
* \return a FirebaseObject value located at that path. Will only be populated if success() is true.
6697
*/
6798
FirebaseObjectget(const String& path);
6899

@@ -94,7 +125,7 @@ class FirebaseArduino {
94125
/**
95126
* Reads the next event in a stream. This is only meaningful once stream() has
96127
* been called.
97-
* \returnObject will have ["type"] that describes the event type, ["path"]
128+
* \returnFirebaseObject will have ["type"] that describes the event type, ["path"]
98129
* that describes the effected path and ["data"] that was updated.
99130
*/
100131
FirebaseObjectreadEvent();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp