From 7857e1e908281945f754804a0d2677d673986f38 Mon Sep 17 00:00:00 2001 From: vuko Date: Tue, 24 Nov 2020 10:58:42 +0100 Subject: [PATCH] use POST request for modyfing light state --- static/index.html | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/static/index.html b/static/index.html index 106b2ef..455da48 100644 --- a/static/index.html +++ b/static/index.html @@ -203,15 +203,22 @@ }; light.element.onclick=function(light){ return function(){ - client.publish(light.mqtt_path + "/toggle", "true"); + var toggle_request = new XMLHttpRequest(); + toggle_request.open("POST", "/light/" + light.id + "/on/toggle", true); + toggle_request.send(JSON.stringify(true)); }; }(light); }; - //document.getElementById("up").onclick = function(){ - // for (i = 1; i <= 8; i++) { - // client.publish("devices/light_904649/light_" + i + "/on/set", 'true'); - // }; - //}; + document.getElementById("up").onclick = function(lights){ + return function ( lights ) { + for ( i in lights ) { + light = lights[i]; + var toggle_request = new XMLHttpRequest(); + toggle_request.open("POST", "/light/" + light.id + "/on/set", true); + toggle_request.send(JSON.stringify(true)); + }; + }; + }(lights); }; client.connect({