#include <WiFi.h>
#include <FirebaseESP32.h>
#include <addons/TokenHelper.h>
//wifi configuration
#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASSWORD ""
#define API_KEY "AIzaSyDfQxDuLEN1gbxz08RxMKbzrY8eQGBnTCY"
#define DATABASE_URL "https://ledcontrol-f1776-default-rtdb.asia-southeast1.firebasedatabase.app/"
#define USER_EMAIL "[email protected]"
#define USER_PASSWORD "123456"
//define firebse data Object
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
void setup() {
//put your setup code here, to run once:
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
config.api_key = API_KEY;
auth.user.email = USER_EMAIL;
auth.user.password = USER_PASSWORD;
config.database_url = DATABASE_URL;
config.token_status_callback = tokenStatusCallback;
Firebase.begin(&config, &auth);
Firebase.reconnectWiFi(true);
//ESP32 Connect Bulb
pinMode(14, OUTPUT);
}
String read_data = "";
void loop() {
if(Firebase.getString(fbdo, "/status")){
if(fbdo.dataType() == "string"){
read_data = fbdo.stringData();
Serial.print("Data received: ");
Serial.println(read_data);
}
//ESP32 Connect Bulb
if(read_data == "ON"){
digitalWrite(14, HIGH);
}else if(read_data == "BLINK"){
digitalWrite(14, HIGH);
delay(500);
digitalWrite(14, LOW);
delay(500);
}else{
digitalWrite(14, LOW);
}
}
}
/*
// Car parking using Ultra sonic sensor
https://wokwi.com/projects/376360643701796865
//buzzer Pir rasberry pi
https://wokwi.com/projects/385316804502238209
//rgb,ssd13006,esp32
https://wokwi.com/projects/385253070387615745
//led in stm32
https://wokwi.com/projects/385251964747975681
//motion sensor in raspberry pi
https://wokwi.com/projects/385251553806806017
//lcd panel showing the dht22 sensor(temperature,humidity) in raspberry pi internt copy
https://wokwi.com/projects/385250954977587201
//lcd panel showing the dht22 sensor(temperature,humidity) sir coding
https://wokwi.com/projects/385250904718288897
//buzzer connect with 3 lds in raspberry pi
https://wokwi.com/projects/385248448449744897
//3 leds in raspberry pi
https://wokwi.com/projects/385248321966305281
//buzzer connect with dht22(tem,hum) in ultrasonic sensor in esp32
https://wokwi.com/projects/385246798071624705
//only the ultrasonic sensor and dht22 in esp32
https://wokwi.com/projects/385244928758194177
//esp32 with ultrasonic sensor only
https://wokwi.com/projects/385244652218258433
//esp32 and dht22 temperatures and humidity sensor
https://wokwi.com/projects/385244447167106049
//ifi connect using esp32
https://wokwi.com/projects/385243958598790145
//raffic lights in esp32
https://wokwi.com/projects/385243623127846913
//wokwi connect to firebase on off LED
https://wokwi.com/projects/385271968137135105
//Android Application Code
package com.example.examapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.google.firebase.Firebase;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class MainActivity extends AppCompatActivity {
Button button,button1,button2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
DatabaseReference dbtest = firebaseDatabase.getReference("status");
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dbtest.setValue("ON");
}
});
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dbtest.setValue("BLINK");
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dbtest.setValue("OFF");
}
});
}
}
=====mvi===
***mobile application fire base connct***
first add two buttons and finish that design...
build gradle module app application id copy and paste in firebase app creating....
go to android studio file then to sync project with gradle files....
go to gralde in right side then task then to android then to signingreport....
If not come check the setting experimental untick the 1 one….
SHA1 copy and paste in the firebase SHA1...
download json file...copy file...go to project click on app..right click on app..paste the file....
copy 1st code set....paste under the build gradle project
copy 2nd code set..1st id and the 1st dependcny....paste under the build gradle module
Tools firebase Realtimedatabase...copy and paste the code under mainactivity.java
in firbase create database....status 1
change project module...4.3.14... make comment as the 3rd dependency...
Change path:message into path:status
run app and click the buttons...data will change in firebase
package com.example.myapplicationnew;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class MainActivity extends AppCompatActivity {
Button button,button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
button1 = (Button) findViewById(R.id.button2);
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("status");
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
myRef.setValue(1);
}
});
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
myRef.setValue(100);
}
});
}
}
*/