94 lines
2.9 KiB
PHP
94 lines
2.9 KiB
PHP
<?php
|
|
ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
error_reporting(E_ALL);
|
|
?>
|
|
|
|
<?php include('partialpage/header.php');?>
|
|
<?php include('partialpage/sidebar.php');?>
|
|
|
|
<script>
|
|
$( document ).ready(function() {
|
|
if(typeof(EventSource) !== "undefined") {
|
|
var relaystatus = new EventSource("helperpage/relaystatus.php");
|
|
relaystatus.onmessage = function(event) {
|
|
obj = JSON.parse(event.data);
|
|
for (i = 0; i < 8; i++) {
|
|
htmlcode = "<div class='w3-col m12 l4 w3-margin-bottom'>";
|
|
if (obj[i] == "0"){
|
|
htmlcode = htmlcode + "<div class='w3-container w3-red'>";
|
|
}else if(obj[i] == "1"){
|
|
htmlcode = htmlcode + "<div class='w3-container w3-green'>";
|
|
}else{
|
|
htmlcode = htmlcode + "<div class='w3-container w3-orange'>";
|
|
htmlcode = htmlcode + "<h1>Error: " + obj[i] + "</h1>";
|
|
}
|
|
htmlcode = htmlcode + "<h2 class='w3-opacity'><b>Relay " + (i+1) + "</b></h2>";
|
|
if(obj[i] == "0"){
|
|
htmlcode = htmlcode + "<img src='/images/open-switch.png' alt='Switch Open' style='width:50%'><h3>Open</h3>";
|
|
}else if(obj[i] == "1"){
|
|
htmlcode = htmlcode + "<img src='/images/closed-switch.png' alt='Switch Closed' style='width:50%'><h3>Closed</h3>";
|
|
}
|
|
htmlcode = htmlcode + "</div></div>";
|
|
$("#relay" + (i+1)).html(htmlcode);
|
|
}
|
|
};
|
|
} else {
|
|
$("#error").text("browser not supported, no auto updates");
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<!-- !PAGE CONTENT! -->
|
|
<div class="w3-main" style="margin-left:340px;margin-right:40px">
|
|
|
|
<!-- Relay Header -->
|
|
<div class="w3-container" id="Relays" style="margin-top:75px">
|
|
<h1 class="w3-jumbo"><b>Relays</b></h1>
|
|
<br>
|
|
<div style="border:5px solid red; width:100px" class="w3-round"></div>
|
|
<br>
|
|
<p>Relays on the board.</p>
|
|
<p id="error"></p>
|
|
</div>
|
|
|
|
<?php
|
|
function relayblock($number, $pin){
|
|
echo "<!-- relay $number -->";
|
|
echo "<div class='w3-row-padding' id='relay$number'>";
|
|
echo "<div class='w3-col m4 w3-margin-bottom'>";
|
|
$command = "cat /sys/class/gpio/pioC$pin/value 2>&1";
|
|
$value = exec($command);
|
|
if ($value == "0"){
|
|
echo "<div class='w3-container w3-red'>";
|
|
}elseif($value == "1"){
|
|
echo "<div class='w3-container w3-green'>";
|
|
}else{
|
|
echo "<div class='w3-container w3-orange'>";
|
|
echo "<h1>Error: $value </h1>";
|
|
}
|
|
echo "<h2 class='w3-opacity'><b>Relay $number</b></h2>";
|
|
|
|
if($value == "0"){
|
|
echo "<img src='/images/open-switch.png' alt='Switch Open' style='width:50%'><h3>Open</h3>";
|
|
}elseif($value == "1"){
|
|
echo "<img src='/images/closed-switch.png' alt='Switch Closed' style='width:50%'><h3>Closed</h3>";
|
|
}
|
|
echo "</div></div></div>";
|
|
echo "\n";
|
|
}
|
|
relayblock("1", "17");
|
|
relayblock("2", "16");
|
|
relayblock("3", "15");
|
|
relayblock("4", "14");
|
|
relayblock("5", "19");
|
|
relayblock("6", "20");
|
|
relayblock("7", "12");
|
|
relayblock("8", "13");
|
|
?>
|
|
|
|
<!-- End page content -->
|
|
</div>
|
|
|
|
<?php include('partialpage/footer.php');?>
|