Skip to content

Commit

Permalink
webinterface: add comments, update layout
Browse files Browse the repository at this point in the history
* added a lot of comments to increase readability
* updated layout, it is now possible to create empty boxes
  • Loading branch information
xkonni committed Nov 25, 2012
1 parent e0caf86 commit d388fc2
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 27 deletions.
28 changes: 24 additions & 4 deletions webinterface/config.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
<?php
/*
* Raspberry Remote
* http://xkonni.github.com/raspberry-remote/
*
* configuration for the webinterface
*
*/

/*
* define ip address and port here
*/
$source = $_SERVER['SERVER_ADDR'];
$target = '192.168.11.124';
$port = 11337;

/*
* specify configuration of sockets to use
* array("group", "plug", "description");
* use empty string to create empty box
* ""
*
*/
$config=array(
array("00001", "01", "Schreibtisch"),
array("00001", "02", "Sofa"),
array("00010", "01", "Schreibtisch"),
array("00010", "02", "Laptop"),
"",
"",
array("00001", "01", "Sofa Lampe"),
array("00001", "02", "Sofa Steckdose"),
array("00001", "03", "TV"),
array("00001", "04", "Verstaerker"),
array("00010", "05", "Bla"),
array("00011", "01", "Blob")
)
?>
76 changes: 53 additions & 23 deletions webinterface/index.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
<?php
/*
* Raspberry Remote
* http://xkonni.github.com/raspberry-remote/
*
* webinterface
*
*/

/*
* get configuration
* don't forget to edit config.php
*/
include("config.php");
// config

/*
* get parameters
*/
if (isset($_GET['group'])) $nGroup=$_GET['group'];
else $nGroup="";
if (isset($_GET['switch'])) $nSwitch=$_GET['switch'];
Expand All @@ -12,7 +26,11 @@
else $nDelay=0;


// actually send
/*
* actually send to the daemon
* then reload the webpage without parameters
* except for delay
*/
$output = $nGroup.$nSwitch.$nAction.$nDelay;
if (strlen($output) >= 8) {
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("Could not create socket\n");
Expand Down Expand Up @@ -41,6 +59,9 @@
</head>
<body>
<?php
/*
* links to change the delay
*/
echo "<P>Delay: ";
echo "<A";
if ($nDelay == 0) echo " class=\"bold\"";
Expand All @@ -59,31 +80,36 @@
echo " HREF=\"index.php?delay=60\">60</A> ";
echo "</P>";

/*
* table containing all configured sockets
*/
$index=0;
echo "<TABLE BORDER=\"0\">\n";
foreach($config as $current) {
$ig = $current[0];
$is = $current[1];
$id = $current[2];
if ($current != "") {
$ig = $current[0];
$is = $current[1];
$id = $current[2];

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("Could not create socket\n");
socket_bind($socket, $source) or die("Could not bind to socket\n");
socket_connect($socket, $target, $port) or die("Could not connect to socket\n");
if ($index%2 == 0) echo "<TR>\n";

$output = $ig.$is."2";
socket_write($socket, $output, strlen ($output)) or die("Could not write output\n");
$state = socket_read($socket, 2048);
if ($state == 0) {
$color=" BGCOLOR=\"#C00000\"";
$ia = 1;
$direction="on";
}
if ($state == 1) {
$color=" BGCOLOR=\"#00C000\"";
$ia = 0;
$direction="off";
}
if ($index%2 == 0) echo "<TR>\n";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("Could not create socket\n");
socket_bind($socket, $source) or die("Could not bind to socket\n");
socket_connect($socket, $target, $port) or die("Could not connect to socket\n");

$output = $ig.$is."2";
socket_write($socket, $output, strlen ($output)) or die("Could not write output\n");
$state = socket_read($socket, 2048);
if ($state == 0) {
$color=" BGCOLOR=\"#C00000\"";
$ia = 1;
$direction="on";
}
if ($state == 1) {
$color=" BGCOLOR=\"#00C000\"";
$ia = 0;
$direction="off";
}
echo "<TD class=outer ".$color.">\n";
echo "<TABLE><TR><TD class=inner BGCOLOR=\"#000000\">";
echo "<A CLASS=\"".$direction."\" HREF=\"?group=".$ig;
Expand All @@ -97,9 +123,13 @@
echo "</TD>";
echo "</TR></TABLE>\n";
echo "</TD>\n";
socket_close($socket);
}
else {
echo "<TD></TD>\n";
}
if ($index%2 == 1) echo "</TR>\n";
$index++;
socket_close($socket);
}
echo "</TR></TABLE>";
?>
Expand Down

0 comments on commit d388fc2

Please sign in to comment.