View Single Post
Old 01-03-16, 03:30 PM   #25
Acuario
Apprentice EcoRenovator
 
Join Date: May 2011
Location: Tortosa, Spain
Posts: 218
Thanks: 2
Thanked 75 Times in 44 Posts
Default

11. Ethernet.ino (part 3)
//Return initial web page - then updated by AJAX XML
void returnWebPage(EthernetClient cl) {

cl.println(F("Content-Type: text/html"));
cl.println(F("Connection: keep-alive"));
cl.println();
cl.println(F("<!DOCTYPE html>"));
cl.println(F("<html><head>"));
cl.println(F("<link rel='stylesheet' type='text/css' href='http://www.tortosaforum.com/heatpump/heatpumpcss.css' />"));
cl.println(F("<title>Heat Pump Controller status</title>"));
cl.println(F("<script>"));
cl.println(F("function GetArduinoInputs(){"));
cl.println(F("nocache = '&nocache=' + Math.random() * 1000000;"));
cl.println(F("var request = new XMLHttpRequest();"));
cl.println(F("request.onreadystatechange = function(){"));
cl.println(F("if (this.readyState == 4) {"));
cl.println(F("if (this.status == 200) {"));
cl.println(F("if (this.responseXML != null) {"));

cl.println(F("document.getElementById('roomTemp'). innerHTML=this.responseXML.getElementsByTagName('r oomTemp')[0].childNodes[0].nodeValue;"));
cl.println(F("document.getElementById('bacSetTemp' ).innerHTML=this.responseXML.getElementsByTagName( 'bacSetTemp')[0].childNodes[0].nodeValue;"));
cl.println(F("document.getElementById('compressor' ).innerHTML=this.responseXML.getElementsByTagName( 'compressor')[0].childNodes[0].nodeValue;"));
cl.println(F("document.getElementById('evaporator' ).innerHTML=this.responseXML.getElementsByTagName( 'evaporator')[0].childNodes[0].nodeValue;"));
cl.println(F("document.getElementById('flow').inne rHTML=this.responseXML.getElementsByTagName('flow' )[0].childNodes[0].nodeValue;"));
cl.println(F("document.getElementById('return').in nerHTML=this.responseXML.getElementsByTagName('ret urn')[0].childNodes[0].nodeValue;"));
cl.println(F("document.getElementById('humidity'). innerHTML=this.responseXML.getElementsByTagName('h umidity')[0].childNodes[0].nodeValue;"));
cl.println(F("document.getElementById('dewpoint'). innerHTML=this.responseXML.getElementsByTagName('d ewpoint')[0].childNodes[0].nodeValue;"));

cl.println(F("document.getElementById('bacMode').i nnerHTML=this.responseXML.getElementsByTagName('ba cMode')[0].childNodes[0].nodeValue;"));
cl.println(F("document.getElementById('bacPowerSta te').innerHTML=this.responseXML.getElementsByTagNa me('bacPowerState')[0].childNodes[0].nodeValue;"));

cl.println(F("document.getElementById('defrost').i nnerHTML=this.responseXML.getElementsByTagName('de frost')[0].childNodes[0].nodeValue;"));
cl.println(F("document.getElementById('systemTime' ).innerHTML=this.responseXML.getElementsByTagName( 'systemTime')[0].childNodes[0].nodeValue;"));
cl.println(F("document.getElementById('defrostStep ').innerHTML=this.responseXML.getElementsByTagName ('defrostStep')[0].childNodes[0].nodeValue;"));
cl.println(F("document.getElementById('hysterisis' ).innerHTML=this.responseXML.getElementsByTagName( 'hysterisis')[0].childNodes[0].nodeValue;"));

cl.println(F("document.getElementById('compStat'). innerHTML=this.responseXML.getElementsByTagName('c ompStat')[0].childNodes[0].nodeValue;"));
cl.println(F("document.getElementById('fanLow').in nerHTML=this.responseXML.getElementsByTagName('fan Low')[0].childNodes[0].nodeValue;"));
cl.println(F("document.getElementById('fanHigh').i nnerHTML=this.responseXML.getElementsByTagName('fa nHigh')[0].childNodes[0].nodeValue;"));
cl.println(F("document.getElementById('valve').inn erHTML=this.responseXML.getElementsByTagName('valv e')[0].childNodes[0].nodeValue;"));
cl.println(F("document.getElementById('pump').inne rHTML=this.responseXML.getElementsByTagName('pump' )[0].childNodes[0].nodeValue;"));
cl.println(F("document.getElementById('state').inn erHTML=this.responseXML.getElementsByTagName('stat e')[0].childNodes[0].nodeValue;"));
cl.println(F("document.getElementById('maxWaterTem p').innerHTML=this.responseXML.getElementsByTagNam e('maxWaterTemp')[0].childNodes[0].nodeValue;"));
cl.println(F("document.getElementById('ambient').i nnerHTML=this.responseXML.getElementsByTagName('am bient')[0].childNodes[0].nodeValue;"));
cl.println(F("document.getElementById('s4').innerH TML=this.responseXML.getElementsByTagName('s4')[0].childNodes[0].nodeValue;"));

cl.println(F("}}}}"));
cl.println(F("request.open('GET', 'ajax_inputs' + nocache, true);"));
cl.println(F("request.send(null);"));
cl.println(F("setTimeout('GetArduinoInputs()', 5000);}"));
cl.println(F("</script></head>"));
cl.println(F("<body onload='GetArduinoInputs()'>"));
cl.println(F("<h1>Heat Pump Controller status</h1>"));

//////////////////////////////////////////////////////////////////////////////////////////////
cl.println(F("<table border = '1' width = '30%'>"));
cl.println(F("<tr><th>Parameter</th><th>Reading</th><th>Setting</th></tr>"));
cl.print(F("<tr><td>Room temperature</td><td><span id='roomTemp'>...</span></td><td><span id='bacSetTemp'>...</span></td></tr>"));
cl.print(F("<tr><td>Flow temperature</td><td><span id='flow'>...</span></td><td><span id='maxWaterTemp'>...</span></td></tr>"));
cl.print(F("<tr><td>Return temperature</td><td><span id='return'>...</span></td><td>&nbsp;</td></tr>"));
cl.print(F("<tr><td>Evaporator</td><td><span id='evaporator'>...</span></td><td>"));
cl.print(defTemp);
cl.print(F("</td></tr>"));
cl.print(F("<tr><td>Compressor</td><td><span id='compressor'>...</span></td><td>&nbsp;</td></tr>"));
cl.println(F("</table>"));

//////////////////////////////////////////////////////////////////////////////////////////////
cl.println(F("<table border = '1' width = '30%'>"));
cl.println(F("<tr><th>Relay</th><th>Status</th></tr>"));
cl.print(F("<tr><td>Compressor</td><td><span id='compStat'>...</span></td></tr>"));
cl.print(F("<tr><td>Fan low</td><td><span id='fanLow'>...</span></td></tr>"));
cl.print(F("<tr><td>Fan high</td><td><span id='fanHigh'>...</span></td></tr>"));
cl.print(F("<tr><td>3W valve</td><td><span id='valve'>...</span></td></tr>"));
cl.print(F("<tr><td>Circulating</td><td><span id='pump'>...</span></td></tr>"));
cl.println(F("</table>"));

cl.println(F("<p>State: <span id='state'>...</span></p>"));

cl.println(F("<p>Ambient: <span id='ambient'>...</span></p>"));
cl.println(F("<p>S4: <span id='s4'>...</span></p>"));
cl.println(F("<p>Humidity: <span id='humidity'>...</span></p>"));
cl.println(F("<p>Dew point: <span id='dewpoint'>...</span></p>"));
cl.println(F("<p>Hysterisis: <span id='hysterisis'>...</span></p>"));

cl.println(F("<p>BAC Mode: <span id='bacMode'>...</span></p>"));
cl.println(F("<p>BAC Power: <span id='bacPowerState'>...</span></p>"));
cl.println(F("<p>Defrost running: <span id='defrost'>...</span></p>"));
cl.println(F("<p>Defrost step: <span id='defrostStep'>...</span></p>"));
cl.println(F("<p></p><p>System time: <span id='systemTime'>...</span></p>"));
cl.println(F("</body></html>"));
}
Acuario is offline   Reply With Quote