Created
May 1, 2017 05:25
-
-
Save hocarm/fc2b3151eada80579a694877a7b88401 to your computer and use it in GitHub Desktop.
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
// | |
// 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> | |
// Cấu hình. | |
#define FIREBASE_HOST "hocarm1.firebaseio.com" //Đổi lại nhé | |
#define FIREBASE_AUTH "" | |
#define WIFI_SSID "ten_wifi" | |
#define WIFI_PASSWORD "mat_khau" | |
void setup() { | |
Serial.begin(9600); | |
// Két nối 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 giá trị lưu vào db | |
Firebase.setFloat("number", 42.0); | |
// Kiểm tra lỗi | |
if (Firebase.failed()) { | |
Serial.print("setting /number failed:"); | |
Serial.println(Firebase.error()); | |
return; | |
} | |
delay(1000); | |
// Cập nhật giá trị | |
Firebase.setFloat("number", 43.0); | |
// Kiểm tra lỗi | |
if (Firebase.failed()) { | |
Serial.print("setting /number failed:"); | |
Serial.println(Firebase.error()); | |
return; | |
} | |
delay(1000); | |
// Lấy giá trị | |
Serial.print("number: "); | |
Serial.println(Firebase.getFloat("number")); | |
delay(1000); | |
// Xóa giá trị | |
Firebase.remove("number"); | |
delay(1000); | |
// Thêm chuỗi | |
Firebase.setString("message", "hello world"); | |
// Kiểm tra lỗi | |
if (Firebase.failed()) { | |
Serial.print("setting /message failed:"); | |
Serial.println(Firebase.error()); | |
return; | |
} | |
delay(1000); | |
// Thêm giá trị bool | |
Firebase.setBool("truth", false); | |
// Kiểm tra lỗi | |
if (Firebase.failed()) { | |
Serial.print("setting /truth failed:"); | |
Serial.println(Firebase.error()); | |
return; | |
} | |
delay(1000); | |
// Lưu log | |
String name = Firebase.pushInt("logs", n++); | |
// Kiểm tra lỗi | |
if (Firebase.failed()) { | |
Serial.print("pushing /logs failed:"); | |
Serial.println(Firebase.error()); | |
return; | |
} | |
Serial.print("pushed: /logs/"); | |
Serial.println(name); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment