Data Sheet

dScript
dScript User Manual v2.15
The last thing to add is a call to startAJAX() after the web page has been loaded. Do this by
modifying the <body> tag like this:
<body onload="startAJAX()">
The new html page looks like this:
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dweb Simple Test Page</title>
</head>
<body onload="startAJAX()">
<button id="Rly1" onmousedown="newAJAXCommand('dscript.cgi?Rly1=2');">Yard
Lights</button>
<br> Temperature is
<script type="text/javascript">
function ajaxUpdate()
{
document.getElementById('Rly1').style.backgroundColor =
(getValue('Rly1')=='1') ? 'rgba(255,0,0,0.2)' : 'rgba(0,0,255,0.2)';
}
</script>
</body>
</html>
The final items we'll add to this simple web page is a couple of variables, the temperature from
the on-board sensor and the input power supply voltage.
Add the following immediately below the button tag.
Temperature: <div id="Temperature">?</div>
DC Voltage: <div id="DCvolts">?</div>
Then add the following in the ajaxUpadte function immediately below the existing line.
document.getElementById('Temperature').innerHTML =
Number(getValue('Temperature')/10).toFixed(1);
document.getElementById('DCvolts').innerHTML =
Number(getValue('Volts')/10).toFixed(1);
In the dScript program we need to declare the two analogue ports, the two variables
Temperature and Volts and add a couple of lines in the do loop to calculate the temperature
and voltage from the incoming ADC values.
Copyright © 2016, Devantech Ltd.
All rights reserved.
www.robot-electronics.co.uk
43