Skip to content

Instantly share code, notes, and snippets.

<?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"
<?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"
#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
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;
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");
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);
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")) {
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);
@sidishere
sidishere / r2
Created December 24, 2019 11:27
final
DatabaseReference smartAC = myRef.child("smartAC").child("status");
final
DatabaseReference smartBulb = myRef.child("smartBulb").child("status");
@sidishere
sidishere / r1
Created December 24, 2019 11:26
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference();