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 24368 times)

0 Members and 1 Guest are viewing this topic.

asiawatcher

  • New Member
  • *
  • Posts: 37
Re: Radarbox and PHP Script for web relay
« Reply #15 on: December 10, 2008, 06:33:09 AM »
what i think is going on is no data are inserted to table coz script times out or something, it doesnt complete the cycle no matter how long i put it to timeout either for 2-3 seconds or even 300 it still times out then maybe query doesn't get completed


Harry

  • Jr. Member
  • **
  • Posts: 98
Re: Radarbox and PHP Script for web relay
« Reply #16 on: December 11, 2008, 07:03:25 AM »
Back to the basics;-)

You are getting data from the port, so that should be working OK.
Could you check the following code?

!c:\php -q
<?php
set_time_limit(0);
$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() );

$DerdeElement="A9876E";
$DatumString="2008-12-11";
$TijdString="07:54:00";
$TweedeElement="GTI8304";
$query = "INSERT INTO liveid VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie')";
                     mysql_query($query);
                     echo $query."\n";
?>


This should insert 1 record into database.

asiawatcher

  • New Member
  • *
  • Posts: 37
Re: Radarbox and PHP Script for web relay
« Reply #17 on: December 11, 2008, 02:32:31 PM »
probably my wampserver has something wrong nothing happens !!!

ill look it up

asiawatcher

  • New Member
  • *
  • Posts: 37
Re: Radarbox and PHP Script for web relay
« Reply #18 on: December 11, 2008, 03:17:05 PM »
ok i fixed the problem i installed other wamp version and it does insert 1 record in database. However problem with airnav script still same, script times out after 2 or 3 or 5 seconds (depends for how long i put the timeout for) and nothing gets inserted. I think its because of the time out that nothing gets inserrted but no matter if i put it for 2-310-300 seconds still it will keep "waiting for reply" till that time is reached then say timeout

"Fatal error: Maximum execution time of 2 seconds exceeded in c:\wamp\www\index.php on line 31"

so if database is working ok now its the time out that we should worry about

here is the full code


<html>

<head>

<meta http-equiv="refresh" content="300">

  <title></title>
</head>

<body>

<?php

set_time_limit(2);

$Locatie="Greece";

//mysql shit
$link=mysql_connect('127.0.0.1','root','');
if(!$link) die("Could not connect to MySQL");

$database = "airnav";

mysql_select_db($database,$link)
        or die ("Could not connect to database");

//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 `live` (a,b,c,d,e) VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie')";
                     mysql_query($query,$link);
                     echo $query."\n";
                     //
                     // Use this script off line ?
                     // Remove the // signs for the commands below.
                     //
                     //$query = "INSERT INTO `live` (a,b,c,d,e) 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);
      }

   }


mysql_close($link);



?>

<a href="2.php">check database contents</a>

</body>

</html>

Andy Frost

  • Full Member
  • ***
  • Posts: 117
    • SquawkBox
Re: Radarbox and PHP Script for web relay
« Reply #19 on: December 11, 2008, 04:26:50 PM »
Your php script is timing out with an error because you have told it to run for just two seconds before stopping and issuing an error by calling "set_time_limit(2);". You could try doing "set_time_limit(0);" instead as Harry suggested in his example. This should run without a timeout ( see http://uk3.php.net/set_time_limit ).

If you need to exit from the loop that is reading messages from port 7879 to update the rest of the page then you can always monitor the message timestamp supplied in the <DATETIME></DATETIME> couplet or use a php get time function ( see http://www.php.net/manual/en/ref.datetime.php ).

asiawatcher

  • New Member
  • *
  • Posts: 37
Re: Radarbox and PHP Script for web relay
« Reply #20 on: December 11, 2008, 07:17:59 PM »
if i put set time limit to zero then there will be no time limit according to the manual and the default will be applied of php.ini at the max_execution_time

NO MATTER what time i put (even 300 seconds) it will still time out after 300 seconds time duration doesn't matter it seems

as for the time functions im a bit lost i dont know how to do this ~:/

Andy Frost

  • Full Member
  • ***
  • Posts: 117
    • SquawkBox
Re: Radarbox and PHP Script for web relay
« Reply #21 on: December 11, 2008, 08:07:22 PM »
According to the php manual, the value supplied with set_time_limit() is "The maximum execution time, in seconds. If set to zero, no time limit is imposed". So zero should mean that the php script runs forever. It won't run forever however because you have set up "<meta http-equiv="refresh" content="300">" which will cause the whole page to reload itself and start again after 300 seconds.

As it is going to take 5 minutes (300 seconds) before any data is transmitted on port 7879 because of the security delay I would have thought that you will need to considerably extend that refresh time in order to receive something on the port before the page refreshes.

You can access the time by using the php function localtime as described in the URL I have posted above, e.g. $time_info = localtime($time,1);
then if you want the minutes you read the variable $time_info['tm_min']

asiawatcher

  • New Member
  • *
  • Posts: 37
Re: Radarbox and PHP Script for web relay
« Reply #22 on: December 11, 2008, 11:34:38 PM »
ok this

<html>

<head>

<meta http-equiv="refresh" content="500">

  <title></title>
</head>

<body>

<?php





$Locatie="Greece";

//mysql shit
$link=mysql_connect('127.0.0.1','root','');
if(!$link) die("Could not connect to MySQL");

$database = "airnav";

mysql_select_db($database,$link)
        or die ("Could not connect to database");


//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 `live` (a,b,c,d,e) VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie')";

                     echo $DerdeElement."\n";
                     echo $DatumString."\n";
                     echo $TijdString."\n";
                     echo $TweedeElement."\n";
                     echo $Locatie."\n";


                     mysql_query($query,$link);
                     echo $query."\n";
                     //
                     // Use this script off line ?
                     // Remove the // signs for the commands below.
                     //
                     //$query = "INSERT INTO `live` (a,b,c,d,e) 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);
      }

   }


mysql_close($link);



?>

<a href="2.php">check database contents</a>

</body>

</html>
gave me THIS

Buffer Empty Buffer Empty Buffer Empty Buffer Empty Buffer Empty  20081211225914  ABE1B6  DAL153  31975  0  480.0  37.7181  23.8892  480.0  20081211225924  ABE1B6  DAL153  32000  0  479.0  37.7384  23.8700  479.0  20081211225934  ABE1B6  DAL153  32000  0  479.0  37.7573  23.8518  479.0  20081211225944  ABE1B6  DAL153  31975  0  475.0  37.7759  23.8329  475.0  20081211225954  ABE1B6  DAL153  31975  0  474.0  37.7941  23.8144  474.0  20081211230005  ABE1B6  DAL153  31975  0  473.0  37.8113  23.7966  473.0  20081211230015  ABE1B6  DAL153  32000  0  474.0  37.8316  23.7756  474.0  20081211230025  ABE1B6  DAL153  32000  0  476.0  37.8493  23.7570  476.0  20081211230036  ABE1B6  DAL153  31975  0  476.0  37.8680  23.7375  476.0  20081211230046  ABE1B6  DAL153  32000  0  476.0  37.8851  23.7193  476.0  20081211230056  ABE1B6  DAL153  32000  0  474.0  37.9050  23.6982  474.0  20081211230107  ABE1B6  DAL153  32000  0  473.0  37.9227  23.6793  473.0  20081211230117  ABE1B6  DAL153  32000  0  474.0  37.9406  23.6601  474.0  20081211230127  ABE1B6  DAL153  31975  0  477.0  37.9605  23.6390  477.0  20081211230138  ABE1B6  DAL153  31975  0  479.0  37.9808  23.6173  479.0  20081211230148  ABE1B6  DAL153  31975  0  477.0  37.9960  23.5998  477.0  20081211230158  ABE1B6  DAL153  32000  0  473.0  38.0149  23.5770  473.0  20081211230208  ABE1B6  DAL153  32000  0  473.0  38.0300  23.5579  473.0  20081211230218  ABE1B6  DAL153  32000  0  475.0  38.0451  23.5387  475.0  20081211230228  ABE1B6  DAL153  31975  0  480.0  38.0623  23.5157  480.0  20081211230238  ABE1B6  DAL153  31975  0  485.0  38.0760  23.4956  485.0 Buffer Empty Buffer Empty Buffer Empty  20081211230550  4B1696  SWR1842  08775  234  149  -1024  000  37.7086  23.4784  000  20081211230600  4B1696  SWR1842  08700  233  138  -448  000  37.7009  23.4866  000  20081211230610  4B1696  SWR1842  08600  228  136  -640  000  37.6934  23.4955  000  20081211230628  4B1696  SWR1842  08300  223  136  -896  000  37.6792  23.5125  000  20081211230707  484057  39000  464  153  0  000  38.3968  23.7604  000  20081211230730  484057  39000  466  153  0  000  38.3545  23.7877  000  20081211230806  484057  39000  463  153  0  000  38.2855  23.8323  000  20081211230831  484057  39000  466  152  0  000  38.2368  23.8646  000  20081211230847  484057  KLM553  39000  468  153  0  000  38.2061  23.8845  000  20081211230902  484057  KLM553  39000  470  153  0  000  38.1766  23.9032  000  20081211230914  484057  KLM553  39000  476  153  0  000  38.1549  23.9171  000  20081211230927  484057  KLM553  39000  480  153  0  000  38.1273  23.9349  000  20081211230937  484057  KLM553  38975  481  153  0  000  38.1076  23.9476  000  20081211230947  484057  KLM553  38975  482  153  0  000  38.0880  23.9604  000  20081211230957  484057  KLM553  39000  482  152  0  000  38.0680  23.9732  000  20081211231007  484057  KLM553  39000  485  150  0  000  38.0524  23.9840  000  20081211231018  484057  KLM553  39000  489  147  0  000  38.0287  24.0015  000  20081211231030  484057  KLM553  39000  491  144  0  000  38.0049  24.0225  000  20081211231041  484057  KLM553  39000  495  141  0  000  37.9855  24.0401  000  20081211231051  484057  KLM553  39000  497  138  0  000  37.9663  24.0608  000  20081211231138  484057  KLM553  39000  498  136  0  000  37.8877  24.1548  000 Buffer Empty  20081211231249  484057  KLM553  39025  498  136  0  000  37.7696  24.2967  000 Buffer Empty Buffer Empty Buffer Empty Buffer Empty Buffer Empty Buffer Empty Buffer Empty Buffer Empty  20081211232051  468965  22575  346  146  -2112  000  38.539  23.4304  000 Buffer Empty Buffer Empty  20081211232307  468965  OAL208  17350  316  158  -2304  000  38.3558  23.5516  000  20081211232347  468965  OAL208  15525  305  159  -3136  000  38.2990  23.5783  000  20081211232357  468965  OAL208  15000  302  159  -3328  000  38.2865  23.5842  000  20081211232408  468965  OAL208  14350  302  159  -3328  000  38.2719  23.5910  000  20081211232437  468965  OAL208  12875  295  158  -2880  000  38.2354  23.6087  000  20081211232442  468967  23375  361  145  -1728  000  38.5309  23.4441  000  20081211232448  468965  OAL208  12350  292  158  -2944  000  38.2214  23.6156  000  20081211232457  468967  22925  363  145  -1600  000  38.5090  23.4630  000  20081211232458  468965  OAL208  11750  288  157  -3072  000  38.2080  23.6227  000  20081211232507  468967  OAL148  22650  365  145  -1728  000  38.4952  23.4749  000  20081211232509  468965  OAL208  11225  284  157  -3072  000  38.1953  23.6293  000  20081211232520  468965  OAL208  10625  279  158  -3264  000  38.1823  23.6360  000  20081211232530  468965  OAL208  10150  276  159  -2944  000  38.1698  23.6421  000  20081211232540  468965  OAL208  09600  273  159  -3392  000  38.1586  23.6475  000  20081211232550  468965  OAL208  09100  271  159  -3392  000  38.1471  23.6532  000  20081211232600  468965  OAL208  08475  271  162  -3264  000  38.1352  23.6585  000

still nothing in database !!

no timeout this time
« Last Edit: December 11, 2008, 11:42:11 PM by asiawatcher »

Harry

  • Jr. Member
  • **
  • Posts: 98
Re: Radarbox and PHP Script for web relay
« Reply #23 on: December 12, 2008, 06:02:07 AM »
Ok, now the other way arround:

what gives the following for output?

fp = fsockopen("tcp://127.0.0.1",7879);
   while (!feof($fp))
   {
      $buff1=fgets($fp, 2048);
      echo $buff1;
}

The $buff1 should give XML statement. In your example it only seems to give plain text without the xml statements.

Which version of Radarbox are you using?

asiawatcher

  • New Member
  • *
  • Posts: 37
Re: Radarbox and PHP Script for web relay
« Reply #24 on: December 12, 2008, 07:27:14 AM »
hi just to note i also tried writing the output to a FILE AS WELL (to check) and this also fails !! here is the code


<html>

<head>

<meta http-equiv="refresh" content="500">

  <title></title>
</head>

<body>

<?php



$File = "YourFile.txt";
$Handle = fopen($File, 'w');
$arrow="----------------------------------------";

$Locatie="Greece";

//mysql shit
$link=mysql_connect('127.0.0.1','root','');
if(!$link) die("Could not connect to MySQL");

$database = "airnav";

mysql_select_db($database,$link)
        or die ("Could not connect to database");


//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 `live` (a,b,c,d,e) VALUES ('$DerdeElement','$DatumString','$TijdString','$TweedeElement','$Locatie')";

                     fwrite($Handle, $arrow);
                     fwrite($Handle, $DerdeElement);
                     fwrite($Handle, $DatumString);
                     fwrite($Handle, $TijdString);
                     fwrite($Handle, $TweedeElement);
                     fwrite($Handle, $Locatie);
                     fwrite($Handle, $Locatie);
                     fwrite($Handle, $arrow);
                     print "Data Written";
                     fclose($Handle);

                     echo $DerdeElement."\n";
                     echo $DatumString."\n";
                     echo $TijdString."\n";
                     echo $TweedeElement."\n";
                     echo $Locatie."\n";


                     mysql_query($query,$link);
                     echo $query."\n";
                     //
                     // Use this script off line ?
                     // Remove the // signs for the commands below.
                     //
                     //$query = "INSERT INTO `live` (a,b,c,d,e) 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);
      }

   }


mysql_close($link);



?>

<a href="2.php">check database contents</a>

</body>

</html>



im using the latest radarbox version in hardware and software i only bought it one week ago

now ill try what you suggested me