Skip to content

Instantly share code, notes, and snippets.

@nonoo
Created April 21, 2014 08:24
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save nonoo/11136124 to your computer and use it in GitHub Desktop.
Save nonoo/11136124 to your computer and use it in GitHub Desktop.
PHP script for sending location APRS message to APRS-IS.
#!/usr/bin/php5
<?php
$aprs_callsign = '';
$aprs_passcode = 0;
$aprs_altinfeet = 2080;
// W is the WX icon. See http://wa8lmf.net/aprs/APRS_symbols.htm
// Use GPS coordinate format, see http://www.csgnetwork.com/gpscoordconv.html
$aprs_coord = '4740.55N/01829.60EW';
$aprs_comment = 'Gerecse WX - www.ha5kdr.hu';
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket) {
$result = socket_connect($socket, 'hun.aprs2.net', 14580);
if ($result) {
// Authenticating
$tosend = "user $aprs_callsign pass $aprs_passcode\n";
socket_write($socket, $tosend, strlen($tosend));
$authstartat = time();
$authenticated = false;
while ($msgin = socket_read($socket, 1000, PHP_NORMAL_READ)) {
if (strpos($msgin, "$aprs_callsign verified") !== FALSE) {
$authenticated = true;
break;
}
// Timeout handling
if (time()-$authstartat > 5)
break;
}
if ($authenticated) {
// Sending position
$tosend = "$aprs_callsign>APRS,TCPIP*:@" . date('Hmi') . "z$aprs_coord/A=" .
str_pad($aprs_altinfeet, 6, '0', STR_PAD_LEFT) . " $aprs_comment\n";
socket_write($socket, $tosend, strlen($tosend));
echo $tosend;
}
}
socket_close($socket);
}
?>
@danthepilotman
Copy link

My revised code used to transmit weather data.

const APRS_CALLSIGN = "your callsign";
const APRS_PASSCODE = "your passcode";
const APRS_COORD = "2801.61N/08037.90W"; // example lat/lon
const APRS_COMMENT = "DLDesigns";
const APRS_URL = "noam.aprs2.net"; // change to match your location's most suitable APRS server
const APRS_SOCKET = 14580;

$socket = socket_create( AF_INET, SOCK_STREAM, SOL_TCP) ;

if ( $socket )
{
    $result = socket_connect( $socket, APRS_URL, APRS_SOCKET );

    if ( $result )
    {
        // Authenticating
        $tosend = "user " . APRS_CALLSIGN . " pass " . APRS_PASSCODE . "\n";

        socket_write( $socket, $tosend, strlen( $tosend ) );

        $authstartat = time();

        $authenticated = false;

        while ( $msgin = socket_read( $socket, 1000, PHP_NORMAL_READ ) )
        {
            if ( strpos( $msgin, APRS_CALLSIGN . " verified" ) !== FALSE )
            {
                $authenticated = true;

                break;
            }
            // Timeout handling
            if ( time() - $authstartat > 5 )
                break;
        }

        if ( $authenticated )
        {
            $tosend = APRS_CALLSIGN . ">APRS,TCPIP*:!" . APRS_COORD . "_000/000g000t" . sendTemp() .
            "r000p000P000h" . sendHumd() . "b" . sendPress() . APRS_COMMENT . "\n";

            socket_write( $socket, $tosend, strlen( $tosend ) );

            echo "<br><br>". "<b>Data sent to APRS Server is: </b>" . $tosend . "<br><br>";
        }
    }

    socket_close( $socket );

function sendTemp()
{
global $value1;

$temp_str = sprintf( "%03d", (int) ( 1.8 * $value1 + 32.0 + 0.5 ) );

return $temp_str;

}

function sendHumd()
{
global $value2;

$humd_str = sprintf( "%02d", (int) ( $value2 + 0.5 ) );

return $humd_str;

}

function sendPress()
{
global $value3;

$press_str = sprintf( "%05d", (int) ( $value3 * 10 ) );

return $press_str;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment