NOTE: This example does not seem to work any more (january 2017), probably due to protocol changes on the server side.

You will find an adapted and more verbose version of the PHP example here.


<syntaxhighlight lang="php">

  1. !/usr/bin/php

<?php

 $master = "localhost:62030";
 $repeater_id = 9991234;  // Change this to your own ID
 $password = "somepassword";  // This needs to match the password in the master
 $number = sprintf("%08X", $repeater_id); 
 $handle = fsockopen("udp://$master");
 stream_set_timeout($handle, 10);

 $state = 0;
 $message = "RPTL$number";
 fwrite($handle, $message);
 print(">> $message\n");

 while (true)
 {
   $buffer = fread($handle, 200);

   if (strlen($buffer) == 0)
   {
     $message = "MSTPING$number";
     fwrite($handle, $message);
     print(">> $message\n");
     continue;
   }

   if (substr($buffer, 0, 4) == "DMRD")
   {
     $data = substr($buffer, 4);
     print(">> [DMR Data] " . bin2hex($data) . "\n");
     continue;
   }

   print("<< $buffer\n");

   if ((substr($buffer, 0, 6) == "MSTACK") &&
       (strlen($buffer) == 22))
   {
     $salt = substr($buffer, 14, 8);
     $digest = hash("sha256", "$salt$password");
     print("Salt: $salt Digest: $digest\n");

     $message = "RPTK$number$digest";
     fwrite($handle, $message);
     print(">> $message\n");
   }

   if ((substr($buffer, 0, 6) == "MSTACK") &&
       (strlen($buffer) == 14) &&
       ($state == 0))
   {
     $state = 1;

     $message = "RPTC";
     $message .= sprintf("%-8s", "R3ABM-T"); //Name of the repeater
     $message .= $number;                    //ID
     $message .= "433787500";                // RX
     $message .= "438787500";                // TX
     $message .= "99";                       // Power
     $message .= "15";                       // Colot Code
     $message .= sprintf("%-08f", 0);        // Latitude
     $message .= sprintf("%-09f", 0);        // Longitude
     $message .= "999";                      // Height
     $message .= sprintf("%-20s", "Moscow"); // Location
     $message .= sprintf("%-20s", "Description"); //Description
     $message .= sprintf("%-124s", "www.dstar.su"); //URL
     $message .= sprintf("%-40s", "linux:dmrrepeater-20150702"); // Software ID 
     $message .= sprintf("%-40s", "rpm:dmrrepeater-20150720-2_i386");  // Package ID

     $length = strlen($message);
     print("Repeater configuration: $length bytes\n");

     fwrite($handle, $message);
     print(">> $message\n");
   }

   if ((substr($buffer, 0, 6) == "MSTNAK") &&
       (strlen($buffer) == 14) &&
       ($state == 1))
   {
     $state = 0;
     $message = "RPTL$number";
     fwrite($handle, $message);
     print(">> $message\n");
   }
 }

 fclose($handle);

?> </syntaxhighlight>

NOTE: This example does not seem to work any more (january 2017), probably due to protocol changes on the server side.

You will find an adapted and more verbose version of the PHP example here.


<syntaxhighlight lang="php">

  1. !/usr/bin/php

<?php

 $master = "localhost:62030";
 $repeater_id = 9991234;  // Change this to your own ID
 $password = "somepassword";  // This needs to match the password in the master
 $number = sprintf("%08X", $repeater_id); 
 $handle = fsockopen("udp://$master");
 stream_set_timeout($handle, 10);

 $state = 0;
 $message = "RPTL$number";
 fwrite($handle, $message);
 print(">> $message\n");

 while (true)
 {
   $buffer = fread($handle, 200);

   if (strlen($buffer) == 0)
   {
     $message = "MSTPING$number";
     fwrite($handle, $message);
     print(">> $message\n");
     continue;
   }

   if (substr($buffer, 0, 4) == "DMRD")
   {
     $data = substr($buffer, 4);
     print(">> [DMR Data] " . bin2hex($data) . "\n");
     continue;
   }

   print("<< $buffer\n");

   if ((substr($buffer, 0, 6) == "MSTACK") &&
       (strlen($buffer) == 22))
   {
     $salt = substr($buffer, 14, 8);
     $digest = hash("sha256", "$salt$password");
     print("Salt: $salt Digest: $digest\n");

     $message = "RPTK$number$digest";
     fwrite($handle, $message);
     print(">> $message\n");
   }

   if ((substr($buffer, 0, 6) == "MSTACK") &&
       (strlen($buffer) == 14) &&
       ($state == 0))
   {
     $state = 1;

     $message = "RPTC";
     $message .= sprintf("%-8s", "R3ABM-T"); //Name of the repeater
     $message .= $number;                    //ID
     $message .= "433787500";                // RX
     $message .= "438787500";                // TX
     $message .= "99";                       // Power
     $message .= "15";                       // Colot Code
     $message .= sprintf("%-08f", 0);        // Latitude
     $message .= sprintf("%-09f", 0);        // Longitude
     $message .= "999";                      // Height
     $message .= sprintf("%-20s", "Moscow"); // Location
     $message .= sprintf("%-20s", "Description"); //Description
     $message .= sprintf("%-124s", "www.dstar.su"); //URL
     $message .= sprintf("%-40s", "linux:dmrrepeater-20150702"); // Software ID 
     $message .= sprintf("%-40s", "rpm:dmrrepeater-20150720-2_i386");  // Package ID

     $length = strlen($message);
     print("Repeater configuration: $length bytes\n");

     fwrite($handle, $message);
     print(">> $message\n");
   }

   if ((substr($buffer, 0, 6) == "MSTNAK") &&
       (strlen($buffer) == 14) &&
       ($state == 1))
   {
     $state = 0;
     $message = "RPTL$number";
     fwrite($handle, $message);
     print(">> $message\n");
   }
 }

 fclose($handle);

?> </syntaxhighlight>