use POST request for modyfing light state

master
vuko 2020-11-24 10:58:42 +01:00
parent 337523e151
commit 7857e1e908
1 changed files with 13 additions and 6 deletions

View File

@ -203,15 +203,22 @@
}; };
light.element.onclick=function(light){ light.element.onclick=function(light){
return function(){ 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); }(light);
}; };
//document.getElementById("up").onclick = function(){ document.getElementById("up").onclick = function(lights){
// for (i = 1; i <= 8; i++) { return function ( lights ) {
// client.publish("devices/light_904649/light_" + i + "/on/set", 'true'); 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({ client.connect({