2019年2月10日 星期日

FirebaseDemo

源自於 https://github.com/FirebaseExtended/firebase-arduino/blob/master/examples/FirebaseDemo_ESP8266/README.md

FirebaseDemo

FirebaseDemo is a sample that shows basic usage of the FirebaseArduino API.

Software setup

  1. Install Arduino 1.6.9
  2. Install Arduino ESP8266 core
  3. Download FirebaseArduino library
  4. Start Arduino
  5. Click Sketch > Include Library > Add .ZIP Library...
  6. Choose firebase-arduino-master.zip downloaded in step 3.

Configuration

  1. Start Arduino
  2. Open File > Examples > FirebaseArduino > FirebaseRoom_ESP8266
  3. In FirebaseRoom_ESP8266: Replace WIFI_SSID and WIFI_PASSWORD with WiFi credentials
  4. Go to https://firebase.google.com/console/ and create a new Firebase Project
  5. Go to Database
  6. Copy the Database hostname (Database URL without https:// and trailing /)
  7. In FirebaseRoom_ESP8266: replace FIREBASE_HOST with the Database Hostname
  8. Go to ⚙ > Project Settings > Database > Database secrets
  9. Click Firebase Secrets > Show
  10. Copy the Database Secret
  11. In FirebaseRoom_ESP8266: Replace FIREBASE_AUTH with Database Secret
  12. Select the board Board > ESP8266 Modules > NodeMCU 1.0
  13. Select the serial port Port > /dev/tty...
  14. Select the upload speed Upload Speed > 115200
  15. Click Sketch > Upload

Play

  1. Go to the Firebase console Data section
  2. Watch the data being modified as the sketch runs

源自於 https://github.com/FirebaseExtended/firebase-arduino/blob/master/examples/FirebaseDemo_ESP8266/FirebaseDemo_ESP8266.ino

//
// 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.
//
// FirebaseDemo_ESP8266 is a sample that demo the different functions
// of the FirebaseArduino API.
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
// Set these to run example.
#define FIREBASE_HOST "example.firebaseio.com"
#define FIREBASE_AUTH "token_or_secret"
#define WIFI_SSID "SSID"
#define WIFI_PASSWORD "PASSWORD"
void setup() {
Serial.begin(9600);
// connect to wifi.
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
int n = 0;
void loop() {
// set value
Firebase.setFloat("number", 42.0);
// handle error
if (Firebase.failed()) {
Serial.print("setting /number failed:");
Serial.println(Firebase.error());
return;
}
delay(1000);
// update value
Firebase.setFloat("number", 43.0);
// handle error
if (Firebase.failed()) {
Serial.print("setting /number failed:");
Serial.println(Firebase.error());
return;
}
delay(1000);
// get value
Serial.print("number: ");
Serial.println(Firebase.getFloat("number"));
delay(1000);
// remove value
Firebase.remove("number");
delay(1000);
// set string value
Firebase.setString("message", "hello world");
// handle error
if (Firebase.failed()) {
Serial.print("setting /message failed:");
Serial.println(Firebase.error());
return;
}
delay(1000);
// set bool value
Firebase.setBool("truth", false);
// handle error
if (Firebase.failed()) {
Serial.print("setting /truth failed:");
Serial.println(Firebase.error());
return;
}
delay(1000);
// append a new value to /logs
String name = Firebase.pushInt("logs", n++);
// handle error
if (Firebase.failed()) {
Serial.print("pushing /logs failed:");
Serial.println(Firebase.error());
return;
}
Serial.print("pushed: /logs/");
Serial.println(name);
delay(1000);
}

沒有留言:

張貼留言

WOKWI DHT22 & LED , Node-Red + SQLite database

 WOKWI DHT22 & LED , Node-Red + SQLite database Node-Red程式 [{"id":"6f0240353e534bbd","type":"comment&...