anything
AirNav RadarBox
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 


Author Topic: Radarbox and PHP Script for web relay  (Read 29256 times)

0 Members and 3 Guests are viewing this topic.

asiawatcher

  • New Member
  • *
  • Posts: 37
Radarbox and PHP Script for web relay
« on: December 02, 2008, 03:03:21 PM »
anyone can give me a php example of how to connect to radarbox and relay its data to my website through php ?

cheers

« Last Edit: December 02, 2008, 03:17:42 PM by AirNav Support »

Andy Frost

  • Full Member
  • ***
  • Posts: 117
    • SquawkBox
Re: Radarbox and PHP Script for web relay
« Reply #1 on: December 03, 2008, 11:25:21 AM »
Asiawatcher, as a start here is an example of how to relay the port 30003 data output by RadarBox on to a webpage using php. I'm assuming that you are familiar with php, have it installed and have a service such as Microsoft's Internet Information Services installed and activated so that you can load and test local php files.

Start by creating a file testport.php on your 'localhost' directory (e.g. C:\Inetpub\wwwroot ) with the contents..

<html>
<body>
<?php
$fp = fsockopen('localhost', 30003, $errno, $errstr);
if (!$fp)
{
   echo "$errstr ($errno)<br />\n";
}
else
{
   $out = "GET / HTTP/1.1\r\n";
   $out .= "Host: localhost\r\n";
   $out .= "Connection: Close\r\n\r\n";
   fwrite($fp, $out);

   while (!feof($fp))
   {
      echo fgets($fp, 128);
   }
   fclose($fp);
}
?>
</body>
</html>


Then, with RadarBox running, if you fire up your browser and type  http://localhost/testport.php  into the address box you should see the port 30003 data relayed on to your webpage.

The trouble then is that after a default of 30 seconds you get a message like "Maximum time exceeded". This is because php scripts are only designed to run for the maximum time specified by "max_execution_time" in your php.ini which you can change (if you change this you will need to reboot). You will still run out of time eventually though so maybe you can look into auto-refreshing the page using a meta tag. Eg. to refresh after 25 seconds add:
<META HTTP-EQUIV="REFRESH" CONTENT="25">

This all works with RadarBox 2009 and Php 5 using WindowsXP Professional and IIS as a webpage publishing service.

asiawatcher

  • New Member
  • *
  • Posts: 37
Re: Radarbox and PHP Script for web relay
« Reply #2 on: December 03, 2008, 02:34:11 PM »
hi thanks for your post in http://www.airnavsystems.com/forum/index.php?topic=1756.new;topicseen

i get lots of raw data of the form

MSG,1,0,0,3412C8,0,2008/12/03,14:22:43.472,2008/12/03,14:27:43.472,AEA1451,39000,465,112,37.3313,22.7358,0,,0,0,0,0 MSG,3,0,0,3A4586,0,2008/12/03,14:22:43.472,2008/12/03,14:27:43.472,MEA236,35025,457,108,37.6098,22.5621,0,,0,0,0,0 MSG,3,0,0,3420CF,0,2008/12/03,14:22:50.081,2008/12/03,14:27:50.081,IBE38RE,15300,369,086,37.7688,23.7292,-960,,0,0,0,0 MSG,3,0,0,4B168F,0,2008/12/03,14:22:50.091,2008/12/03,14:27:50.091,SWR838A,07425,285,104,38.0794,23.9963,-1408,,0,0,0,0 MSG,3,0,0,3C64FA,0,2008/12/03,14:22:52.435,2008/12/03,14:27:52.435,DLH592,36975,455,140,37.9497,23.7401,0,,0,0,0,0 MSG,3,0,0,505CE5,0,2008/12/03,14:22:52.445,2008/12/03,14:27:52.445,ESK8ED,20625,397,335,38.2043,24.2479,3136,,0,0,0,0 MSG,3,0,0,3A4586,0,2008/12/03,14:22:54.818,2008/12/03,14:27:54.818,MEA236,35025,458,108,37.6026,22.5892,0,,0,0,0,0 MSG,3,0,0,3420CF,0,2008/12/03,14:23:00.797,2008/12/03,14:28:00.797,IBE38RE,15150,369,086,37.7699,23.7526,-960,,0,0,0,0 MSG,3,0,0,505CE5,0,2008/12/03,14:23:02.019,2008/12/03,14:28:02.019,ESK8ED,21050,400,336,38.2191,24.2394,2944,,0,0,0,0 MSG,3,0,0,3C64FA,0,2008/12/03,14:23:02.019,2008/12/03,14:28:02.019,DLH592,36975,455,140,37.9351,23.7556,0,,0,0,0,0 MSG,3,0,0,3412C8,0,2008/12/03,14:23:04.382,2008/12/03,14:28:04.382,AEA1451,39000,465,112,37.3030,22.8202,0,,0,0,0,0 MSG,3,0,0,3A4586,0,2008/12/03,14:23:05.554,2008/12/03,14:28:05.554,MEA236,35000,458,108,37.5948,22.6186,0,,0,0,0,0 MSG,3,0,0,3420CF,0,2008/12/03,14:23:10.441,2008/12/03,14:28:10.441,IBE38RE,15000,368,087,37.7708,23.7723,-960,,0,0,0,0

any idea how i can structure them ? like make them being displayed on tables ? i want to make a flight display like the one on radarbox only display flags flights etc without radar

thanks a lot man

Andy Frost

  • Full Member
  • ***
  • Posts: 117
    • SquawkBox
Re: Radarbox and PHP Script for web relay
« Reply #3 on: December 03, 2008, 02:55:36 PM »
Yes, that's what I get too.

I don't know what you want to display, you'll have to extract the fields you want to display from the line, each field is separated with a comma. If you want to display flight numbers in a table for example then you will have to extract the flight number from each line and put it in a variable called say $flightNumber then in your html you can do something like this for each MSG line to produce a line of the table

<TR><TD><?php echo $flightNumber; ?></TD></TR>

I think what you probably want to do is to build up a table of flight numbers without repetitions. In which case you are going to have to create an array of the flight numbers first and then display the elements of the array like this...

<TABLE>
<?php
$count = count($array);
for ($i = 0; $i < $count; $i++)
{
    echo '<TR><TD>' . $array[$i] . '</TD></TR>';
}
?>
</TABLE>

asiawatcher

  • New Member
  • *
  • Posts: 37
Re: Radarbox and PHP Script for web relay
« Reply #4 on: December 03, 2008, 09:21:58 PM »
thanks a lot mate that was very helpful

i don't know how to deal with timeout tho it has to timeout first to display me those data for 30 seconds the script is executing i just want it to open connection display data and close then ill put all of those in a table to display flight numbers etc

ill figure it out, have you done personally anything useful with those radarbox data?  like put them on your website ? any idea where i can get more resources considering that ? (probably more commands etc)

is the one you showed me the only command i can give to radar box to output me the data or there are more ?

cheers mate


Andy Frost

  • Full Member
  • ***
  • Posts: 117
    • SquawkBox
Re: Radarbox and PHP Script for web relay
« Reply #5 on: December 03, 2008, 10:06:52 PM »
You can leave the php timeout alone and exit from your port reading loop before that (by using php time functions). Then after a bit more time you can use the update meta tag to update the whole page and start the process again.

What you really want to be able to do is to redraw your table each time a new message is read by your webpage. Ideally you would like to refresh just your table and keep reading messages but I don't think you can do this with php. ASP.Net can refresh part of an html page though.

Another solution might be to make use of mySql together with php. You could use something like a Perl script separate from html to read the port 30003 data to the mySql database and then get the php to display from that database, though again the php page would need to auto-update. I've used this type of setup with Perl/mySql/php to get aviation METAR/TAF data from the net and display the current weather or a weather forecast on a map.

I am the author of SquawkBox (http://www.gfrost.co.uk/SquawkBox/) which reads the port 30003 data you have been looking at and displays a squawk code description for each flight in a scrolling window.

As far as outputs from RadarBox are concerned, you might want to look at the recorded files. These contain more information than the flight data output to port 30003 as they also contain non-positional flights. Data is also output by RadarBox to port 7879 in XML. It is described on page 83 of the manual.

Allocator

  • RadarBox24.com Beta Testers
  • Hero Member
  • *
  • Posts: 3568
Re: Radarbox and PHP Script for web relay
« Reply #6 on: December 03, 2008, 10:14:20 PM »
Crikey Andy!

I know that you know what you are talking about, but it's all scribble to me :-)

Seriously though, it's good to see work such as SquawkBox coming out to exploit all the capabilities of RadarBox.  I've always wanted to do something with that port 7879 and 30003 data, but it's just beyond me.

I'll keep reading this thread and try to learn a bit more!

tarbat

  • ShipTrax Beta Testers
  • Hero Member
  • *
  • Posts: 4219
    • Radarbox at Easter Ross
Re: Radarbox and PHP Script for web relay
« Reply #7 on: December 03, 2008, 10:23:40 PM »
Agreed.  Looks to me like Andy could maybe give us a "master-class" in using port 7879/30003 output.  And I'm pretty sure that Andy's Squawkbox addon is the first to have been developed for the Radarbox, and then adopted by the SBS-1 community!!!

asiawatcher

  • New Member
  • *
  • Posts: 37
Re: Radarbox and PHP Script for web relay
« Reply #8 on: December 04, 2008, 12:46:40 AM »
can i use the same code for the xml port 7879 ?

like

<html>
<body>
<?php
$fp = fsockopen('localhost', 7879, $errno, $errstr);
if (!$fp)
{
   echo "$errstr ($errno)<br />\n";
}
else
{
   $out = "GET / HTTP/1.1\r\n";
   $out .= "Host: localhost\r\n";
   $out .= "Connection: Close\r\n\r\n";
   fwrite($fp, $out);

   while (!feof($fp))
   {
      echo fgets($fp, 128);
   }
   fclose($fp);
}
?>
</body>
</html>

cheers

Andy Frost

  • Full Member
  • ***
  • Posts: 117
    • SquawkBox
Re: Radarbox and PHP Script for web relay
« Reply #9 on: December 04, 2008, 09:10:04 AM »
Yes you can. You will see something like this...

20081204085814 484006 39000 542 100 0 000 53.2487 -1.2352 000 20081204085815 4004BC MON4177 13375 341 327 -1344 000 52.9074 -1.3171 000 20081204085815 78014F 02780 141 274 640 000 53.3162 -2.3541 000 20081204085817 4CA242 RYR103S 28025 447 301 0 000 52.9134 -1.6948 000 20081204085817 C078AE 08025 316 084 0 000 53.5529 -2.5163 000 20081204085817 4CA56E RYR6123 33750 416 298 -1728 000 53.8648 -3.7095 000 20081204085817 47836D SAS2547 04480 191 231 -1088 000 53.4596 -2.0552 000 20081204085818 3949E9 AFR022 33975 469 323 0 000 52.8271 -1.2371 000 20081204085818 48406B KLM957 22000 454 331 0 000 53.8009 -1.5320 000 20081204085818 4CA250 RYR205 34000 421 297 0 000 53.2564 -1.9241 000 20081204085825 78014F CPA038 02855 152 282 576 000 53.3175 -2.3652 000 20081204085826 484006 39000 542 100 0 000 53.2432 -1.1858 000

Note that the XML is decoded by Internet Explorer so the '<' and '>' are stripped away as compared with the example shown in the pdf manual.

You will have to wait 5 minutes to see this data however as the output on this port is delayed by 5 minutes (it should be on port 30003 as well, and will be in the next version). As a result you will have to change max_execution_time in php.ini to be greater than 5 minutes and during this time the page will do nothing except say "Connecting...".

Note that the recorded files are also delayed by 5 minutes so the filename is created but nothing is written to the file until 5 minutes have elapsed.

DaveReid

  • Hero Member
  • *****
  • Posts: 1815
    • Heathrow last 100 ADS-B arrivals
Re: Radarbox and PHP Script for web relay
« Reply #10 on: December 04, 2008, 01:22:14 PM »
any idea how i can structure them ? like make them being displayed on tables ? i want to make a flight display like the one on radarbox only display flags flights etc without radar

See http://www.civilaircraftregisters.org/Mode_S_Resources/LogReport/EGLLADSB.asp for an example of a web application powered by the port 30003 output.  Although it's driven by an SBS, there is no reason why it shouldn't work equally well with the RadarBox 30003 output.

Hopefully that will give you some ideas.
This post has been scanned for any traces of negativity, bias, sarcasm and general anti-social behaviour

Harry

  • Jr. Member
  • **
  • Posts: 98
Re: Radarbox and PHP Script for web relay
« Reply #11 on: December 08, 2008, 06:18:22 AM »
anyone can give me a php example of how to connect to radarbox and relay its data to my website through php ?

cheers



I use the following:
!c:\php -q
<?php
$Locatie="Your Location, Your Country";
$link=mysql_connect('ipadres database','username','password');

if(! $link)
        die("Could not connect to MySQL");
$database = "databasename";
mysql_select_db($database)
        or die ("could not open $database: ".mysql_error() );

$fp = fsockopen("tcp://127.0.0.1",7879);
   while (!feof($fp))   
   {
      $buff1=fgets($fp, 2048);
      echo $buff1;
      if (strlen($buff1)<>0)
         {      
         $numbers = explode("</MODESMESSAGE>", $buff1,-1);
         for($i = 0; $i < count($numbers); $i++)
         {
            $DateVar = explode("</DATETIME>", $numbers[$i]);
            $DateVarModes = strstr($DateVar[0], "<DATETIME>");
            $DateVarJaar = substr($DateVarModes,10,4 );
            $DateVarMaand = substr($DateVarModes,14,2 );
            $DateVarDag = substr($DateVarModes,16,2 );
            $DatumString=$DateVarJaar."-".$DateVarMaand."-".$DateVarDag;

            if (strlen($DateVarJaar)<>0)
            {
               $DateVarUur = substr($DateVarModes,18,2 );
               $DateVarMin = substr($DateVarModes,20,2 );
               $DateVarSec = substr($DateVarModes,22,2 );
               $TijdString=$DateVarUur.":".$DateVarMin.":".$DateVarSec ;
               if (strlen($DateVarUur)<>0)
               {
                  $CallsVar = explode("</CALLSIGN>", $numbers[$i]);
                  $CallsVarModes = strstr($CallsVar[0], "<CALLSIGN>");
                  $CallsVarModes = substr($CallsVarModes,10,50 );
                  $TweedeElement=$CallsVarModes;
                  $HexVar = explode("</MODES>", $numbers[$i]);
                  $HexVarModes = strstr($HexVar[0], "<MODES>");
                  $HexVarModes = substr($HexVarModes,7,50 );
                  $DerdeElement=$HexVarModes;
                  if (strlen($DerdeElement)<>0)
                  {
            
                     if (strlen($TweedeElement)==0)
                     {
                     $TweedeElement="---";
                     }
   
                     $query = "INSERT INTO liveid VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie')";
                     mysql_query($query);
                     echo $query."\n";
                     //
                     // Use this script off line ?
                     // Remove the // signs for the commands below.
                     //
                     //$query = "INSERT INTO liveid VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie');";
                     //$handle1 = fopen("$DatumString mysqllog.txt", 'a');
                     //fwrite($handle1, $query);   
                     //fwrite($handle1, "\r\n");
                     //fclose ($handle1);
                  }
               }
            }
      
         }
      }
      else
      {
         echo "Buffer Empty"."\n";
         //CheckSocket($fp,$Locatie);
      }

   }
?>

asiawatcher

  • New Member
  • *
  • Posts: 37
Re: Radarbox and PHP Script for web relay
« Reply #12 on: December 09, 2008, 07:54:10 AM »
right this is what i get:

Buffer Empty  20081209072320  468974  09550  277  270  3200  000  38.0714  23.9220  000  20081209072327  4692CB  AEE107  15800  386  176  -960  000  38.2513  23.7194  000  20081209072332  468974  OAL151  10200  278  270  3328  000  38.0714  23.9042  000  20081209072337  4692CB  AEE107  15650  377  176  -832  000  38.2352  23.7207  000  20081209072347  4692CB  AEE107  15525  372  176  -832  000  38.2179  23.7220  000  20081209072347  468974  OAL151  10750  287  270  1472  000  38.0716  23.8786  000  20081209072357  468974  OAL151  10950  308  270  1024  000  38.0716  23.8601  000  20081209072358  4692CB  AEE107  15375  360  176  -832  000  38.1983  23.7235  000  20081209072418  4692CB  AEE107  15075  343  176  -576  000  38.1658  23.7260  000  20081209072418  468974  OAL151  11350  338  270  1408  000  38.0719  23.8203  000  20081209072429  468974  OAL151  11550  349  270  1152  000  38.0719  23.8001  000  20081209072429  4692CB  AEE107  15000  337  176  -896  000  38.1500  23.7272  000  20081209072439  4692CB  AEE107  14750  334  176  -1280  000  38.1328  23.7283  000  20081209072441  468974  OAL151  11750  355  270  896  000  38.0719  23.7751  000  20081209072449  4692CB  AEE107  14575  331  176  -1088  000  38.1187  23.7293  000  20081209072455  468974  OAL151  11900  358  270  832  000  38.0721  23.7461  000  20081209072459  4692CB  AEE107  14375  323  176  -832  000  38.1026  23.7305  000  20081209072506  468974  OAL151  12025  360  270  0  000  38.0721  23.7208  000  20081209072509  4692CB  AEE107  14250  317  176  -768  000  38.0887  23.7315  000  20081209072518  468974  OAL151  12000  361  270  0  000  38.0721  23.6977  000  20081209072519  4692CB  AEE107  14125  310  176  -576  000  38.0732  23.7327  000  20081209072528  468974  OAL151  12000  362  269  0  000  38.0721  23.6770  000  20081209072529  4692CB  AEE107  14000  307  176  -1344  000  38.0601  23.7338  000  20081209072538  468974  OAL151  12000  362  268  0  000  38.0717  23.6534  000  20081209072540  4692CB  AEE107  13550  311  176  -2624  000  38.0446  23.7350  000  20081209072548  468974  OAL151  12000  362  268  0  000  38.0714  23.6325  000  20081209072550  4692CB  AEE107  13075  316  176  -2752  000  38.0281  23.7361  000  20081209072600  4692CB  AEE107  12600  321  181  -3200  000  38.0146  23.7365  000  20081209072600  468974  OAL151  12000  361  269  0  000  38.0709  23.6082  000  20081209072610  468974  OAL151  12000  360  269  0  000  38.0707  23.5862  000  20081209072610  4692CB  AEE107  12050  325  193  -3584  000  37.9997  23.7334  000  20081209072620  468974  OAL151  12000  359  269  0  000  38.0706  23.5656  000  20081209072620  4692CB  AEE107  11350  332  200  -3456  000  37.9844  23.7268  000
Fatal error: Maximum execution time of 300 seconds exceeded in C:\wamp\www\index.php on line 23

and the database is empty i created a table and database called "liveid" but nothing gets inserted and data are displayed in a very raw way instead of structured why ?

my modified code


<html>

<head>
  <title></title>
</head>

<body>

<?php
$Locatie="Your Location, Your Country";

//mysql shit
$link=mysql_connect('127.0.0.1','root','');
if(! $link) die("Could not connect to MySQL");
$database = "liveid";
mysql_select_db($database)
        or die ("could not open $database: ".mysql_error() );

//airnav
$fp = fsockopen("tcp://127.0.0.1",7879);
   while (!feof($fp))
   {
      $buff1=fgets($fp, 2048);
      echo $buff1;
      if (strlen($buff1)<>0)
         {
         $numbers = explode("</MODESMESSAGE>", $buff1,-1);
         for($i = 0; $i < count($numbers); $i++)
         {
            $DateVar = explode("</DATETIME>", $numbers[$i]);
            $DateVarModes = strstr($DateVar[0], "<DATETIME>");
            $DateVarJaar = substr($DateVarModes,10,4 );
            $DateVarMaand = substr($DateVarModes,14,2 );
            $DateVarDag = substr($DateVarModes,16,2 );
            $DatumString=$DateVarJaar."-".$DateVarMaand."-".$DateVarDag;

            if (strlen($DateVarJaar)<>0)
            {
               $DateVarUur = substr($DateVarModes,18,2 );
               $DateVarMin = substr($DateVarModes,20,2 );
               $DateVarSec = substr($DateVarModes,22,2 );
               $TijdString=$DateVarUur.":".$DateVarMin.":".$DateVarSec ;
               if (strlen($DateVarUur)<>0)
               {
                  $CallsVar = explode("</CALLSIGN>", $numbers[$i]);
                  $CallsVarModes = strstr($CallsVar[0], "<CALLSIGN>");
                  $CallsVarModes = substr($CallsVarModes,10,50 );
                  $TweedeElement=$CallsVarModes;
                  $HexVar = explode("</MODES>", $numbers[$i]);
                  $HexVarModes = strstr($HexVar[0], "<MODES>");
                  $HexVarModes = substr($HexVarModes,7,50 );
                  $DerdeElement=$HexVarModes;
                  if (strlen($DerdeElement)<>0)
                  {

                     if (strlen($TweedeElement)==0)
                     {
                     $TweedeElement="---";
                     }

                     $query = "INSERT INTO `liveid` (1,2,3,4,5) VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie')";
                     mysql_query($query);
                     echo $query."\n";
                     //
                     // Use this script off line ?
                     // Remove the // signs for the commands below.
                     //
                     //$query = "INSERT INTO liveid VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie');";
                     //$handle1 = fopen("$DatumString mysqllog.txt", 'a');
                     //fwrite($handle1, $query);
                     //fwrite($handle1, "\r\n");
                     //fclose ($handle1);
                  }
               }
            }

         }
      }
      else
      {
         echo "Buffer Empty"."\n";
         //CheckSocket($fp,$Locatie);
      }

   }
/*

   // read data from database and display
mysql_connect("127.0.0.1", "root", "") or die(mysql_error());
mysql_select_db("liveid") or die(mysql_error());
$data = mysql_query("SELECT * FROM liveid")
or die(mysql_error());
Print "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<th>ID:</th> <td>".$info['id'] . "</td> ";
Print "<th>1:</th> <td>".$info['1'] . "</td> ";
Print "<th>2:</th> <td>".$info['2'] . "</td> ";
Print "<th>3:</th> <td>".$info['3'] . "</td> ";
Print "<th>4:</th> <td>".$info['4'] . "</td> ";
Print "<th>5:</th> <td>".$info['5'] . " </td></tr>";
}
Print "</table>";

*/
?>

</body>

</html>


Harry

  • Jr. Member
  • **
  • Posts: 98
Re: Radarbox and PHP Script for web relay
« Reply #13 on: December 09, 2008, 12:05:28 PM »
20081209072320  468974  09550  277  270  3200  000  38.0714  23.9220  000 
-> this seems to be OK.

Fatal error: Maximum execution time of 300 seconds exceeded in C:\wamp\www\index.php on line 23
--> this is a setting in php and can easly be soved by putting  set_time_limit(0);; in your php file on the first line.
 

and the database is empty i created a table and database called "liveid" but nothing gets inserted and data are displayed in a very raw way instead of structured why ?
--> Did you also created a table with the name liveid in your database?

                     $query = "INSERT INTO `liveid` (1,2,3,4,5) VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie')";
                     mysql_query($query);
                     echo $query."\n";

--> this echo should show sometling like : Hexcode, 2008-12-09, 13:02:00, callsign, Your Location, Your Country";

For testing:
place // before the line echo $buff1;
and run the script again.
echo $query."\n"; should be showing something like Hexcode, 2008-12-09, 13:02:00, callsign, Your Location, Your Country";

if not, please let me know
 

asiawatcher

  • New Member
  • *
  • Posts: 37
Re: Radarbox and PHP Script for web relay
« Reply #14 on: December 10, 2008, 05:46:18 AM »
ok for the script it shows (i put timer for 60 seconds)

Fatal error: Maximum execution time of 60 seconds exceeded in C:\wamp\www\index.php on line 26

yes both database and table are called liveid is this a problem ?

if data get inserted in database then i can display them as i want for some reason they aren't tho

cheers