BUG FIX: variable name JSON for slider controls. Supports Fixed Hz now

This commit is contained in:
rljonesau 2018-12-16 09:07:31 +11:00
parent 4a3a28540b
commit 3ed4335db0
2 changed files with 70 additions and 77 deletions

Binary file not shown.

View file

@ -2,10 +2,66 @@
const char* MAIN_PAGE PROGMEM = R"=====( const char* MAIN_PAGE PROGMEM = R"=====(
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="en">
<head> <head>
<meta charset="utf-8"/>
<script> <script>
var Socket;
function init() {
Socket = new WebSocket('ws://' + window.location.hostname + ':81/');
Socket.onmessage = function(event){
var heater = JSON.parse(event.data);
var key;
for(key in heater) {
console.log("JSON decode:", key, heater[key]);
switch(key) {
case "TempCurrent":
document.getElementById(key).innerHTML = heater[key];
break;
case "RunState":
if (heater.RunState == 0) {
document.getElementById("myonoffswitch").checked = false;
document.getElementById("myonoffswitch").style = "block";
} else if(heater.RunState >= 7) {
document.getElementById("myonoffswitch").checked = false;
document.getElementById("myonoffswitch").style = "none";
} else {
document.getElementById("myonoffswitch").checked = true;
document.getElementById("myonoffswitch").style = "block";
}
break;
case "TempDesired":
document.getElementById("slide").value = heater[key];
document.getElementById(key).innerHTML = heater[key];
break;
case "ErrorState":
break;
case "Thermostat":
if(heater[key] != 0) {
document.getElementById("FixedDiv").hidden = true;
document.getElementById("ThermoDiv").hidden = false;
}
else {
document.getElementById("FixedDiv").hidden = false;
document.getElementById("ThermoDiv").hidden = true;
}
break;
case "PumpFixed":
document.getElementById(key).innerHTML = heater[key];
break;
}
}
}
}
function sendJSONobject(obj){
var str = JSON.stringify(obj);
console.log("JSON Tx:", str);
Socket.send(str);
}
// Scripts for date handling // Scripts for date handling
Date.prototype.today = function () { Date.prototype.today = function () {
return ((this.getDate() < 10)?"0":"") + this.getDate() +"/"+(((this.getMonth()+1) < 10)?"0":"") + (this.getMonth()+1) +"/"+ this.getFullYear(); return ((this.getDate() < 10)?"0":"") + this.getDate() +"/"+(((this.getMonth()+1) < 10)?"0":"") + (this.getMonth()+1) +"/"+ this.getFullYear();
@ -14,20 +70,17 @@ Date.prototype.today = function () {
// Scripts for setting date and time // Scripts for setting date and time
function setcurrenttime(){ function setcurrenttime(){
const cmd = { Time: 0 }; var cmd = {};
cmd.Time = document.getElementById("curtime").value; cmd.Time = document.getElementById("curtime").value;
var str = JSON.stringify(cmd); sendJSONobject(cmd);
Socket.send(str);
} }
function setcurrentdate(){ function setcurrentdate(){
var cmd = { Date: 0 }; var cmd = {};
cmd.date = document.getElementById("curdate").value cmd.Date = document.getElementById("curdate").value;
var str = JSON.stringify(cmd); sendJSONobject(cmd);
console.log("Json Tx",str);
Socket.send(str);
} }
@ -135,59 +188,6 @@ window.onload = function() {
}; };
// End date Picker Script // End date Picker Script
var Socket;
function init() {
Socket = new WebSocket('ws://' + window.location.hostname + ':81/');
Socket.onmessage = function(event){
var heater = JSON.parse(event.data);
var key;
for(key in heater) {
switch(key) {
case "TempCurrent":
console.log("JSON Rx: TempCurrent:", heater.TempCurrent);
document.getElementById("TempCurrent").innerHTML = heater.TempCurrent;
break;
case "RunState":
console.log("JSON Rx: RunState:", heater.RunState);
if (heater.RunState == 0) {
document.getElementById("myonoffswitch").checked = false;
document.getElementById("myonoffswitch").style = "block";
} else if(heater.RunState >= 7) {
document.getElementById("myonoffswitch").checked = false;
document.getElementById("myonoffswitch").style = "none";
} else {
document.getElementById("myonoffswitch").checked = true;
document.getElementById("myonoffswitch").style = "block";
}
break;
case "TempDesired":
console.log("JSON Rx: TempDesired:", heater.TempDesired);
document.getElementById("slide").value = heater.TempDesired;
document.getElementById("TempDesired").innerHTML = heater.TempDesired;
break;
case "ErrorState":
console.log("JSON Rx: ErrorState:", heater.ErrorState);
break;
case "Thermostat":
console.log("JSON Rx: Thermostat:", heater.Thermostat);
if(heater.Thermostat) {
document.getElementById("FixedDiv").hidden = true;
document.getElementById("ThermoDiv").hidden = false;
}
else {
document.getElementById("FixedDiv").hidden = false;
document.getElementById("ThermoDiv").hidden = true;
}
break;
case "PumpFixed":
console.log("JSON Rx: Thermostat:", heater.PumpFixed);
document.getElementById("PumpFixed").innerHTML = heater.PumpFixed;
break;
}
}
}
}
function funcNavLinks() { function funcNavLinks() {
var x = document.getElementById("myLinks"); var x = document.getElementById("myLinks");
if (x.style.display === "block") { if (x.style.display === "block") {
@ -247,7 +247,6 @@ function funcdispAdvanced(){
function OnOffCheck(){ function OnOffCheck(){
// Get the checkbox status and place in the checkbox variable // Get the checkbox status and place in the checkbox variable
// var checkBox = document.getElementById("myonoffswitch").value;
var checkBox = document.getElementById("myonoffswitch"); var checkBox = document.getElementById("myonoffswitch");
// Send a message to the Devel console of web browser for debugging // Send a message to the Devel console of web browser for debugging
@ -256,25 +255,20 @@ function OnOffCheck(){
// If the checkbox is checked, display the output 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 // We also need to send a message back into the esp as we cannot directly run Arduino Functions from within the javascript
var cmd = {};
if (checkBox.checked == true){ if (checkBox.checked == true){
//Insert Code Here To Turn On The Heater //Insert Code Here To Turn On The Heater
console.log("Turning On Heater"); console.log("Turning On Heater");
const cmd = { RunState: 1 }; cmd.RunState = 1;
var str = JSON.stringify(cmd); sendJSONobject(cmd);
console.log("JSON Tx:", str);
Socket.send(str);
} }
else{ else{
//Insert Code Here To Turn Off The Heater //Insert Code Here To Turn Off The Heater
console.log("Turning Off Heater"); console.log("Turning Off Heater");
const cmd = { RunState: 0 }; cmd.RunState = 0;
var str = JSON.stringify(cmd); sendJSONobject(cmd);
console.log("JSON Tx:", str);
Socket.send(str);
} }
} }
@ -283,10 +277,9 @@ function onSlide(newVal, JSONKey) {
document.getElementById(JSONKey).innerHTML = newVal; document.getElementById(JSONKey).innerHTML = newVal;
// hand carve JSON string - cannot get JSON.stringify to co-operate with a variable as the key var cmd = {};
var str = '{\"' + JSONKey + '\":' + newVal + '}'; cmd[JSONKey] = newVal; // note: variable name needs []
console.log("JSON Tx:", str); sendJSONobject(cmd);
Socket.send(str);
} }