Basic web idea

Fri, 11 Jul 2014 22:53:33 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 11 Jul 2014 22:53:33 +0200
changeset 100
012576d7386d
parent 99
5dccd1d8d817
child 101
1302abe92eb1

Basic web idea

thermferm/server.c file | annotate | diff | comparison | revisions
www-thermferm/css/style.css file | annotate | diff | comparison | revisions
www-thermferm/images/Fermenter_60l.gif file | annotate | diff | comparison | revisions
www-thermferm/images/thermferm_logo.png file | annotate | diff | comparison | revisions
www-thermferm/index.php file | annotate | diff | comparison | revisions
www-thermferm/liveview.php file | annotate | diff | comparison | revisions
www-thermferm/thermferm_logo.png file | annotate | diff | comparison | revisions
www-thermferm/utilities.php file | annotate | diff | comparison | revisions
--- a/thermferm/server.c	Fri Jul 11 13:29:26 2014 +0200
+++ b/thermferm/server.c	Fri Jul 11 22:53:33 2014 +0200
@@ -209,7 +209,7 @@
 	i = 0;
 	for (unit = Config.units; unit; unit = unit->next) {
 	    i++;
-	    srv_send((char *)"%02d %s %-20s %-7s", i, unit->uuid, unit->name, UNITMODE[unit->mode]);
+	    srv_send((char *)"%d,%s,%s,%s", i, unit->uuid, unit->name, UNITMODE[unit->mode]);
 	}
 	srv_send((char *)".");
 	return 0;
@@ -223,17 +223,17 @@
 	    while ((de = readdir(fd))) {
 		if (de->d_name[0] != '.') {
 		    if (strncmp(de->d_name, (char *)"w1", 2) == 0) {
-			srv_send((char *)"%-15s       system device", de->d_name);
+			srv_send((char *)"%s,N/A,System device", de->d_name);
 		    } else if (strncmp(de->d_name, (char *)"10", 2) == 0) {
-			srv_send((char *)"%-15s 18S20 digital thermometer", de->d_name);
+			srv_send((char *)"%s,18S20,Digital thermometer", de->d_name);
 		    } else if (strncmp(de->d_name, (char *)"28", 2) == 0) {
-			srv_send((char *)"%-15s 18B20 digital thermometer", de->d_name);
+			srv_send((char *)"%s,18B20,Digital thermometer", de->d_name);
 		    } else if (strncmp(de->d_name, (char *)"29", 2) == 0) {
-			srv_send((char *)"%-15s 2408  8-channel addressable switch/LCD", de->d_name);
+			srv_send((char *)"%s,2408,8 Channel addressable switch/LCD", de->d_name);
 		    } else if (strncmp(de->d_name, (char *)"3a", 2) == 0) {
-			srv_send((char *)"%-15s 2413  dual channel addressable switchs", de->d_name);
+			srv_send((char *)"%s,2413,Dual channel addressable switchs", de->d_name);
 		    } else {
-			srv_send((char *)"%-15s       unknown device", de->d_name);
+			srv_send((char *)"%s,N/A,Unknown device", de->d_name);
 		    }
 		}
 	    }
@@ -253,7 +253,7 @@
 	i = 0;
 	for (profile = Config.profiles; profile; profile = profile->next) {
 	    i++;
-	    srv_send((char *)"%02d %s %s", i, profile->uuid, profile->name);
+	    srv_send((char *)"%d,%s,%s", i, profile->uuid, profile->name);
 	}
 	srv_send((char *)".");
 	return 0;
@@ -272,39 +272,41 @@
 	for (unit = Config.units; unit; unit = unit->next) {
 	    i++;
 	    if (i == current_unit) {
-		srv_send((char *)"Name of the unit/beer      %s", unit->name);
-		srv_send((char *)"UUID of this unit          %s", unit->uuid);
+		srv_send((char *)"NAME,%s", unit->name);
+		srv_send((char *)"UUID,%s", unit->uuid);
 		if (unit->air_address) {
-		    srv_send((char *)"1-wire address air sensor  %s", unit->air_address);
-		    srv_send((char *)"Air temperature            %.1f", unit->air_temp);
+		    srv_send((char *)"AIR_ADDRESS,%s", unit->air_address);
+		    srv_send((char *)"AIR_TEMP,%.1f", unit->air_temp);
 		}
 		if (unit->beer_address) {
-		    srv_send((char *)"1-wire address beer sensor %s", unit->air_address);
-		    srv_send((char *)"Beer temperature           %.1f", unit->air_temp);
+		    srv_send((char *)"BEER_ADDRESS,%s", unit->beer_address);
+		    srv_send((char *)"BEER_TEMP,%.1f", unit->beer_temp);
 		}
 		if (unit->io1_address) {
-		    srv_send((char *)"1-wire address cool/heat   %s", unit->io1_address);
+		    srv_send((char *)"IO1_ADDRESS,%s", unit->io1_address);
 		}
 		if (unit->io2_address) {
-		    srv_send((char *)"1-wire address fan/door    %s", unit->io2_address);
+		    srv_send((char *)"IO2_ADDRESS,%s", unit->io2_address);
 		}
 		if (unit->heater_available) {
-		    srv_send((char *)"Heater available           %s", unit->heater_available);
+		    srv_send((char *)"HEATER_AVAILABLE,%s", unit->heater_available);
 		}
 		if (unit->cooler_available) {
-		    srv_send((char *)"Cooler available           %s", unit->cooler_available);
+		    srv_send((char *)"COOLER_AVAILABLE,%s", unit->cooler_available);
 		}
 		if (unit->fan_available) {
-		    srv_send((char *)"Fan available              %s", unit->fan_available);
+		    srv_send((char *)"FAN_AVAILABLE,%s", unit->fan_available);
 		}
-		srv_send((char *)"Unit mode                  %s", UNITMODE[unit->mode]);
-		srv_send((char *)"Fridge temperature set to  %.1f", unit->fridge_set);
-		srv_send((char *)"Beer temperature set to    %.1f", unit->beer_set);
+		srv_send((char *)"MODE,%s", UNITMODE[unit->mode]);
+		srv_send((char *)"FRIDGE_SET,%.1f", unit->fridge_set);
+		srv_send((char *)"BEER_SET,%.1f", unit->beer_set);
 		if (unit->profile) {
-		    srv_send((char *)"Profile name               %s", unit->profile);
+		    srv_send((char *)"PROFILE,%s", unit->profile);
 		}
-		srv_send((char *)"Temperature range          %.1f .. %.1f", unit->temp_set_min, unit->temp_set_max);
-		srv_send((char *)"Idle temperature range     %.1f .. %.1f", unit->idle_rangeL, unit->idle_rangeH);
+		srv_send((char *)"TEMP_SET_MIN,%.1f", unit->temp_set_min);
+		srv_send((char *)"TEMP_SET_MAX,%.1f", unit->temp_set_max);
+		srv_send((char *)"IDLE_RANGE_L,%.1f", unit->idle_rangeL);
+		srv_send((char *)"IDLE_RANGE_H,%.1f", unit->idle_rangeH);
 	    }
 	}
 	srv_send((char *)".");
--- a/www-thermferm/css/style.css	Fri Jul 11 13:29:26 2014 +0200
+++ b/www-thermferm/css/style.css	Fri Jul 11 22:53:33 2014 +0200
@@ -36,7 +36,7 @@
 #container {
     width: 980px;
     height: 510px;
-    background: #7ff;
+    background: #ddd;
     margin-bottom: 10px;
     float: left;
 }
@@ -44,7 +44,7 @@
 #header {
     width: 968px;
     height: 90px;
-    background: #ff7;
+    background: #222;
     margin: 5px;
     float: left;
 }
@@ -62,8 +62,40 @@
 #content {
     width: 968px;
     height: 400px;
-    background: #f7f;
+    background: #fff;
+    margin: 5px;
+    float: left;
+}
+
+
+#fermentor {
+    border: 5px solid;
+    border-color: #FFCC01;
+    border-radius: 15px 15px 15px 15px;
+    height: 380px;
+    width: 464px;
+    background: #fff;
     margin: 5px;
     float: left;
 }
 
+#fermentor_head {
+    margin-bottom: 1px;
+    padding: 3px 10px 8px;
+    background-color: #FFCC01;
+    color: #666666;
+    font-weight: bold;
+}
+
+#fermentor_pict {
+    width: 220px;
+    height: 350px;
+    float: left;
+}
+
+#fermentor_control {
+    width: 240px;
+    height: 350px;
+    float: right;
+}
+
Binary file www-thermferm/images/Fermenter_60l.gif has changed
Binary file www-thermferm/images/thermferm_logo.png has changed
--- a/www-thermferm/index.php	Fri Jul 11 13:29:26 2014 +0200
+++ b/www-thermferm/index.php	Fri Jul 11 22:53:33 2014 +0200
@@ -22,6 +22,9 @@
  *****************************************************************************/
 
 
+require_once('liveview.php');
+
+
 $outstr  = '<!DOCTYPE html>'.PHP_EOL;
 $outstr .= '<html>'.PHP_EOL;
 $outstr .= ' <head>'.PHP_EOL;
@@ -33,13 +36,13 @@
 $outstr .= '  <div id="container" class="container_16">'.PHP_EOL;
 $outstr .= '   <div id="header">'.PHP_EOL;
 $outstr .= '    <div id="logo">'.PHP_EOL;
-$outstr .= '     <img src="thermferm_logo.png" width="94" height="80">'.PHP_EOL;
+$outstr .= '     <img src="images/thermferm_logo.png" width="94" height="80">'.PHP_EOL;
 $outstr .= '    </div>'.PHP_EOL;
 $outstr .= '    <button class="script-status ui-state-error"></button>'.PHP_EOL;
 $outstr .= '    <button id="maintenance" class="ui-state-default">Maintenance panel</button>'.PHP_EOL;
 $outstr .= '   </div> <!-- header -->'.PHP_EOL;
 $outstr .= '   <div id="content">'.PHP_EOL;
-$outstr .= '    Content deel'.PHP_EOL;
+$outstr .= liveview();
 $outstr .= '   </div> <!-- content -->'.PHP_EOL;
 $outstr .= '  </div> <!-- container -->'.PHP_EOL;
 $outstr .= ' </body>'.PHP_EOL;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www-thermferm/liveview.php	Fri Jul 11 22:53:33 2014 +0200
@@ -0,0 +1,135 @@
+<?php
+/*****************************************************************************
+ * Copyright (C) 2014
+ *   
+ * Michiel Broek <mbroek at mbse dot eu>
+ *
+ * This file is part of ThermFerm
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * ThermFerm is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with ThermFerm; see the file COPYING.  If not, write to the Free
+ * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *****************************************************************************/
+
+
+require_once('utilities.php');
+
+
+
+function showunit($unit)
+{
+    $outstr = '';
+
+    $sock = open_socket();
+    if ($sock == false) {
+	return '';
+    }
+
+    socket_write($sock, "UNIT " . $unit, 4096);
+    $answer = "";
+    while (1) {
+	$line = socket_read($sock, 4096);
+	if ($line === '')
+		break;
+	$answer .= $line;
+    }
+    socket_close($sock);
+
+    $sock = open_socket();
+    if ($sock == false) {
+	return '';
+    }
+
+    socket_write($sock, "LIST UNIT", 4096);
+    $answer = "";
+    while (1) {
+	$line = socket_read($sock, 4096);
+	if ($line === '')
+	    break;
+	$answer .= $line;
+    }
+    socket_close($sock);
+    $arr = explode("\r\n", $answer);
+
+    if (startsWith($arr[0], "213")) {
+
+	$outstr .= '    <div id="fermentor">'.PHP_EOL;
+
+	foreach($arr as $l) {
+	    $vals = explode(",", $l);
+	    if (strcmp($vals[0], "NAME") == 0) {
+		/*
+		 * The name is allways first, so when we have it
+		 * emit the formatting.
+		 */
+		$outstr .= '     <div id="fermentor_head">'.PHP_EOL;
+		$outstr .= '      ' . $vals[1] .PHP_EOL;
+		$outstr .= '     </div>'.PHP_EOL;
+		$outstr .= '     <div id="fermentor_pict">'.PHP_EOL;
+		$outstr .= '      <img src="images/Fermenter_60l.gif">'.PHP_EOL;
+		$outstr .= '     </div>'.PHP_EOL;
+		$outstr .= '     <div id="fermentor_control">'.PHP_EOL;
+	    }
+	    if (strcmp($vals[0], "MODE") == 0) {
+		$outstr .= '      mode ' . $vals[1] . '<br>' .PHP_EOL;
+	    }
+	}
+	$outstr .= '      temp 12.3'.PHP_EOL;
+	$outstr .= '     </div>'.PHP_EOL;
+    	$outstr .= '    </div>'.PHP_EOL;
+    }
+
+    return $outstr;
+}
+
+
+
+function liveview()
+{
+    $outstr  = PHP_EOL;
+
+    $sock = open_socket();
+    if ($sock !== false) {
+	socket_write($sock, "LIST", 4096);
+
+	/*
+	 * Multiple reads until the remote closed the connection
+	 */
+	$answer = "";
+	while (1) {
+	    $line = socket_read($sock, 4096);
+	    if ($line === '')
+		break;
+	    $answer .= $line;
+	}
+	socket_close($sock);
+	$arr = explode("\r\n", $answer);
+
+	if (startsWith($arr[0], "212")) {
+	    $i = 1;
+	    while (1) {
+		if (strcmp($arr[$i], ".") == 0)
+			break;
+		$parts = explode(",", $arr[$i]);
+		$outstr .= showunit($parts[1]);
+		$i++;
+	    }
+	}
+    }
+
+    return $outstr;
+}
+
+
+
+?>
Binary file www-thermferm/thermferm_logo.png has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www-thermferm/utilities.php	Fri Jul 11 22:53:33 2014 +0200
@@ -0,0 +1,46 @@
+<?php
+/*****************************************************************************
+ * Copyright (C) 2014
+ *   
+ * Michiel Broek <mbroek at mbse dot eu>
+ *
+ * This file is part of ThermFerm
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * ThermFerm is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with ThermFerm; see the file COPYING.  If not, write to the Free
+ * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *****************************************************************************/
+
+
+function open_socket()
+{
+    $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
+
+    if (!($sock === false)) {
+	if (socket_connect($sock, "localhost", 6554)) {
+	    socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 15, 'usec' => 0));
+	} else {
+	    socket_close($sock);
+    	}
+    }
+    return $sock;
+}
+
+
+
+function startsWith($haystack, $needle)
+{
+    return !strncmp($haystack, $needle, strlen($needle));
+}
+
+

mercurial