Index: src/webapp/webservice/index.php
===================================================================
--- src/webapp/webservice/index.php	(revision 5519ced720fb38c5b38c6dedc224ade1d8f5e7d7)
+++ src/webapp/webservice/index.php	(revision c53f31a6bc677465032fb7237420e709c7980a70)
@@ -36,57 +36,17 @@
 );
 
-$debug = 0;
-if(array_key_exists("debug", $_GET))
-	$debug = $_GET["debug"];
+function addRrdData($interval, $period, &$result, &$lastTime){
+	global $dbFile;
+	global $debug;
+	global $configRound;
 
-$request = REQUEST_DATA;
-if(array_key_exists("request", $_GET)){
-	$request = $_GET["request"];
-}
-
-if($debug == 0)
-	header('Content-Type: application/json');
-
-$result = array();
-if($request == REQUEST_SHUTDOWN){
-	$handle = @fopen("/var/spool/gnuboat/gnuboat_shutdown", "w");
-	if($handle === false){
-		$message = "Could not create file to indicate shutdown to the daemon (Timezone: ". date_default_timezone_get() .")";
-		if($debug > 0)
-			echo $message;
-		error_log($message);
-		$result["shutdownstart"] = -1;
-		$shutdownTime = new DateTime('NOW');
-		$shutdownTime->modify("+60 seconds");
-		$result["shutdownstart"] = $shutdownTime->format(DateTime::ISO8601);
-	}
-	else{
-		$shutdownTime = new DateTime('NOW');
-		$shutdownTime>modify("+15 seconds");
-		fwrite($handle, $shutdownTime->format(DateTime::ISO8601));
-		$result["shutdownstart"] = $shutdownTime->format(DateTime::ISO8601);
-	}
-}
-elseif($request == REQUEST_DATA){
-	$result["lastvalid"] = array();
-	$result["track"] = array();
-
-	if(!file_exists($dbFile)){
-		echo json_encode("");
-		if($debug > 0)
-			echo "Database file ". $dbFile ." does not exist!";
-		error_log("Database file ". $dbFile ." does not exist");
-		exit;
-	}
-	// Fetch entries of the last 12hours
-	$data = rrd_fetch($dbFile, array( "AVERAGE", "--resolution", "5", "--start", "-12h"));
+	$data = rrd_fetch($dbFile, array( "AVERAGE", "--resolution", $interval, "--start", "-". $period, "--end", "start+". $period));
 	if($data === false){
 		echo json_encode($result);
-		$message = "Could not open rrd database ". $dbFile; 
+		$message = "Failure reading rrd database ". $dbFile .": ". rrd_error(); 
 		if($debug > 0)
 			echo $message;
 		else
 			error_log($message);
-		exit;
 	}
 
@@ -107,4 +67,7 @@
 		echo json_encode("");
 		exit;
+	}
+	if($debug > 0){
+		echo "<p>Variables: ". count($keys) ."; Timeframes: ". count($data[$keys[0]]) ."</p>\n";
 	}
 	for($i = 0; $i < count($data[$keys[0]]); $i++){
@@ -136,9 +99,12 @@
 		// only add the timeframe to the track, if the values are valid and we had a gps fix at that time
 		if($allValid && $tmp["gpsfix"] != "-"){
-			$result["track"][$time] = $tmp;
+			echo "want to add ". $time ."<br/>\n";
+			if(!array_key_exists($time, $result["track"])){
+				$result["track"][$time] = $tmp;
+			}
 			$lastTime = $time;
 		}
 		else{
-			if($debug > 0){
+			if($debug > 1){
 				echo "Failed <pre>";
 				var_dump($tmp);
@@ -147,7 +113,55 @@
 		}
 	}
+	
+ 	ksort($result["track"]);
+}
+
+$debug = 0;
+if(array_key_exists("debug", $_GET))
+	$debug = $_GET["debug"];
+
+$request = REQUEST_DATA;
+if(array_key_exists("request", $_GET)){
+	$request = $_GET["request"];
+}
+
+if($debug == 0)
+	header('Content-Type: application/json');
+
+$result = array();
+if($request == REQUEST_SHUTDOWN){
+	$handle = @fopen("/var/spool/gnuboat/gnuboat_shutdown", "w");
+	if($handle === false){
+		$message = "Could not create file to indicate shutdown to the daemon (Timezone: ". date_default_timezone_get() .")";
+		if($debug > 0)
+			echo $message;
+		error_log($message);
+		$result["shutdownstart"] = -1;
+	}
+	else{
+		$shutdownTime = new DateTime('NOW');
+		$shutdownTime>modify("+15 seconds");
+		fwrite($handle, $shutdownTime->format(DateTime::ISO8601));
+		$result["shutdownstart"] = $shutdownTime->format(DateTime::ISO8601);
+	}
+}
+elseif($request == REQUEST_DATA){
+	$result["lastvalid"] = array();
+	$result["track"] = array();
+
+	if(!file_exists($dbFile)){
+		echo json_encode("");
+		if($debug > 0)
+			echo "Database file ". $dbFile ." does not exist!";
+		error_log("Database file ". $dbFile ." does not exist");
+		exit;
+	}
+	// Fetch entries of the last 30 seconds
+	addRrdData("5s", "30s", $result, $lastTime);
 	if($lastTime > -1){
 		$result["lastvalid"] = $result["track"][$lastTime];
 	}
+ 	addRrdData("15s", "5minutes", $result, $lastTime);
+ 	addRrdData("30s", "12h", $result, $lastTime);
 }
 
