4 light version

master
vuko 2020-11-23 12:10:31 +01:00
parent 929961c3c8
commit 474e2fd1cf
1 changed files with 25 additions and 27 deletions

View File

@ -76,26 +76,37 @@
<rect
ry="5"
y="30"
x="29.999992"
x="30"
height="80"
width="180"
width="80"
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" />
style="opacity:0;fill:#ffff00;fill-opacity:0.50196078;stroke:#000000;stroke-width:0.66942149;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<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"
style="opacity:0;fill:#000000;fill-opacity:0.50196078;stroke:#000000;stroke-width:0.66942149;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rec_light_4"
width="180"
width="80"
height="80"
x="29.999992"
x="30"
y="130"
ry="5" />
</svg>
<rect
style="opacity:0;fill:#ffff00;fill-opacity:0.50196078;stroke:#000000;stroke-width:0.66942149;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rec_light_2"
width="80"
height="80"
x="130"
y="30"
ry="5" />
<rect
ry="5"
y="130"
x="130"
height="80"
width="80"
id="rec_light_1"
style="opacity:0;fill:#000000;fill-opacity:0.50196078;stroke:#000000;stroke-width:0.66942149;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</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>
@ -103,14 +114,10 @@
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++) {
for (i = 1; 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){
@ -121,9 +128,8 @@
lights[n].style.fill = "var(--color-p-3)";
}
}
})
for (i = 3; i <= 4; i++) {
for (i = 1; i <= 4; i++) {
client.subscribe("devices/light_904649/light_" + i + "/on");
lights[i].onclick=function(value){
console.log("Fuck pass-by-reference");
@ -137,14 +143,6 @@
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>