Components and supplies
ESP8266 ESP-01
Arduino UNO
Slide Switch, SPDT-CO
Power Relay, SPDT
Test Accessory, AC Power Adaptor
Tools and machines
Router
Project description
Code
control.html
html
1<!DOCTYPE html> 2<html lang="en"> 3 4<head> 5 <meta charset="UTF-8"> 6 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 7 <meta http-equiv="X-UA-Compatible" content="ie=edge"> 8 <link rel="stylesheet" href="../bootstrap-4.3.1/dist/css/bootstrap.min.css"> 9 <script src="../bootstrap-4.3.1/dist/js/jquery.min.js"></script> 10 <script src="script.js"></script> 11 <title>IoT Home Automation</title> 12</head> 13 14<body> 15 <nav class="navbar navbar-expand-md bg-dark navbar-dark"> 16 <a class="navbar-brand" href="home.html">IoT Home Automation</a> 17 <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar"> 18 <span class="navbar-toggler-icon"></span> 19 </button> 20 <div class="collapse navbar-collapse" id="collapsibleNavbar"> 21 <ul class="navbar-nav"> 22 <!-- <li class="nav-item"> 23 <a class="nav-link" href="dashboard.html">Dashboard</a> 24 </li> --> 25 <li class="nav-item"> 26 <a class="nav-link" href="control.html">Controller</a> 27 </li> 28 </ul> 29 </div> 30 </nav> 31 <div class="container"> 32 <h5 style="padding-top: 15px;" class="h5 text-left">Home/Controller</h5><hr> 33 34 <div class="row"> 35 <div class=" col-sm-12 col-md-12 text-center"> 36 <h3>Turn ON/OFF</h3> 37 </div> 38 <div style="padding: 20px;" class="col-6 col-sm-6"> 39 <h2 style="padding-bottom: 50px;" class="text-center">AC</h2> 40 <button id="60" class="get_id btn btn-lg btn-block btn-primary" onclick="sendRequest(this.id)">ON/OFF</button> 41 </div> 42 <div style="padding: 20px;" class="col-6 col-sm-6"> 43 <h2 style="padding-bottom: 50px;" class="text-center">Light 1</h2> 44 <button id="70" class="get_id btn btn-lg btn-block btn-primary" onclick="sendRequest(this.id)">ON/OFF</button> 45 </div> 46 <div style="padding: 20px;" class="col-6 col-sm-6"> 47 <h2 style="padding-bottom: 50px;" class="text-center">Light 2</h2> 48 <button id="80" class="get_id btn btn-lg btn-block btn-primary" onclick="sendRequest(this.id)">ON/OFF</button> 49 </div> 50 <div style="padding: 20px;" class="col-6 col-sm-6"> 51 <h2 style="padding-bottom: 50px;" class="text-center">Socket</h2> 52 <button id="90" class="get_id btn btn-lg btn-block btn-primary" onclick="sendRequest(this.id)">ON/OFF</button> 53 </div> 54 </div> 55 </div> 56 <script src="../bootstrap-4.3.1/dist/js/bootstrap.min.js"></script> 57</body> 58 59</html>
Arduino Code
arduino
1#include <SoftwareSerial.h> 2 3SoftwareSerial esp8266(2,3); 4 5#define serialCommunicationSpeed 9600 6#define DEBUG true 7//#define STATUS = 0 8 9//int checkStOne = 0; 10//int checkStTwo = 0; 11//int checkStThree = 1; 12//int checkStFour = 1; 13 14 15//int detectorOne = 9; 16//int detectorTwo = 10; 17//int detectorThree = 11; 18//int detectorFour = 12; 19 20int lightOne = 6; 21int lightTwo = 7; 22int lightThree = 8; 23int lightFour = 9; 24 25int indicator = 13; 26 27 28void setup() 29{ 30// pinMode(detectorOne,INPUT); 31// pinMode(detectorTwo,INPUT); 32// pinMode(detectorThree,INPUT); 33// pinMode(detectorFour,INPUT); 34 35 36// digitalWrite(detectorOne,LOW); 37// digitalWrite(detectorTwo,LOW); 38// digitalWrite(detectorThree,LOW); 39// digitalWrite(detectorFour,LOW); 40 41 pinMode(lightOne,OUTPUT); 42 pinMode(lightTwo,OUTPUT); 43 pinMode(lightThree,OUTPUT); 44 pinMode(lightFour,OUTPUT); 45 46 pinMode(indicator,OUTPUT); 47 48 49 digitalWrite(lightOne,HIGH); 50 digitalWrite(lightTwo,HIGH); 51 digitalWrite(lightThree,HIGH); 52 digitalWrite(lightFour,HIGH); 53 54 digitalWrite(indicator,HIGH); 55 56 57 Serial.begin(serialCommunicationSpeed); 58 esp8266.begin(serialCommunicationSpeed); 59 60 InitWifiModule(); 61// checkCircuitStatus(); 62 63 digitalWrite(indicator,LOW); 64 delay(200); 65} 66void loop() 67{ 68 if(esp8266.available()) 69 { 70// Serial.println("i got something"); 71 delay(500); 72 if(esp8266.find("+IPD,")) 73 { 74 delay(500); 75 int connectionId = esp8266.read()-48; 76 esp8266.find("pin="); 77 int pinNumber = (esp8266.read()-48); 78// pinNumber = pinNumber + (esp8266.read()-48); 79 int statusLed =(esp8266.read()-48); 80 delay(500); 81 String responseData = "AT+CIPSEND="; 82 responseData += connectionId; 83 responseData += ",1\ \ 84"; 85 Serial.println(responseData); 86 sendData(responseData , 800, DEBUG); 87 delay(100); 88 sendData(pinNumber+"\ \ 89",500,DEBUG); 90 delay(100); 91 digitalWrite(pinNumber, statusLed); 92 String closeCommand = "AT+CIPCLOSE="; 93 closeCommand+=connectionId; 94 closeCommand+="\ \ 95"; 96 sendData(closeCommand,500,DEBUG); 97 } 98 } 99// if(digitalRead(detectorOne) != checkStOne || digitalRead(detectorTwo) != checkStTwo || digitalRead(detectorThree) != checkStThree || digitalRead(detectorFour) != checkStFour){ 100// Serial.println("i am inside loop"); 101// if(digitalRead(detectorOne) != checkStOne){ 102// checkStOne = digitalRead(detectorOne); 103// sendStToDatabase(detectorOne, checkStOne); 104// } 105// if(digitalRead(detectorTwo) != checkStTwo){ 106// checkStTwo = digitalRead(detectorTwo); 107// sendStToDatabase(detectorTwo , checkStTwo); 108// } 109// if(digitalRead(detectorThree) != checkStThree){ 110// checkStThree = digitalRead(detectorThree); 111// sendStToDatabase(detectorThree , checkStThree); 112// } 113// if(digitalRead(detectorFour) != checkStFour){ 114// checkStFour = digitalRead(detectorFour); 115// sendStToDatabase(detectorFour , checkStFour); 116// } 117// 118// } 119// else{ 120// Serial.println("I AM NOT OK, ok?"); 121// Serial.println(digitalRead(detectorTwo)); 122// delay(1000); 123// } 124} 125 126 127// int changeOccured(){ 128// int static StatusOfDetectorOne = 0; 129// int static StatusOfDetectoTwo = 0; 130// int static StatusOfDetectorThree = 0; 131// int static StatusOfDetectorFour = 0; 132// if(digitalRead(detectorOne) != StatusOfDetectorOne){ 133// StatusOfDetectorOne = digitalRead(detectorOne); 134// } 135// if(digitalRead(detectorTwo) != StatusOfDetectoTwo){ 136// StatusOfDetectoTwo = digitalRead(detectorTwo); 137// } 138// if(digitalRead(detectorThree) != StatusOfDetectorThree){ 139// StatusOfDetectorThree = digitalRead(detectorThree); 140// } 141// if(digitalRead(detectorFour) != StatusOfDetectorFour){ 142// StatusOfDetectorFour = digitalRead(detectorFour); 143// } 144// 145// } 146 147void sendData(String command, const int timeout, boolean debug){ 148 String response = ""; 149 esp8266.print(command); 150 long int time = millis(); 151 while( (time+timeout) > millis()){ 152 while(esp8266.available()){ 153 char c = esp8266.read(); 154 response+=c; 155 } 156 } 157 if(DEBUG){ 158 Serial.print(response); 159 } 160// return response; 161} 162void InitWifiModule(){ 163 sendData("AT+RST\ \ 164", 1000, DEBUG); 165 delay(1000); 166 sendData("AT+CWMODE=1\ \ 167", 1000, DEBUG); 168 delay (500); 169 sendData("AT+CWJAP=\\"your SSID\\",\\"password\\"\ \ 170", 10000, DEBUG); 171 delay (1000); 172 sendData("AT+CIFSR\ \ 173", 1000, DEBUG); 174 delay (1000); 175 sendData("AT+CIPMUX=1\ \ 176", 500, DEBUG); 177 delay (1000); 178 sendData("AT+CIPSERVER=1,80\ \ 179", 1000, DEBUG); 180 delay(500); 181} 182//void checkCircuitStatus(){ 183// if(digitalRead(detectorOne)){ 184// checkStOne = 1; 185// sendStToDatabase(detectorOne, checkStOne); 186// } 187// if(digitalRead(detectorTwo)){ 188// checkStTwo = 1; 189// sendStToDatabase(detectorTwo , checkStTwo); 190// } 191// if(digitalRead(detectorThree)){ 192// checkStThree = 1; 193// sendStToDatabase(detectorThree , checkStThree); 194// } 195// if(digitalRead(detectorFour)){ 196// checkStFour = 1; 197// sendStToDatabase(detectorFour , checkStFour); 198// } 199//} 200//void sendStToDatabase(int detector, int checkSt){ 201// Serial.println("i am here"); 202// Serial.println(detector); 203// Serial.println(checkSt); 204// 205//} 206
Arduino Code
arduino
1#include <SoftwareSerial.h> 2 3SoftwareSerial esp8266(2,3); 4 5#define serialCommunicationSpeed 9600 6#define DEBUG true 7//#define STATUS = 0 8 9//int checkStOne = 0; 10//int checkStTwo = 0; 11//int checkStThree = 1; 12//int checkStFour = 1; 13 14 15//int detectorOne = 9; 16//int detectorTwo = 10; 17//int detectorThree = 11; 18//int detectorFour = 12; 19 20int lightOne = 6; 21int lightTwo = 7; 22int lightThree = 8; 23int lightFour = 9; 24 25int indicator = 13; 26 27 28void setup() 29{ 30// pinMode(detectorOne,INPUT); 31// pinMode(detectorTwo,INPUT); 32// pinMode(detectorThree,INPUT); 33// pinMode(detectorFour,INPUT); 34 35 36// digitalWrite(detectorOne,LOW); 37// digitalWrite(detectorTwo,LOW); 38// digitalWrite(detectorThree,LOW); 39// digitalWrite(detectorFour,LOW); 40 41 pinMode(lightOne,OUTPUT); 42 pinMode(lightTwo,OUTPUT); 43 pinMode(lightThree,OUTPUT); 44 pinMode(lightFour,OUTPUT); 45 46 pinMode(indicator,OUTPUT); 47 48 49 digitalWrite(lightOne,HIGH); 50 digitalWrite(lightTwo,HIGH); 51 digitalWrite(lightThree,HIGH); 52 digitalWrite(lightFour,HIGH); 53 54 digitalWrite(indicator,HIGH); 55 56 57 Serial.begin(serialCommunicationSpeed); 58 esp8266.begin(serialCommunicationSpeed); 59 60 InitWifiModule(); 61// checkCircuitStatus(); 62 63 digitalWrite(indicator,LOW); 64 delay(200); 65} 66void loop() 67{ 68 if(esp8266.available()) 69 { 70// Serial.println("i got something"); 71 delay(500); 72 if(esp8266.find("+IPD,")) 73 { 74 delay(500); 75 int connectionId = esp8266.read()-48; 76 esp8266.find("pin="); 77 int pinNumber = (esp8266.read()-48); 78// pinNumber = pinNumber + (esp8266.read()-48); 79 int statusLed =(esp8266.read()-48); 80 delay(500); 81 String responseData = "AT+CIPSEND="; 82 responseData += connectionId; 83 responseData += ",1\ \ 84"; 85 Serial.println(responseData); 86 sendData(responseData , 800, DEBUG); 87 delay(100); 88 sendData(pinNumber+"\ \ 89",500,DEBUG); 90 delay(100); 91 digitalWrite(pinNumber, statusLed); 92 String closeCommand = "AT+CIPCLOSE="; 93 closeCommand+=connectionId; 94 closeCommand+="\ \ 95"; 96 sendData(closeCommand,500,DEBUG); 97 } 98 } 99// if(digitalRead(detectorOne) != checkStOne || digitalRead(detectorTwo) != checkStTwo || digitalRead(detectorThree) != checkStThree || digitalRead(detectorFour) != checkStFour){ 100// Serial.println("i am inside loop"); 101// if(digitalRead(detectorOne) != checkStOne){ 102// checkStOne = digitalRead(detectorOne); 103// sendStToDatabase(detectorOne, checkStOne); 104// } 105// if(digitalRead(detectorTwo) != checkStTwo){ 106// checkStTwo = digitalRead(detectorTwo); 107// sendStToDatabase(detectorTwo , checkStTwo); 108// } 109// if(digitalRead(detectorThree) != checkStThree){ 110// checkStThree = digitalRead(detectorThree); 111// sendStToDatabase(detectorThree , checkStThree); 112// } 113// if(digitalRead(detectorFour) != checkStFour){ 114// checkStFour = digitalRead(detectorFour); 115// sendStToDatabase(detectorFour , checkStFour); 116// } 117// 118// } 119// else{ 120// Serial.println("I AM NOT OK, ok?"); 121// Serial.println(digitalRead(detectorTwo)); 122// delay(1000); 123// } 124} 125 126 127// int changeOccured(){ 128// int static StatusOfDetectorOne = 0; 129// int static StatusOfDetectoTwo = 0; 130// int static StatusOfDetectorThree = 0; 131// int static StatusOfDetectorFour = 0; 132// if(digitalRead(detectorOne) != StatusOfDetectorOne){ 133// StatusOfDetectorOne = digitalRead(detectorOne); 134// } 135// if(digitalRead(detectorTwo) != StatusOfDetectoTwo){ 136// StatusOfDetectoTwo = digitalRead(detectorTwo); 137// } 138// if(digitalRead(detectorThree) != StatusOfDetectorThree){ 139// StatusOfDetectorThree = digitalRead(detectorThree); 140// } 141// if(digitalRead(detectorFour) != StatusOfDetectorFour){ 142// StatusOfDetectorFour = digitalRead(detectorFour); 143// } 144// 145// } 146 147void sendData(String command, const int timeout, boolean debug){ 148 String response = ""; 149 esp8266.print(command); 150 long int time = millis(); 151 while( (time+timeout) > millis()){ 152 while(esp8266.available()){ 153 char c = esp8266.read(); 154 response+=c; 155 } 156 } 157 if(DEBUG){ 158 Serial.print(response); 159 } 160// return response; 161} 162void InitWifiModule(){ 163 sendData("AT+RST\ \ 164", 1000, DEBUG); 165 delay(1000); 166 sendData("AT+CWMODE=1\ \ 167", 1000, DEBUG); 168 delay (500); 169 sendData("AT+CWJAP=\\"your SSID\\",\\"password\\"\ \ 170", 10000, DEBUG); 171 delay (1000); 172 sendData("AT+CIFSR\ \ 173", 1000, DEBUG); 174 delay (1000); 175 sendData("AT+CIPMUX=1\ \ 176", 500, DEBUG); 177 delay (1000); 178 sendData("AT+CIPSERVER=1,80\ \ 179", 1000, DEBUG); 180 delay(500); 181} 182//void checkCircuitStatus(){ 183// if(digitalRead(detectorOne)){ 184// checkStOne = 1; 185// sendStToDatabase(detectorOne, checkStOne); 186// } 187// if(digitalRead(detectorTwo)){ 188// checkStTwo = 1; 189// sendStToDatabase(detectorTwo , checkStTwo); 190// } 191// if(digitalRead(detectorThree)){ 192// checkStThree = 1; 193// sendStToDatabase(detectorThree , checkStThree); 194// } 195// if(digitalRead(detectorFour)){ 196// checkStFour = 1; 197// sendStToDatabase(detectorFour , checkStFour); 198// } 199//} 200//void sendStToDatabase(int detector, int checkSt){ 201// Serial.println("i am here"); 202// Serial.println(detector); 203// Serial.println(checkSt); 204// 205//} 206
checkConnection.js
javascript
1function checkConnection(){ 2 // var x = document.cookie 3 // if(!x){ 4 // var name = prompt("Enter your name.") 5 // if(name == null || name == "" || name.trim().length == 0){ 6 // document.getElementById("demo").innerHTML = "ERROR!! Reload the page."; 7 // return; 8 // } 9 // else{ 10 // document.cookie = "name="+name; 11 // var xhttp = new XMLHttpRequest(); 12 // xhttp.onreadystatechange = function(){ 13 // if (this.readyState == 4 && this.status == 200){ 14 // document.getElementById("demo").innerHTML = xhttp.responseText; 15 // } 16 // }; 17 // xhttp.open("GET","http://127.0.0.1/IoT/server/checkConnection.php",true); 18 // xhttp.send(); 19 // } 20 // } 21 window.location.href = "/IoT/client/home.html"; 22 23}
script.js
javascript
1function initApp() { 2 // var xhttp = new XMLHttpRequest(); 3 // xhttp.onreadystatechange = function() { 4 // if (this.readyState == 4 && this.status == 200) { 5 // // console.log(this.responseText); 6 // } 7 // }; 8 // xhttp.open("GET", "../server/server.php", true); 9 // xhttp.send(); 10} 11function sendRequest(id) { 12 // var res; 13 // var paramg; 14 document.getElementById(id).classList.remove('btn-primary'); 15 document.getElementById(id).classList.add('btn-warning'); 16 document.getElementsByClassName("get_id")[0].disabled = true; 17 document.getElementsByClassName("get_id")[1].disabled = true; 18 document.getElementsByClassName("get_id")[2].disabled = true; 19 document.getElementsByClassName("get_id")[3].disabled = true; 20 var xhttp = new XMLHttpRequest(); 21 // if(this.readyState == 0){ 22 // console.log("0: request not initialized"); 23 // } 24 // if(this.readyState == 1){ 25 // console.log("1: server connection established"); 26 // } 27 // if(this.readyState == 2){ 28 // console.log("2: request received"); 29 // } 30 // if(this.readyState == 3){ 31 // console.log("3: processing request"); 32 // } 33 // if(this.readyState == 4){ 34 // console.log("4: request finished and response is ready"); 35 // } 36 // res = this.responseText; 37 // if (this.readyStatus == 4) { 38 // alert(res); 39 // } 40 // } 41 42 xhttp.open("GET", "http://192.168.1.100:80?pin=" + id, true); 43 // xhttp.setRequestHeader("Access-Control-Allow-Headers","*"); 44 // xhttp.setRequestHeader("Origin", "*"); 45 // xhttp.setRequestHeader("Access-Control-Allow-Methods", "GET, POST,PUT"); 46 // xhttp.setRequestHeader('Access-Control-Allow-Credential','true'); 47 xhttp.send(); 48 // alert('Sending Request to server!!'); 49 setTimeout(function(){ 50 document.getElementById(id).classList.remove('btn-warning'); 51 document.getElementById(id).classList.add('btn-primary'); 52 document.getElementsByClassName("get_id")[0].disabled = false; 53 document.getElementsByClassName("get_id")[1].disabled = false; 54 document.getElementsByClassName("get_id")[2].disabled = false; 55 document.getElementsByClassName("get_id")[3].disabled = false; 56 if (id % 2 == 0) { 57 document.getElementById(id).id = parseInt(id) + 1; 58 } 59 if (id % 2 != 0) { 60 document.getElementById(id).id = parseInt(id) - 1; 61 } 62 63 },4000); 64 return; 65 66} 67// function sendToArduino(id) { 68 69// var xhttp = new XMLHttpRequest() 70// xhttp.open("GET", "http://10.10.5.101:80/?pin=" + id, false); 71// xhttp.send(); 72// }
home.html
html
1<!DOCTYPE html> 2<html lang="en"> 3 4<head> 5 <meta charset="UTF-8"> 6 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 7 <meta http-equiv="X-UA-Compatible" content="ie=edge"> 8 <link rel="stylesheet" href="../bootstrap-4.3.1/dist/css/bootstrap.min.css"> 9 <script src="../bootstrap-4.3.1/dist/js/jquery.min.js"></script> 10 <script src="script.js"></script> 11 12 <title>IoT Home Automation</title> 13</head> 14 15<body onload="initApp()"> 16 <div class=""> 17 <nav class="navbar navbar-expand-md bg-dark navbar-dark"> 18 <!-- Brand --> 19 <a class="navbar-brand" href="home.html">IoT Home Automation</a> 20 21 <!-- Toggler/collapsibe Button --> 22 <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar"> 23 <span class="navbar-toggler-icon"></span> 24 </button> 25 26 <!-- Navbar links --> 27 <div class="collapse navbar-collapse" id="collapsibleNavbar"> 28 <ul class="navbar-nav"> 29 <!-- <li class="nav-item"> 30 <a class="nav-link" href="dashboard.html">Dashboard</a> 31 </li> 32 <li class="nav-item"> --> 33 <a class="nav-link" href="control.html">Controller</a> 34 </li> 35 </ul> 36 </div> 37 </nav> 38 <br> 39 <img src="img/khec.png" style="padding-top:20px; padding-bottom: 50px;" class="img img-fluid rounded mx-auto d-block" 40 alt="Khwopa Engineering College"> 41 <div class="col"> 42 <h3 class="text-center">Welcome to IoT Home Automation</h3> 43 </div> 44 <div style="padding-top:20px;" class="container col"> 45 <ulc class="list-group"> 46 <li class="list-group-item active">Team Members:</li> 47 <li class="font-weight-bold list-group-item d-flex justify-content-between align-items-center">Prabin Raj Upreti 48 <span class="badge badge-primary badge-pill">750421</span> 49 </li> 50 <li class="list-group-item d-flex justify-content-between align-items-center">Erina Sharma 51 <span class="badge badge-primary badge-pill">750411</span></li> 52 <li class="list-group-item d-flex justify-content-between align-items-center">Parash Sapkota 53 <span class="badge badge-primary badge-pill">750419</span></li> 54 <li class="list-group-item d-flex justify-content-between align-items-center">Sajan Duwal 55 <span class="badge badge-primary badge-pill">750425</span></li> 56 </ul> 57 </div> 58 <script src="../bootstrap-4.3.1/dist/js/bootstrap.min.js"></script> 59</body> 60 61</html>
home.html
html
1<!DOCTYPE html> 2<html lang="en"> 3 4<head> 5 <meta charset="UTF-8"> 6 7 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 8 9 <meta http-equiv="X-UA-Compatible" content="ie=edge"> 10 <link rel="stylesheet" 11 href="../bootstrap-4.3.1/dist/css/bootstrap.min.css"> 12 <script src="../bootstrap-4.3.1/dist/js/jquery.min.js"></script> 13 14 <script src="script.js"></script> 15 16 <title>IoT Home Automation</title> 17</head> 18 19<body 20 onload="initApp()"> 21 <div class=""> 22 <nav class="navbar navbar-expand-md 23 bg-dark navbar-dark"> 24 <!-- Brand --> 25 <a class="navbar-brand" 26 href="home.html">IoT Home Automation</a> 27 28 <!-- Toggler/collapsibe 29 Button --> 30 <button class="navbar-toggler" type="button" data-toggle="collapse" 31 data-target="#collapsibleNavbar"> 32 <span class="navbar-toggler-icon"></span> 33 34 </button> 35 36 <!-- Navbar links --> 37 <div class="collapse 38 navbar-collapse" id="collapsibleNavbar"> 39 <ul class="navbar-nav"> 40 41 <!-- <li class="nav-item"> 42 <a class="nav-link" href="dashboard.html">Dashboard</a> 43 44 </li> 45 <li class="nav-item"> --> 46 <a class="nav-link" 47 href="control.html">Controller</a> 48 </li> 49 </ul> 50 </div> 51 52 </nav> 53 <br> 54 <img src="img/khec.png" style="padding-top:20px; 55 padding-bottom: 50px;" class="img img-fluid rounded mx-auto d-block" 56 alt="Khwopa 57 Engineering College"> 58 <div class="col"> 59 <h3 class="text-center">Welcome 60 to IoT Home Automation</h3> 61 </div> 62 <div style="padding-top:20px;" 63 class="container col"> 64 <ulc class="list-group"> 65 <li class="list-group-item 66 active">Team Members:</li> 67 <li class="font-weight-bold list-group-item 68 d-flex justify-content-between align-items-center">Prabin Raj Upreti 69 <span 70 class="badge badge-primary badge-pill">750421</span> 71 </li> 72 <li 73 class="list-group-item d-flex justify-content-between align-items-center">Erina 74 Sharma 75 <span class="badge badge-primary badge-pill">750411</span></li> 76 77 <li class="list-group-item d-flex justify-content-between align-items-center">Parash 78 Sapkota 79 <span class="badge badge-primary badge-pill">750419</span></li> 80 81 <li class="list-group-item d-flex justify-content-between align-items-center">Sajan 82 Duwal 83 <span class="badge badge-primary badge-pill">750425</span></li> 84 85 </ul> 86 </div> 87 <script src="../bootstrap-4.3.1/dist/js/bootstrap.min.js"></script> 88</body> 89 90</html>
checkConnection.js
javascript
1function checkConnection(){ 2 // var x = document.cookie 3 // if(!x){ 4 5 // var name = prompt("Enter your name.") 6 // if(name == null || name 7 == "" || name.trim().length == 0){ 8 // document.getElementById("demo").innerHTML 9 = "ERROR!! Reload the page."; 10 // return; 11 // } 12 // else{ 13 14 // document.cookie = "name="+name; 15 // var xhttp = new XMLHttpRequest(); 16 17 // xhttp.onreadystatechange = function(){ 18 // if (this.readyState 19 == 4 && this.status == 200){ 20 // document.getElementById("demo").innerHTML 21 = xhttp.responseText; 22 // } 23 // }; 24 // xhttp.open("GET","http://127.0.0.1/IoT/server/checkConnection.php",true); 25 26 // xhttp.send(); 27 // } 28 // } 29 window.location.href = "/IoT/client/home.html"; 30 31}
control.html
html
1<!DOCTYPE html> 2<html lang="en"> 3 4<head> 5 <meta charset="UTF-8"> 6 7 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 8 9 <meta http-equiv="X-UA-Compatible" content="ie=edge"> 10 <link rel="stylesheet" 11 href="../bootstrap-4.3.1/dist/css/bootstrap.min.css"> 12 <script src="../bootstrap-4.3.1/dist/js/jquery.min.js"></script> 13 14 <script src="script.js"></script> 15 <title>IoT Home Automation</title> 16</head> 17 18<body> 19 20 <nav class="navbar navbar-expand-md bg-dark navbar-dark"> 21 <a class="navbar-brand" 22 href="home.html">IoT Home Automation</a> 23 <button class="navbar-toggler" 24 type="button" data-toggle="collapse" data-target="#collapsibleNavbar"> 25 26 <span class="navbar-toggler-icon"></span> 27 </button> 28 <div 29 class="collapse navbar-collapse" id="collapsibleNavbar"> 30 <ul class="navbar-nav"> 31 32 <!-- <li class="nav-item"> 33 <a class="nav-link" href="dashboard.html">Dashboard</a> 34 35 </li> --> 36 <li class="nav-item"> 37 <a class="nav-link" 38 href="control.html">Controller</a> 39 </li> 40 </ul> 41 </div> 42 43 </nav> 44 <div class="container"> 45 <h5 style="padding-top: 15px;" 46 class="h5 text-left">Home/Controller</h5><hr> 47 48 <div class="row"> 49 50 <div class=" col-sm-12 col-md-12 text-center"> 51 <h3>Turn ON/OFF</h3> 52 53 </div> 54 <div style="padding: 20px;" class="col-6 col-sm-6"> 55 56 <h2 style="padding-bottom: 50px;" class="text-center">AC</h2> 57 <button 58 id="60" class="get_id btn btn-lg btn-block btn-primary" onclick="sendRequest(this.id)">ON/OFF</button> 59 60 </div> 61 <div style="padding: 20px;" class="col-6 col-sm-6"> 62 63 <h2 style="padding-bottom: 50px;" class="text-center">Light 1</h2> 64 65 <button id="70" class="get_id btn btn-lg btn-block btn-primary" onclick="sendRequest(this.id)">ON/OFF</button> 66 67 </div> 68 <div style="padding: 20px;" class="col-6 col-sm-6"> 69 70 <h2 style="padding-bottom: 50px;" class="text-center">Light 2</h2> 71 72 <button id="80" class="get_id btn btn-lg btn-block btn-primary" onclick="sendRequest(this.id)">ON/OFF</button> 73 74 </div> 75 <div style="padding: 20px;" class="col-6 col-sm-6"> 76 77 <h2 style="padding-bottom: 50px;" class="text-center">Socket</h2> 78 79 <button id="90" class="get_id btn btn-lg btn-block btn-primary" onclick="sendRequest(this.id)">ON/OFF</button> 80 81 </div> 82 </div> 83 </div> 84 <script src="../bootstrap-4.3.1/dist/js/bootstrap.min.js"></script> 85</body> 86 87</html>
script.js
javascript
1function initApp() { 2 // var xhttp = new XMLHttpRequest(); 3 // 4 xhttp.onreadystatechange = function() { 5 // if (this.readyState == 4 && this.status 6 == 200) { 7 // // console.log(this.responseText); 8 // } 9 // }; 10 11 // xhttp.open("GET", "../server/server.php", true); 12 // xhttp.send(); 13} 14function 15 sendRequest(id) { 16 // var res; 17 // var paramg; 18 document.getElementById(id).classList.remove('btn-primary'); 19 20 document.getElementById(id).classList.add('btn-warning'); 21 document.getElementsByClassName("get_id")[0].disabled 22 = true; 23 document.getElementsByClassName("get_id")[1].disabled = true; 24 25 document.getElementsByClassName("get_id")[2].disabled = true; 26 document.getElementsByClassName("get_id")[3].disabled 27 = true; 28 var xhttp = new XMLHttpRequest(); 29 // if(this.readyState == 30 0){ 31 // console.log("0: request not initialized"); 32 // } 33 34 // if(this.readyState == 1){ 35 // console.log("1: server connection 36 established"); 37 // } 38 // if(this.readyState == 2){ 39 // 40 console.log("2: request received"); 41 // } 42 // if(this.readyState 43 == 3){ 44 // console.log("3: processing request"); 45 // } 46 47 // if(this.readyState == 4){ 48 // console.log("4: request finished 49 and response is ready"); 50 // } 51 // res = this.responseText; 52 53 // if (this.readyStatus == 4) { 54 // alert(res); 55 // } 56 // 57 } 58 59 xhttp.open("GET", "http://192.168.1.100:80?pin=" + id, true); 60 61 // xhttp.setRequestHeader("Access-Control-Allow-Headers","*"); 62 // xhttp.setRequestHeader("Origin", 63 "*"); 64 // xhttp.setRequestHeader("Access-Control-Allow-Methods", "GET, 65 POST,PUT"); 66 // xhttp.setRequestHeader('Access-Control-Allow-Credential','true'); 67 68 xhttp.send(); 69 // alert('Sending Request to server!!'); 70 setTimeout(function(){ 71 72 document.getElementById(id).classList.remove('btn-warning'); 73 document.getElementById(id).classList.add('btn-primary'); 74 75 document.getElementsByClassName("get_id")[0].disabled = false; 76 document.getElementsByClassName("get_id")[1].disabled 77 = false; 78 document.getElementsByClassName("get_id")[2].disabled = false; 79 80 document.getElementsByClassName("get_id")[3].disabled = false; 81 if (id 82 % 2 == 0) { 83 document.getElementById(id).id = parseInt(id) + 1; 84 } 85 86 if (id % 2 != 0) { 87 document.getElementById(id).id = parseInt(id) - 88 1; 89 } 90 91 },4000); 92 return; 93 94} 95// function sendToArduino(id) 96 { 97 98// var xhttp = new XMLHttpRequest() 99// xhttp.open("GET", "http://10.10.5.101:80/?pin=" 100 + id, false); 101// xhttp.send(); 102// }
Downloadable files
Circuit Diagram
Circuit Diagram
Documentation
House Model
This is a model of the house. in where we are installing our system.
House Model
House Model
This is a model of the house. in where we are installing our system.
House Model
Comments
Only logged in users can leave comments