Last active
April 26, 2024 13:02
-
-
Save TrickSumo/2f16c122b2f59c1e7b0846514dd945cd 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
/* | |
Created by:- Rishi Tiwari | |
Website:- TrickSumo.com | |
Video Tutorial:- https://youtu.be/nLzC0-VaqDs | |
Libraries used:- | |
https://github.com/mobizt/Firebase-ESP8266/ | |
*/ | |
#include <ESP8266WiFi.h> | |
#include <FirebaseESP8266.h> | |
#define FIREBASE_HOST "test.firebaseio.com" //Your Firebase Project URL goes here without "http:" , "\" and "/" | |
#define FIREBASE_AUTH "83Z6iVjTlxjfhjsgjhwerhwqweZxrTXiy0C9" //Your Firebase Database Secret goes here | |
#define WIFI_SSID "Wifiname-here" //WiFi SSID to which you want NodeMCU to connect | |
#define WIFI_PASSWORD "Wifipassword-here" //Password of your wifi network | |
// Declare the Firebase Data object in the global scope | |
FirebaseData firebaseData; | |
// Declare global variable to store value | |
int val=0; | |
void setup() { | |
Serial.begin(115200); // Select the same baud rate if you want to see the datas on Serial Monitor | |
Serial.println("Serial communication started\n\n"); | |
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); //try to connect with wifi | |
Serial.print("Connecting to "); | |
Serial.print(WIFI_SSID); | |
while (WiFi.status() != WL_CONNECTED) { | |
Serial.print("."); | |
delay(500); | |
} | |
Serial.println(); | |
Serial.print("Connected to "); | |
Serial.println(WIFI_SSID); | |
Serial.print("IP Address is : "); | |
Serial.println(WiFi.localIP()); //print local IP address | |
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); // connect to firebase | |
Firebase.reconnectWiFi(true); | |
delay(1000); | |
} | |
void loop() { | |
// Firebase Error Handling And Writing Data At Specifed Path************************************************ | |
if (Firebase.setInt(firebaseData, "/data", val)) { // On successful Write operation, function returns 1 | |
Serial.println("Value Uploaded Successfully"); | |
Serial.print("Val = "); | |
Serial.println(val); | |
Serial.println("\n"); | |
val++; | |
delay(1000); | |
} | |
else { | |
Serial.println(firebaseData.errorReason()); | |
} | |
} | |
/* NOTE: | |
* To upload value, command is ===> Firebase.setInt(firebaseData, "path", variable); | |
* Example ===> Firebase.setInt(firebaseData, "/data", val); | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#include <FirebaseESP8266.h>
#include <ESP8266WiFi.h>
const char* ssid = "ASLAB 2024";
const char* password = "aslabfkom";
FirebaseData firebaseData;
int led = D6;
void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
digitalWrite(led, LOW); //nilai awal relay akan off
WifiConnect();
Firebase.begin("https://kendali-led-267ca-default-rtdb.asia-southeast1.firebasedatabase.app/", "3rq1K5m7xwS32bjFTTngTcQ7hgtaPhS6fx0cLTCo");
//Firebase.begin("firebase host", "firebase auth database");
}
void WifiConnect() {
WiFi.begin(ssid, password);
//memulai menghubungkan ke wifi router
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print("."); //status saat mengkoneksikan
}
Serial.println("Sukses terkoneksi wifi!");
Serial.println("IP Address:"); //alamat ip lokal
Serial.println(WiFi.localIP());
}
void loop() {
if (Firebase.getString(firebaseData, "/Led")) {
if (firebaseData.dataType() == "string")
{
String Status = firebaseData.stringData();
if (Status == "ON") {
Serial.println("Led Menyala");
digitalWrite(led, HIGH); }
else if (Status == "OFF") {
Serial.println("led Mati");
digitalWrite(led, LOW);
}
else {Serial.println("Silahkan hanya isi dengan ON atau OFF");}
}
}
}
Compilation error: cannot convert 'const char [55]' to 'FirebaseConfig*' {aka 'firebase_cfg_t*'}