Also ich habe die Original Php vom Hersteller genommen, und modifiziert um die SQL Funktionalität zu bekommen. Die Fehlermeldung am iPhone ist damit weg:
- utrackme.php Empfängt die Daten vom Iphone
<?
/*
* This is a simple php frontend implementing the uTrackMe web API to provide
* a multi-user tracking service.
*
* It uses a file to store the last known locations. This script requires
* php 4.3 or higher.
*/
/* Init globals */
// SQL Datenbank Zugriffsdaten und Gerätename bitte
$MySQLHost="127.0.0.1";
$username="dbuser";
$password="dbpass";
// ---------------------------
$data_file_path="utrackme_data_store.txt";
$_DATA = array();
/* -------------------------------------------------------------------- */
function store_location_data($ID_KEY)
/*
* Description: Store the newly received location information in the session cache.
* Params : [in] ID_KEY
* Global : [in/out] SESSION
* [in] REQUEST
*/
{
global $_DATA;
global $_REQUEST;
/*
* Get the SESSION data array for this device;
* if it doesn't exist yet create a new array.
*/
if (isset($_DATA[$ID_KEY])) $data = $_DATA[$ID_KEY];
else $data = array();
/*
* Copy the data from the REQUEST into the session data array.
*
* Store the last location, but only if at least one was supplied.
* uTrackMe does not send a location when the device doesn't have
* a location fix or the location didn't change since the last request.
* (Note: The rest of the track log is ignored in this script.)
*/
$data["time"] = time();
$data["id"] = $_REQUEST['id'];
$data["lock"] = $_REQUEST['lk'];
if ($_REQUEST['lk'] == 1) $data["lastlocktime"] = time();
if (isset($_REQUEST["nm"])) $data["device_name"] = $_REQUEST['nm'];
if (isset($_REQUEST["d"])) $data["location"] = end($_REQUEST['d']);
/* Copy the data array back into the SESSION data. */
$_DATA[$ID_KEY] = $data;
}
/* -------------------------------------------------------------------- */
function output_location_data_plist($CUR_ID_KEY = "")
/*
* Description: Output the location data stored in the session cache of
* all devices in text plist format (uTrackMe also supports
* XML format)
*
* (
* {
* id = "0000000";
* tm = 1234567890;
* nm = "iPhone";
* lk = 1;
* d = 1234567890,37.331689,-122.030731,100,-1,-1;
* },
* ... etc ...
* )
*
* Params : [in] CUR_ID_KEY
* Global : [in] SESSION
*/
{
global $_DATA;
foreach( $_DATA as $ID_KEY => $data)
{
if (($ID_KEY == $CUR_ID_KEY) || (!isset($data["id"]))) continue;
/* Output the plist */
$response .= " {
";
$response .= " id = \"".addslashes($data["id"])."\";
";
$response .= " tm = ".$data["time"].";
";
$response .= " nm = \"".addslashes($data["device_name"])."\";
";
$response .= " lk = \"".addslashes($data["lock"])."\";
";
if (isset($data["lastlocktime"])) $response .= " ll = ".$data["lastlocktime"].";
";
if (isset($data["location"])) $response .= " d = \"".addslashes($data["location"])."\";
";
$response .= " },
";
}
return $response;
}
/* -------------------------------------------------------------------- */
/* MAIN */
/* -------------------------------------------------------------------- */
header("content-type:text/plain");
/* Open/create data from file */
if (file_exists($data_file_path))
{
$fp = fopen($data_file_path, "r+");
$contents = '';
while (!feof($fp)) $contents .= fread($fp, 8192);
$_DATA = unserialize($contents);
}
else
{
$fp = fopen($data_file_path, "w");
}
flock($fp, LOCK_EX) or die ("Failed to lock file"); // do an exclusive lock
/* Get the name and version number for the user agent */
$arr = explode(" ", $_SERVER['HTTP_USER_AGENT']);
$arr = explode("/", $arr[0]);
$app=$arr[0];
$version=str_replace(".", "", $arr[1]);
if (isset($_REQUEST["id"]))
{
/* Store the calling device's location information */
store_location_data($_REQUEST["id"]);
}
/* Response begins with "OK". Start plist output */
$response = "OK
(
";
/* Output location information of all devices this script is tracking */
if ($app != "utmBeacon")
{
$response .= output_location_data_plist($_REQUEST["id"]);
}
/*
* Add a welcome message;
*/
//if ( $_REQUEST["nr"] == 1 )
//{
// $msg = "thanx";
// $response .= " {
msg = \"".addslashes($msg)."\";
},
";
//}
/* Close plist output */
$response .= ")
";
/* Write data back and close file */
fseek($fp, 0);
fwrite($fp, serialize($_DATA));
flock($fp, LOCK_UN); // release the lock
fclose($fp);
$number = $_REQUEST['nr'];
$iudid = $_REQUEST['id'];
$devicename = $_REQUEST['nm'];
$locationlock = $_REQUEST['lk'];
$location = $_REQUEST['d'];
foreach ($location as $value)
{
$locationarray = explode(",", $value);
$date = date("Ymd", $locationarray[0]);
$time = date("His", $locationarray[0]);
$latitude = $locationarray[1];
$longitude = $locationarray[2];
$accuracy = $locationarray[3];
$speed = $locationarray[4];
$course = $locationarray[5];
$altitude = $locationarray[6];
}
// Connect zum Datenbankserver
$link = mysql_connect($MySQLHost, $username, $password) or die("Keine Verbindung möglich!");
// Daten in Datenbank eintragen
mysql_select_db("ipsdata") or die("Auswahl der Datenbank fehlgeschlagen");
$insert = "INSERT INTO location SET number='".$number."', iudid='".$iudid."', devicename='".$devicename."', locationlock='".$locationlock."', date='".$date."', time='".$time."', latitude='".$latitude."', longitude='".$longitude."', accuracy='".$accuracy."', speed='".$speed."', course='".$course."', altitude='".$altitude."'";
$query = mysql_query($insert);
//debug.log
$myFile = "debug.log";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $number."
");
fwrite($fh, $iudid."
");
fwrite($fh, $devicename."
");
fwrite($fh, $locationlock."
");
fwrite($fh, $date."
");
fwrite($fh, $time."
");
fwrite($fh, $latitude."
");
fwrite($fh, $longitude."
");
fwrite($fh, $accuracy."
");
fwrite($fh, $speed."
");
fwrite($fh, $course."
");
fwrite($fh, $altitude."
");
if (!$query) {
fwrite($fh, "Fehler im Query");
}
fclose($fh);
// Datenbankverbindung beenden
mysql_close($link);
/* Output response */
echo $response;
IPS_Sleep(1000);
IPS_RunScript(13375);
?>
Die letzte Zeile " IPS_RunScript(13375); " ruft bei mir das IPS Script „Position Anzeigen“ auf. Anstelle des Timers (siehe Post 21 von bmwm3)
- PHP zur Anzeige der Position im Dashboard, im Script wird oben der
Gerätename hinterlegt. Dann im Dash einfach via Browser Element anzeigen
lassn.
<?php
// SQL Datenbank Zugriffsdaten und Gerätename bitte anpassen
$MySQLHost="127.0.0.1";
$username="dbuser";
$password="dbpass";
$name="gerätename";
// Connect zur Datenbank
$link = mysql_connect($MySQLHost, $username, $password) or die("Keine Verbindung möglich!");
mysql_select_db("ipsdata") or die("Auswahl der Datenbank fehlgeschlagen");
$select = "SELECT devicename,date,time,latitude,longitude FROM location where (devicename = '".$name."') ORDER BY id DESC LIMIT 1";
$query = mysql_query($select);
$num_rows = mysql_num_rows($query);
$row = mysql_fetch_array($query);
// Connect zur Datenbank trennen
mysql_close($link);
$lat = $row['latitude'];
$lng = $row['longitude'];
$devicename = $row['devicename'];
$date = $row['date'];
$time = $row['time'];
?>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Standortbestimmung</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(<?php echo $lat; ?>,<?php echo $lng; ?>);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: 'roadmap'
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var marker = new google.maps.Marker({
position: latlng,
map: map,
title:"<?php echo $devicename; ?>"
});
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="height: 100%;"></div>
</body>
</html>
<?php
echo "Zeitstempel der Position: ";
echo $date;
echo " - ";
echo $time;
?>
P.S: Das Script „Position Anzeigen“ und die map.php bleiben so wie im 1. Post beschrieben.
Gruß Martin