ARMweb webpage with synch of RTC and displaying print page

Post details of your projects here.
Post Reply
sbrazz
Posts: 12
Joined: Sun May 05, 2013 11:01 pm

ARMweb webpage with synch of RTC and displaying print page

Post by sbrazz » Fri May 24, 2013 8:54 am

The RTC on my ARMweb runs aboout a minute fast each day, so I've got my webpage to return the time of day in the CGI string each time it auto refreshes. I've included plenty of comments in the .htm listing; hopefully it's clear enough.
Also print statements are output to the file txta.htm on the ARMweb, so I've inluded it as part of my web page; its the last couple of lines of HTML in the listing. (I'm using my ARMWeb to control my ponds, my solar heating, and my heat-pump). In the screenshot below the output in the txta.htm iframe is CSV; This can be copy and pasted (concatenated) onto a spreadsheet and displayed graphically.
housemon screenshot.png
housemon screenshot.png (176.94 KiB) Viewed 4339 times
I can't upload the .htm file because I get this error:-The extension htm is not allowed.
The upload was rejected because the uploaded file was identified as a possible attack vector."
So I've copied and pasted below. To view it copy and paste it into a good editor (gedit and set view=>highlight mode=>markup=>HTML). All the action starts at the line <body onload="startTime()">
Lines like <?BASIC IF ((PumpStatus AND $02) = $02) Then Print "<td style =color:#66DDFF;text-decoration:blink;>on</td>" else print "<td style =color:#1666bb;>off</td>" ?> can be used to print a dull "off" or a bright blinking "on"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head> <!-- Steven Brazzale - House monitor -->
<style>

th {text-align:left}

</style>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Steven's House monitor</title>
<script type="text/javascript">


function show_confirm(t) //pops up a confimation box
{
var r=confirm("Are you Sure");
if (r==true)
{
sendvalue(t)
}
}

function sendvalue(s){ //reloads this page, but with string s as cgi output added
document.location.replace("housemon.htm?"+s); //sends string s to the CGI input of the main program - all actions ultimately end here
}

function sendTime() //makes up the string of YY-1900:MM:DD:HH:MM:SS
{ // and sends it.
var today=new Date();
var y = today.getYear();
var mm = today.getMonth();
var d=today.getDate();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
// add a zero in front of numbers<10
if (m<58) //my RTC runs fast, so don't send in last 2 minutes of the hour
{ // this is now redundant, the main program now handles unequal hours
if (y>2000) //most browsers now number years from 1900, but IE V.old didn't
{
y = y - 1900;
}
m=checkTime(m); //all values must be two digit, so add leading zero if necessary
s=checkTime(s);
mm = mm + 1; // months from 1 to 12, not 0 to 11
mm = checkTime(mm);
h = checkTime(h);
d = checkTime(d)
sendvalue('z'+y+":"+mm+":"+d+":"+h+":"+m+":"+s);

}
else
{
sendvalue(''); //if it is last 15 min of the hour, send nothing, just refresh page
}
t=setTimeout('sendTime()',500);
}

function checkTime(i) //routine to add leading zero to single digit numbers
{
if (i<10)
{
i="0" + i;
}
return i;
}

function startTime() //on load of the page <body onload="startTime()"> calls this routine
{ // which after 45s calls the sendTime, which then refreshes the page
t=setTimeout('sendTime()',45000); // which executes <body onload="startTime()"> again .....
}


function passwrd(x) //certian actions are password protected. This pops up a prompt box
{ //requiring password input - it passes the command foloowed by
//the pass code, which the main program checks before executing the command
var name=prompt("Password","xxxxxx");

if (name!=null)
{
x= x + name;
sendvalue(x)
}
}

function SelectResult() //routine to handle the select box - sends a value "ci" where i is the
{ // number of the item selected. The main program the sets a flag
var x=document.getElementById("downloadselect"); //of what to print on the iframe "texta.htm"

var a ="c"
a = a + x.selectedIndex
if (a == "c7")
{
show_confirm('s')
}
else
{ if (a =="c8")
{
passwrd('hzfg')
}
else
{ if (a == "c9")
{
passwrd('Rzfg')
}
else
{ sendvalue(a);
}
}
}
}

</script></head>

<body onload="startTime()"> <!-- When the page loads, it starts this timer routine, which then reloads the page -->

<div id="leftpanel" style="background-color:#003333;height:500px;width:340px;text-align:top;color:#2288ff;float:left"> <!--Defines the Left panel and background colour -->


<?BASIC print "RTC:- ";Hrs;":";Mins;":";Secs ?> <!--displays the ARMWeb RTC, so you can see how it compares to your computer clock -->

<br />

Alarms:- &nbsp <input type="button" value="Clear Alarms" onclick="sendvalue('j');" /> <br /> <!--button to clear any alarm flags that may be set in the main program -->

<p style="color:#ff0000;text-decoration:blink;"> <!--set the colour to red and blinking paragraph definition and style-->
<?BASIC If AlarmStatus Then Print alarmstr else print " " ?> <!--if an alarm present then display it (alarmstr); otherwise display nothing -->
</p> <!-- end of the paragraph, so all styles return to that of the left panel div -->
PondMode is <?BASIC print pondMode
If In(22) then print " opening" else print " closing"?> <br /> <!-- prints the pondmode (shutdown, wait, move regulation tap fast or slow, zero the tap stepper motor etc) -->
<table border="0"> <!-- so now we enter a table within the main table. This is just to right justify labels and values -->
<tr> <!-- row one -->
<td>Tap Position</td> <!-- Row1,Column1 Label -->
<td><?BASIC print TapPosition ?></td> <!-- R1,C2 Stepper motor on the tank outlet - this is the current position 0 - 19000 -->
</tr> <!-- row two -->
<tr> <!-- row two -->
<td>TapTarget</td>
<td><?BASIC print TapTarget ?></td> <!-- if you really want to knw the details you can go to my website steven.brazzale.org -->
</tr>
<tr>
<td>Average Tap Position</td>
<td><?BASIC print (AveTapPos128>>7) ?></td> <!-- I use the number on the end to indicate the scaling of the variable. The "average" the tapposition over 128 minutes by AVTP = AVTP - AVTP/128 + current tap position. So AVTP scale is 128 times the TP (so it all remains integer aritmetic -->
</tr>
<tr>
<td>Tap speed (steps per hour)</td>
<td><?BASIC If PndLvlTime >= 32 Then print SlowSpeed else print "0" ?></td>
</tr>
<tr style="color:#44aaff;">
<td>Av steps per hour</td>
<td><?BASIC print (Avstepshr512>>9) ?></td>
</tr>
<tr style="color:#44aaff;">
<td>Slow Speed</td>
<td><?BASIC print (SS) ?></td>
<td><input type="button" value="v" onclick="passwrd('gzfg');" /></td>
</tr>
<tr style="color:#44aaff;">
<td>Tap Boost</td>
<td><?BASIC print TapBoost ?></td>
<td><input type="button" value="v" onclick="passwrd('ezfg');" /></td>
</tr>
<tr style="color:#228888;"> <!-- All above are tap related. Now onto pond level switches so change colour so they're grouped -->
<td>Pond Switch</td>
<td><?BASIC print PondSw ?></td>
</tr>
<tr style="color:#228888;">
<td>Level History (cm)</td>
<td><?BASIC print " ";PondLevel(2);" ";PondLevel(1);" ";PondLevel(0) ?></td>
</tr>
<tr style="color:#228888;">
<td>At current level for(min)</td>
<td><?BASIC print PndLvlTime ?></td>
</tr>
<tr style="color:#5555ff;">
<td>Main Pump Duty</td>
<td><?BASIC If PumpDuty <= 3200 Then print (PumpDuty>>5) else print "" ?>%</td>
<?BASIC IF ((PumpStatus AND $04) = $04) Then Print "<td style =color:#66DDFF;text-decoration:blink;>on</td>" else print "<td style =color:#1666bb;>off</td>" ?>
<!-- note conditional prints can include HTML - if the pump is "on" it blinks a light blue, if "off" its a passive dull blue-->
</tr>
<tr style="color:#5555ff;">
<td>Stormwater Duty</td>
<td><?BASIC print (StmWtrDuty>>2) ?>/1000</td>
<?BASIC IF ((PumpStatus AND $02) = $02) Then Print "<td style =color:#66DDFF;text-decoration:blink;>on</td>" else print "<td style =color:#1666bb;>off</td>" ?>

</tr>
</table> <!-- end of data table -->
<br />
<a style="color:#777777;" href="help.htm"> help </a> <!-- link to help page -->
<!-- end of left panel of page -->
</div> <!-- closes the left panel; otherwise the next panel will go below this one -->
<div id="centrepanel" style="background-color:#00aa55;height:500px;width:290px;text-align:top;color:#000022;float:left;"> <!-- centre panel, floated left against previous panel-->
Heater Mode is <?BASIC print SolarMode ?>
<table border="0">
<tr>
<th>Temp </th>
<th style="text-align:left">Deg C</th>
</tr>
<tr>
<td>Upper </td>
<td style="text-align:left"><?BASIC print (UpperTemp4>>2);".";((UpperTemp4 MOD 4) * 25) ?></td>
</tr>
<tr>
<td>Lower </td>
<td style="text-align:left"><?BASIC print (LowerTemp4>>2);".";((LowerTemp4 MOD 4) * 25) ?></td>
</tr>
<tr>
<td>Outside </td>
<td style="text-align:left"><?BASIC print (OutsideTemp4>>2);".";((OutsideTemp4 MOD 4) * 25) ?></td>
</tr>
<tr>
<td>Solar </td>
<td style="text-align:left"><?BASIC print (SolarTemp4>>2);".";((SolarTemp4 MOD 4) * 25) ?></td>
</tr>
<tr>
<td>Cold Water </td>
<td style="text-align:left"><?BASIC print (HotWaterTemp4>>2);".";((HotWaterTemp4 MOD 4) * 25) ?></td>
</tr>
<tr>
<td>Garage </td>
<td style="text-align:left"><?BASIC print (GarageTemp4>>2);".";((GarageTemp4 MOD 4) * 25) ?></td>
</tr>
<tr>
<td>Solar cut-off.. </td>
<td style="text-align:left"><?BASIC print (TargetTemp8>>3)
If ((TargetTemp8 MOD 8) > 3) Then Print ".5" Else print ".0" ?></td>
</tr>
<tr>
<td>Desired </td>
<td style="text-align:left"><?BASIC print (DesiredTemp2 >> 1)
If (((DesiredTemp2) MOD 2) > 0) Then Print ".5" Else print ".0" ?></td>
<td><input type="button" value="+.5" onclick="passwrd('azfg');" /><input type="button" value="-.5" onclick="passwrd('bzfg');" /> </td>
</tr>
</table>



<p style="color:#0000ff;">
<?BASIC IF ((PumpStatus AND $01) = $01) Then Print "Fan Pump On <br />" else print "" ?>
<?BASIC IF ((PumpStatus AND $8) >= $8) Then Print "Tank FULL/ Top Ponds overflow<br />" else print ""?> </p>

<table border="2">
<tr>
<td><?BASIC print (WattHrs/45612),".", ((WattHrs/4561) MOD 10) ?> </td><td style="text-align:center">KWh used in </td><td><?BASIC print WattHrstimer ?> hr</td>
</tr>
<tr>
<td></td><td>Current usage</td><td><?BASIC print 20 * (PwrCnt(1)+PwrCnt(2)+PwrCnt(3)+PwrCnt(4)) ?> watt</td>
</tr>
<tr>
<td></td><td>Line Volatge is </td><td><?BASIC Print (ACinvoltage/29200),".",(ACinvoltage/2920) mod 10 ?>V</td>
</tr>
</table>

<br />Printing to right iframe ==><br /> <!--drop down list. Sends the number of the selection -->
<a style="color:#ddddff;">
<?BASIC IF PrintFlags = 0 Then Print "Only main events<br />" else print "" ?> <!--main program the sets flags on what to print -->
<?BASIC IF ((PrintFlags AND $01) = $01) Then Print "Second data<br />" else print "" ?> <!--print which flags are set -->
<?BASIC IF ((PrintFlags AND $02) = $02) Then Print "Pump data<br />" else print "" ?> <!-- Note the <br /> is in the if statement, else no newline is printed -->
<?BASIC IF ((PrintFlags AND $08) = $08) Then Print "Forcing time synch<br />" else print "" ?></a>
<form>
<select id="downloadselect" onchange="SelectResult();" > <!-- action done onchange, so first option must be nochange -->
<option>choose action below..</option> <!-- retrns 0 = the default option - if nothing else is selected, then this reamins, so there is no change -->
<option>Toggle Second data flag</option> <!-- executes SelectResult(1) prints data related to each second (power pulses from the pond pump power meter, tap position etc -->
<option>Toggle print Pump data flag</option> <!-- executes SelectResult(2) when different pumps are on/off -->
<option>Print daily stats</option> <!-- executes SelectResult(3) Energy used, solar energy gained, average inside/outside temperatures etc -->
<option>Print (next block) Hourly stats</option> <!-- 4 Temperatures -->
<option>Print (next block) Tap Events</option> <!-- 5 -->
<option>Force Time synch</option> <!-- 6 if hours/days/month/years don't match, my progrom won't allow automatic synch; This forces it -->
<option>Restart after error</option> <!-- 7 If ponds shut down due to lack of AC power, switch failure etc this restarts it -->
<option>Shut Down Ponds</option> <!-- 8 -->
<option>Freeze state for reprogramming</option> <!-- 9 Just added this to store the state of everything so I don't have do a whole shutdown/restart ech time I reprogram the ARMWeb -->
</select>

</form>

</div>
<div id="text" style="background-color:#444;height:500px;width:420px;text-align:top;color:#2288ff;float:left;"> <!--The iframe panel -->
<iframe align="bottom" width="420" height = "495" src = "txta.htm"></iframe> <!--and display texta.htm (ARMWebs print page) -->
</div>
</body>


</html>


And here is the basic subroutine that handles all the CGI input from the webpage
Web page input.bas
(5.53 KiB) Downloaded 380 times



Post Reply