/*
Make sure your Firebase project's '.read' and '.write' rules are set to 'true'.
Ignoring this will prevent the MCU from communicating with the database.
For more details- https://github.com/Rupakpoddar/ESP32Firebase
*/
#include <ESP32Firebase.h>
#define _SSID "Professor Moriarty" // Your WiFi SSID
#define _PASSWORD "who are you?" // Your WiFi Password
#define REFERENCE_URL "https://led-with-app-default-rtdb.firebaseio.com" // Your Firebase project reference url
#define LED_PIN 13
#define LED_PIN1 12
Firebase firebase(REFERENCE_URL);
void setup() {
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
pinMode(LED_PIN1, OUTPUT);
digitalWrite(LED_PIN, HIGH);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(1000);
// Connect to WiFi
Serial.println();
Serial.println();
Serial.print("Connecting to: ");
Serial.println(_SSID);
//WiFi.begin(_SSID, _PASSWORD);
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print("-");
}
Serial.println("");
Serial.println("WiFi Connected");
// Print the IP address
Serial.print("IP Address: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
//================================================================//
//================================================================//
// Example of getting an int.
String data2 = firebase.getString("/APP/LED_STATE");
Serial.print("Received Int:");
Serial.print(data2);
digitalWrite(LED_PIN1, HIGH);
}
void loop() {
char ledstate = firebase.getchar("/APP/LED_STATE");
int state = int(ledstate);
Serial.println("Received Int:");
Serial.print(ledstate);
Serial.print(state);
if(state == 1){
//Serial.print("ON");
digitalWrite(LED_PIN, HIGH);
}else{
//Serial.print("OFF");
digitalWrite(LED_PIN, LOW);
}
delay(0); // Adjust delay as needed
}
esp:0
esp:1
esp:2
esp:3
esp:4
esp:5
esp:6
esp:7
esp:8
esp:9
esp:10
esp:11
esp:12
esp:13
esp:14
esp:15
esp:16
esp:17
esp:18
esp:19
esp:20
esp:21
esp:26
esp:33
esp:34
esp:35
esp:36
esp:37
esp:38
esp:39
esp:40
esp:41
esp:42
esp:45
esp:46
esp:3V3
esp:5V
esp:GND.1
esp:TX
esp:RX
esp:RST
esp:GND.2
led1:A
led1:C
led2:A
led2:C