For a project I am working on, I need to get data from an iPhone app "SensorLog". With SensorLog you can read out sensor data of your iOS device and send it via email as csv file, stream it via tcp/ip, and send it via HTTP GET/POST request
I need to stream it via tcp/ip, and send it via HTTP GET/POST request to my local computer. below is configuration screen on phone.
Below is the PHP code supplied by the APP.
<html>
<head>
<title>php post get</title>
</head>
<body>
<?php
echo "PHP Example: Receiving SensorLog data via HTTP GET/POST and save it to a file<br>
";
$line = array();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$line[] = "HTTP:POST";
foreach($_POST as $key=>$value) {
$line[] = "$key:$value";
}
}
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$line[] = "HTTP:GET";
foreach($_REQUEST as $key=>$value) {
$line[] = "$key:$value";
}
}
if (count($line) > 1) {
$myfile = fopen("SensorLog.txt", "a") or die("Unable to open file!");
$line = implode(",",$line);
$line .= "
";
fwrite($myfile,$line);
fclose($myfile);
} else {
echo "<h3>Logged Data</h3>";
$myfile = fopen("SensorLog.txt", "r") or die("Unable to open file!");
while(!feof($myfile)) {
echo fgets($myfile) . "<br>";
}
fclose($myfile);
}
?>
</body>
</html>
I have set up a Apache Web Server and PHP in my local system.
QUESTION ** 1. What should I put in URL of the app in iPhone
2. How do I receive the data in my local system **
I am really new to this. I need to further work on data but but unable to get the "Stream of Data". Please help.
If your app is dealing with php script through the URL then you have to deal with the $_GET
and you should change your php code to:
...
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$line[] = "HTTP:GET";
foreach($_GET as $key=>$value) {
$line[] = "$key:$value";
}
}
...
Your URL should look like:http://yourdomain/?KEY1_VALUE=VALUE1_VALUE&KEY2_VALUE=VALUE2_VALUE&KEY3_VALUE=VALUE3_VALUE
Which will result this content in your file:KEY1_VALUE:VALUE1_VALUE,KEY2_VALUE:VALUE2_VALUE,KEY3_VALUE:VALUE3_VALUE
If your working on a local server then your domain is: http://127.0.0.1/
or http://localhost/
.