lights-web/static/index.html

152 lines
5.8 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>light up</title>
</head>
<style>
:root {
--color-p-0: #7688A9;
--color-p-1: #D5DCE8;
--color-p-2: #A6B3CB;
--color-p-3: #50668F;
--color-p-4: #2D4571;
--color-c-0: #FEE0A9;
--color-c-1: #FFF7E8;
--color-c-2: #FFEDCC;
--color-c-3: #D7B26E;
--color-c-4: #AA8239;
}
</style>
<body style="background-color:var(--color-p-1)">
<header style="margin:auto;font-family:DejaVu Sans,sans-serif;text-align:center;color:var(--color-p-4);">
<h1 id="up" style="cursor:pointer">light your space <strong style="color:var(--color-c-3)">up</strong></h1>
</header>
<div style="margin-left:auto;margin-right:auto;width:240px">
<svg width="240px" height="240px" style="margin:auto;">
<rect
y="20"
x="19.999992"
height="25"
width="50"
id="rect4145"
style="opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<rect
y="115"
x="114.99999"
height="10"
width="10"
id="rect4149"
style="opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
id="path4151"
d="m 124.99999,120 95,0"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
id="path4153"
d="m 119.99999,115 0,-40"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
id="path4155"
d="m 119.99999,60 0,-40"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
id="path4157"
d="m 99.999992,20 -80,0 0,200 199.999998,0 0,-200 -105,0"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
d="m 133.14724,67.221494 a 15,15 0 0 1 -13.17405,7.778482"
id="path4161"
style="opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
id="path4163"
d="M 133.25892,67.767857 119.99999,60"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
transform="matrix(0,-1,-1,0,0,0)"
style="opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path4165"
d="m -7.0534165,-107.93734 a 15,15 0 0 1 -13.1740505,7.77848" />
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 107.39099,6.941734 7.76786,13.258928"
id="path4167" />
<rect
ry="5"
y="30"
x="29.999992"
height="80"
width="180"
id="rec_light_3"
style="opacity:0;fill:#ffff00;fill-opacity:0.50196078;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;cursor:pointer" />
<rect
style="opacity:0;fill:#000000;fill-opacity:0.50196078;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;cursor:pointer"
id="rec_light_4"
width="180"
height="80"
x="29.999992"
y="130"
ry="5" />
</svg>
</div>
<center>
<b>wyciag:</b> <span id="exhaust"></span>
<button id="exhaust_on">on</button>
<button id="exhaust_off">off</button>
</center>
<script src="https://unpkg.com/mqtt@2.1.3/dist/mqtt.min.js" ></script>
<!-- <script src="mqtt.min.js"></script> -->
<script>
window.onload = function() {
var mqtt_server = 'ws://sound.waw.hackerspace.pl:1881';
var client = mqtt.connect(mqtt_server, {username: "light", password: "MG4Dhp6vCZjgbTzJ"});
var lights = [];
for (i = 3; i <= 4; i++) {
lights[i] = document.getElementById("rec_light_" + i);
}
client.on("message", function (topic, payload) {
if(topic == "iot/c0dbe7/relay/on") {
document.getElementById('exhaust').innerText = payload;
return;
}
var match = /devices\/light_904649\/light_(.*)\/on/.exec(topic);
var n = parseInt(match[1]);
if(~isNaN(n) && n > 0 && n <= 4){
lights[n].style.opacity = 1;
if (payload == "true") {
lights[n].style.fill = "var(--color-c-0)";
} else {
lights[n].style.fill = "var(--color-p-3)";
}
}
})
for (i = 3; i <= 4; i++) {
client.subscribe("devices/light_904649/light_" + i + "/on");
lights[i].onclick=function(value){
console.log("Fuck pass-by-reference");
return function(){
client.publish("devices/light_904649/light_" + value + "/on/toggle", 'true');
};
} (i);
};
document.getElementById("up").onclick = function(){
for (i = 3; i <= 4; i++) {
client.publish("devices/light_904649/light_" + i + "/on/set", 'true');
};
};
client.subscribe('iot/c0dbe7/relay/on');
document.getElementById('exhaust_on').onclick = function() {
client.publish('iot/c0dbe7/relay/on/set', 'true');
}
document.getElementById('exhaust_off').onclick = function() {
client.publish('iot/c0dbe7/relay/on/set', 'false');
}
};
</script>
</html>