made website working

This commit is contained in:
2021-04-22 20:52:19 +02:00
parent 8ba23873b8
commit d95b851055
8 changed files with 197 additions and 17 deletions

View File

@@ -39,26 +39,64 @@ li {
}
.button {
.button{
width: 30%;
margin: auto;
padding: 15px 25px;
font-size: 24px;
text-align: center;
cursor: pointer;
outline: none;
color: #fff;
background-color: #4CAF50;
border: none;
border-radius: 15px;
box-shadow: 0 9px #999;
/* box-shadow: 0 9px #999; */
}
.small-button{
background-color: red;
width: 15%;
/* margin: auto; */
padding: 15px 25px;
font-size: 24px;
text-align: center;
cursor: pointer;
outline: none;
color: #fff;
border: none;
border-radius: 40px;
position: relative;
bottom: 0;
right: 20px;
/* box-shadow: 0 9px #999; */
}
.light-button-on {
background-color: #4caf4fce;
}
.light-button-on:hover {
background-color: #00a305ce;
}
.button:hover {background-color: #941414}
/* .button:hover {background-color: #941414}
.button:active {
background-color: #3e8e41;
box-shadow: 0 5px #666;
transform: translateY(4px);
}
} */
.light-button-off {
background-color: #af4c4ccc;
cursor: url("kksign.png"), pointer;
}
.light-button-off:hover {
background-color: #910101cc;
cursor: url("kksign.png");
}
.name {
color: #a9322c ;

View File

@@ -1,7 +1,10 @@
<!DOCTYPE html>
<html>
<html lang="en"></htmllang>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>KrabbyHome</title>
<link rel="shortcut icon" href="Icon2.ico"/>
<link rel="stylesheet" href="Styles.css"/>
@@ -18,7 +21,9 @@
<div class="box a">
<h1 class="name" >Karen</h1>
<div class="button">Ambient lights</div>
<div class="button" id="ambiance-light-btn">Ambient lights</div>
<!-- <div class="small-button" id="all-on-light-btn">All lights</div>
<div class="small-button" id="all-off-light-btn">All lights</div> -->
</div>
@@ -28,9 +33,10 @@
<h1 class="name" >Secret formula</h1>
<ul class="text">
<li>Time: 1:17am</li>
<li>Temperature: 19.9 C</li>
<li>No Motion Detected</li>
<li class="digital-clock">Local time: .. AM</li>
<li class="temp">Temperature: ..°C</li>
<li class="hum">Humidity: ..%</li>
<!-- <li class="motion">No motion detected</li> -->
</ul>
</div>
@@ -52,4 +58,6 @@
</div>
</body>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="./index.js"></script>
</html>

View File

@@ -0,0 +1,88 @@
const endpoint = "http://192.168.178.60";
let datas = {};
$(document).ready(function(){
console.log("once");
setInterval(() => {
myTimer();
getData();
}, 1000);
$("#ambiance-light-btn").click(function() {
if (datas.state.ambiance_light == true) {
$.get(`${endpoint}/api/device?id=ambiance_light&action=off&data=-`, (data) => {
$("#ambiance-light-btn").addClass("light-button-off");
$("#ambiance-light-btn").removeClass("light-button-on");
});
return;
}
if (datas.state.ambiance_light == false) {
$.get(`${endpoint}/api/device?id=ambiance_light&action=on&data=-`, (data) => {
$("#ambiance-light-btn").addClass("light-button-on");
$("#ambiance-light-btn").removeClass("light-button-off");
});
return;
}
// $.get(`${endpoint}/api/device?id=ambiance_light&action=on&data=-`, (data) => {
// });
});
});
function myTimer() {
var d = new Date();
$('.digital-clock').text("Local Time: " + d.toLocaleTimeString());
}
function getData() {
$.get(`${endpoint}/api/currentstate`, ( data ) => {
// set all data from api
if(data.state){
// set climate info
$('.temp').text("Temperature: " + data.state.main_temp + "°C");
$('.hum').text("Humidity: " + data.state.main_hum + "%");
// set text for motion
if(data.state.motion){
$('.motion').text("Motion detected!");
}else if(!data.state.motion){
$('.motion').text("No motion detected");
}
// insert once
if(jQuery.isEmptyObject(datas)){
// set lights state
if(data.state.ambiance_light){
$("#ambiance-light-btn").addClass("light-button-on");
}else if(!data.state.ambiance_light){
$("#ambiance-light-btn").addClass("light-button-off");
}
}
}
datas = data;
console.log(datas);
console.log( "Load was performed." );
});
}
function turnLights(){
if (currentState.main_light) {
if (currentState.main_light == true) {
$.get(`${endpoint}/api/device?id=ambiance_light&action=off&data=-`, (data) => {
});
return;
}
}
$.get(`${endpoint}/api/device?id=ambiance_light&action=on&data=-`, (data) => {
});
}