From 2bc415b2afc236e3f0d8036070df928b1cbe1f65 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 9 Dec 2018 17:09:50 +1100 Subject: [PATCH] Fixed on off toggle switch so it works --- Arduino/BTCDieselHeater/mainpage.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Arduino/BTCDieselHeater/mainpage.cpp b/Arduino/BTCDieselHeater/mainpage.cpp index aad9a57..151f1f4 100644 --- a/Arduino/BTCDieselHeater/mainpage.cpp +++ b/Arduino/BTCDieselHeater/mainpage.cpp @@ -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"); }