Index: webapp/webservice/index.php
===================================================================
--- webapp/webservice/index.php	(revision 36be960b88f24d18f9964c350b6543a8cc4fdabd)
+++ webapp/webservice/index.php	(revision 1fec879a9d6689dff57c972a68369089f76f5de4)
@@ -17,13 +17,96 @@
 */
 
-mt_srand(microtime());
+/**
+  * The GPSD parts are adepted from the gpsd.php script deployed with GPSD package!
+  */
+
+$gpsdHost = "localhost";
+$gpsdPort = "2947";
+
+set_time_limit(3);
+ini_set('max_execution_time', 3);
+
+function readGpsd(){
+	global $gpsdHost, $gpsdPort;
+
+	
+	$speedOverGround = "-";
+	$gpsfix = "-";
+	$errno = "";
+	$errstr = "";
+	
+	$sock = @fsockopen($gpsdHost, $gpsdPort, $errno, $errstr, 2);
+	if(!$sock){
+		$speedOverGround = "-";
+		$gpsfix = -1; 
+	}
+	@fwrite($sock, "?WATCH={\"enable\":true}\n");
+	usleep(1000);
+	@fwrite($sock, "?POLL;\n");
+	usleep(1000);
+	for($tries = 0; $tries < 10; $tries++){
+		$response = @fread($sock, 2000); # SKY can be pretty big
+		if (preg_match('/{"class":"POLL".+}/i', $response, $m)){
+			$response = $m[0];
+			break;
+		}
+	}
+	@fclose($sock);
+	if(!$response){
+		$speedOverGround = "-";
+		$gpsfix = -2; 
+	}
+	else{
+		$data = json_decode($response, true);
+		if ($data['class'] != 'POLL'){
+			$speedOverGround = "-";
+			$gpsfix = -3; 
+		}
+		if(!array_key_exists('tpv', $data) && is_array($data['tpv'])){
+			$speedOverGround = "-";
+			$gpsfix = -4;
+		}
+		$tpv = $data['tpv'][0];
+
+		if(!array_key_exists('mode', $tpv)){
+			$gpsfix = -5;
+		}
+		else{
+			switch($tpv['mode']){
+				case 1:
+					$gpsfix = "2D";
+					break;
+				case 2:
+					$gpsfix = "3D";
+					break;
+				default:
+					$gpsfix = "-";
+			}
+		}
+		
+		if(!array_key_exists('speed', $tpv)){
+			$speedOverGround = "-1";
+		}
+		else{
+			$speedOverGround = $tpv['speed'];
+		}
+	}
+	
+	return array("speedOverGround" => $speedOverGround, "gpsfix" => $gpsfix);
+}
+
+
+
+mt_srand((double) microtime() * 1000000);
 
 $result = array();
 
+$gpsdResult = readGpsd();
+
 $result["speedthroughwater"] = mt_rand(0, 10);
-$result["speedoverground"] = mt_rand(0, 5);
-$result["waterdepth"] = mt_rand(1, 30);
-$result["watertemperature"] = mt_rand(15, 25);
-$result["satellites"] = mt_rand(0, 10);
+$result["speedoverground"] = $gpsdResult["speedOverGround"];
+$result["waterdepth"] = mt_rand(1, 30) + 0.5;
+$result["watertemperature"] = mt_rand(15, 25) + 0.5;
+$result["gpsfix"] = $gpsdResult["gpsfix"];
 
 echo json_encode($result);
