www-thermferm/liveview.php

changeset 196
4d7a96c5d1ff
parent 195
b34a1b2421fb
child 219
ae720212accc
--- a/www-thermferm/liveview.php	Fri Aug 08 23:07:44 2014 +0200
+++ b/www-thermferm/liveview.php	Sat Aug 09 11:29:02 2014 +0200
@@ -32,21 +32,7 @@
 
     $outstr = '';
     $air_state = $beer_state = 1;
-
-    $sock = open_socket();
-    if ($sock == false) {
-	return '';
-    }
-
-    socket_write($sock, "UNIT GET ".$unit, 4096);
-    $answer = "";
-    while (1) {
-	$line = socket_read($sock, 4096);
-	if ($line === '')
-	    break;
-	$answer .= $line;
-    }
-    socket_close($sock);
+    $answer = send_cmd("UNIT GET ".$unit);
     $arr = explode("\r\n", $answer);
 
     if (startsWith($arr[0], "213")) {
@@ -235,19 +221,8 @@
 	    /*
 	     * First, load a list with available profiles.
 	     */
-	    $sock = open_socket();
-	    if ($sock == true) {
-	    	socket_write($sock, "PROFILE LIST", 4096);
-	    	$answer = "";
-	    	while (1) {
-		    $line = socket_read($sock, 4096);
-		    if ($line === '')
-			break;
-		    $answer .= $line;
-	    	}
-	    	socket_close($sock);
-	    	$reply = explode("\r\n", $answer);
-	    }
+	    $answer = send_cmd("PROFILE LIST");
+	    $reply = explode("\r\n", $answer);
 
 	    /*
 	     * Show loaded profile.
@@ -379,21 +354,8 @@
 {
     $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);
+    $answer = send_cmd("LIST");
+    if (strlen($answer)) {
 	$arr = explode("\r\n", $answer);
 
 	$outstr .= '   <div id="jqxTabs">'.PHP_EOL;

mercurial