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
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:paddingLeft="16dp" | |
android:paddingRight="16dp" | |
android:orientation="vertical" > | |
<EditText | |
android:id="@+id/name" | |
android:layout_width="match_parent" |
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
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:paddingLeft="16dp" | |
android:paddingRight="16dp" > | |
<TextView | |
android:id="@+id/view1" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" |
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
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino | |
#include <FirebaseArduino.h> //needed for Wifimanager library | |
#include <DNSServer.h> | |
#include <ESP8266WebServer.h> | |
#include <WiFiManager.h> //led init | |
#define RED_LED D0 | |
#define GREEN_LED D1 | |
#define BLUE_LED D2 //Dataabase init | |
#define FIREBASE_HOST "YOUR HOST ID" //link of api | |
#define FIREBASE_AUTH "YOUR AUTH ID" //database secret |
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
import androidx.appcompat.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.widget.CompoundButton; | |
import android.widget.Switch; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
import com.google.firebase.database.DataSnapshot; |
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
s4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() | |
{ | |
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) | |
{ | |
if (!s4.isChecked()) | |
{ | |
s1.setChecked(false); | |
s2.setChecked(false); | |
s3.setChecked(false); | |
smartAC.setValue("OFF"); |
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
s1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | |
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |
if (s4.isChecked()) | |
if (s1.isChecked()) | |
smartAC.setValue(("ON")); | |
else | |
smartAC.setValue("OFF"); | |
else | |
if(s1.isChecked()){ | |
s1.setChecked(false); |
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
smartAC.addValueEventListener(new ValueEventListener() { | |
boolean firstTime=true; | |
@Override | |
public void onDataChange(DataSnapshot dataSnapshot) { | |
// This method is called once with the initial value and again | |
// whenever data at this location is updated. | |
String value = dataSnapshot.getValue(String.class); | |
textView1.setText("smartAC " + value); | |
if(firstTime) { | |
if (value.equals( "ON")) { |
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
TextView textView1, textView2, textView3, masterSwitchSwitch s1, s2, s3, s4; | |
s1 = (Switch) findViewById(R.id.button1); | |
s2 = (Switch) findViewById(R.id.button2); | |
s3 = (Switch) findViewById(R.id.button3); | |
s4 = (Switch) findViewById(R.id.button4); | |
textView1 = (TextView) findViewById(R.id.textView1); | |
textView2 = (TextView) findViewById(R.id.textView2); | |
textView3 = (TextView) findViewById(R.id.textView3); | |
masterSwitch = (TextView) findViewById(R.id.master_switch); |
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
final | |
DatabaseReference smartAC = myRef.child("smartAC").child("status"); | |
final | |
DatabaseReference smartBulb = myRef.child("smartBulb").child("status"); | |
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
FirebaseDatabase database = FirebaseDatabase.getInstance(); | |
DatabaseReference myRef = database.getReference(); |