String script() { String s = "$(document).ready(function () {\n"; s +="getTemp();\n"; s +="getHumidity();\n"; s +="getSwitch1();\n"; s +="getSwitch2();\n"; s +="getSwitch3();\n"; s +="getSwitch4();\n"; s +="function getTemp(){ $.get(\"/gettemp\", function(data) { $(\".temp-value\").html(data); window.setTimeout(getTemp, 5*1000); }); }\n"; s +="function getHumidity(){ $.get(\"/gethumidity\", function(data) { $(\".humidity-value\").html(data); window.setTimeout(getHumidity, 5*1000); }); }\n"; s +="function getSwitch1(){ $.get(\"/switch_state?relay=1\", function(data) { if(data == 1) {$(\"#switch1\").attr('checked', true)} else {$(\"#switch1\").attr('checked', false)}; window.setTimeout(getSwitch1, 1000); }); }\n"; s +="function getSwitch2(){ $.get(\"/switch_state?relay=2\", function(data) { if(data == 1) {$(\"#switch2\").attr('checked', true)} else {$(\"#switch2\").attr('checked', false)}; window.setTimeout(getSwitch2, 1000); }); }\n"; s +="function getSwitch3(){ $.get(\"/switch_state?relay=3\", function(data) { if(data == 1) {$(\"#switch3\").attr('checked', true)} else {$(\"#switch3\").attr('checked', false)}; window.setTimeout(getSwitch3, 1000); }); }\n"; s +="function getSwitch4(){ $.get(\"/switch_state?relay=4\", function(data) { if(data == 1) {$(\"#switch4\").attr('checked', true)} else {$(\"#switch4\").attr('checked', false)}; window.setTimeout(getSwitch4, 1000); }); }\n"; s +="$(\"#switch1\").change(function() { if(this.checked) { $.get(\"/switch?relay=1&state=1\", function(data) {}); } else { $.get(\"/switch?relay=1&state=0\", function(data) {}); } });\n"; s +="$(\"#switch2\").change(function() { if(this.checked) { $.get(\"/switch?relay=2&state=1\", function(data) {}); } else { $.get(\"/switch?relay=2&state=0\", function(data) {}); } });\n"; s +="$(\"#switch3\").change(function() { if(this.checked) { $.get(\"/switch?relay=3&state=1\", function(data) {}); } else { $.get(\"/switch?relay=3&state=0\", function(data) {}); } });\n"; s +="$(\"#switch4\").change(function() { if(this.checked) { $.get(\"/switch?relay=4&state=1\", function(data) {}); } else { $.get(\"/switch?relay=4&state=0\", function(data) {}); } });\n"; s +="})"; return s; }