Fixed on off toggle switch so it works

This commit is contained in:
James 2018-12-09 17:09:50 +11:00
parent 1d98716dd4
commit 2bc415b2af

View file

@ -9,6 +9,19 @@ const char* MAIN_PAGE PROGMEM = R"=====(
function init() {
Socket = new WebSocket('ws://' + window.location.hostname + ':81/');
Socket.onmessage = function(event){
console.log("msg rec", evt.data);
var msgArray = evt.data.split(","); // split message by delimiter into a string array
console.log("msgArray", msgArray[0]);
console.log("msgArray", msgArray[1]);
console.log("msgArray", msgArray[2]);
console.log("msgArray", msgArray[3]);
var indicator = msgArray[1]; // the first element in the message array is the ID of the object to update
console.log("indiactor", indicator);
if (SensorRead) // if an object by the name of the message exists, update its value or its attributes
{
switch (msgArray[1])
{
case "CurrentTemp":
document.getElementById("TempCurrent").innerHTML = event.data;
}
}
@ -264,20 +277,20 @@ function funcdispAdvanced(){
// Function to check the power on/off slide switch.
function OnOffCheck(){
// Get the checkbox status and place in the checkbox variable
var checkBox = document.getElementById("myonoffswitch");
var checkBox = document.getElementById("myonoffswitch").value;
// Send a message to the Devel console of web browser for debugging
console.log(document.getElementById("myonoffswitch").checked);
// Get the output text
var text = document.getElementById("text");
// If the checkbox is checked, display the output text
// We also need to send a message back into the esp as we cannot directly run Arduino Functions from within the javascript
if (checkBox.checked == true){
//Insert Code Here To Turn On The Heater
Console.log("Turning On Heater");
Socket.send("[CMD]ON");
}
else{
//Insert Code Here To Turn Off The Heater
Console.log("Turning Off Heater");
Socket.send("[CMD]OFF");
}