Created
September 16, 2015 19:08
-
-
Save brentmaxwell/010ffe2b859643d4beff to your computer and use it in GitHub Desktop.
Simple PHP page to post to APRS-IS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$aprs_php_ver = "0.1"; | |
$aprs_is_url = "http://srvr.aprs-is.net:8080"; | |
date_default_timezone_set('UTC'); | |
$defaultSSID = "10"; | |
$defaultPath = "APRS,WIDE2-2,TCPIP*"; | |
if($_SERVER["REQUEST_METHOD"] == "POST") | |
{ | |
$isValidLogin = true; | |
if(empty($_REQUEST["callsign"])){ | |
$isValidLogin = false; | |
$responseMessage = "Callsign provided"; | |
header("HTTP/1.1 403 Forbidden"); | |
} | |
if(empty($_REQUEST["passcode"])){ | |
$isValidLogin = false; | |
$responseMessage = "Passcode required"; | |
header("HTTP/1.1 403 Forbidden"); | |
} | |
if($isValidLogin){ | |
$username = strtoupper($_REQUEST["callsign"]); | |
$passcode = $_REQUEST["passcode"]; | |
$callsign = $username; | |
$callsign = empty($_REQUEST['ssid']) ? $username ."-" . $defaultSSID : ($_REQUEST['ssid'] != 0 ? $username . "-" . $_REQUEST['ssid'] : $username); | |
$path = empty($_REQUEST['path']) ? $defaultPath : $_REQUEST['path']; | |
$message = chr($_REQUEST['data_type']); | |
switch($_REQUEST['data_type']){ | |
case 62: | |
$message .= $_REQUEST["data"]; | |
break; | |
case 33: | |
case 47: | |
case 61: | |
case 64: | |
$latRaw = floatval($_REQUEST["latitude"]); | |
$lngRaw = floatval($_REQUEST["longitude"]); | |
$latMin = fmod($latRaw,1); | |
$lngMin = fmod($lngRaw,-1); | |
$lat = str_pad(abs($latRaw - $latMin),2,"0"); | |
$lng = str_pad(abs($lngRaw - $lngMin),3,"0",STR_PAD_LEFT); | |
number_format((float)$latMin, 2, '.', ''); | |
$latMin = abs($latMin*60); | |
$lngMin = abs($lngMin*60); | |
$latMin = number_format((float)$latMin, 2, '.', ''); | |
$lngMin = number_format((float)$lngMin, 2, '.', ''); | |
if(strpos($latMin,'.') <= 1){ | |
$latMin = "0" . $latMin; | |
} | |
if(strpos($lngMin,'.') <=1){ | |
$lngMin = "0" . $lngMin; | |
} | |
$lat .= $latMin; | |
$lng .= $lngMin; | |
$lat .= $latRaw >= 0 ? "N" : "S"; | |
$lng .= $lngRaw >= 0 ? "E" : "W"; | |
$date = date('His'); | |
if($_REQUEST['data_type'] == 64 || $_REQUEST['data_type'] == 47){ | |
$message .= $date."h"; | |
} | |
$message .= $lat."/".$lng."l"; | |
break; | |
default: | |
$message .= $_REQUEST["data"]; | |
} | |
$login_line = "user ".$callsign." pass ".$passcode." vers aprs.php $aprs_php_ver\n"; | |
$message_line = $callsign .">" . $path . ":" . $message . "\n"; | |
$ch = curl_init(); | |
$curl_opts = array( | |
CURLOPT_URL => $aprs_is_url, | |
CURLOPT_POST => true, | |
CURLOPT_HTTPHEADER => array( | |
'Accept-Type: text/plain', | |
'Content-type: application/octet-stream', | |
), | |
CURLOPT_POSTFIELDS => $login_line . $message_line, | |
CURLOPT_RETURNTRANSFER => 1 | |
); | |
curl_setopt_array($ch, $curl_opts); | |
$output = curl_exec($ch); | |
$return = curl_getinfo($ch); | |
if($return['http_code'] == 204){ | |
$responseMessage = $message_line; | |
} | |
else{ | |
$responseMessage = "Error from APRS-IS: " . $return['http_code']; | |
} | |
curl_close($ch); | |
} | |
} | |
?> | |
</pre> | |
<html> | |
<head> | |
<script> | |
function getLocation() { | |
if (navigator.geolocation) { | |
navigator.geolocation.getCurrentPosition(showPosition); | |
} else { | |
} | |
} | |
function showPosition(position) { | |
var latitudeElement = document.getElementById("latitude"); | |
var longitudeElement = document.getElementById("longitude"); | |
latitudeElement.value = position.coords.latitude; | |
longitudeElement.value = position.coords.longitude; | |
} | |
function selectMessageFields(element){ | |
switch(element.selectedOptions[0].value){ | |
case "33": | |
case "47": | |
case "61": | |
case "64": | |
document.getElementById('locationFields').style.display = "block"; | |
break; | |
default: | |
document.getElementById('locationFields').style.display = "none"; | |
break; | |
} | |
} | |
</script> | |
</head> | |
<body onload="getLocation()"> | |
<form method="post"> | |
<div> | |
Callsign: | |
<input id="callsign" name="callsign" type="text"/> | |
</div> | |
<div> | |
SSID: | |
<select id="ssid" name="ssid"> | |
<option value="0">0: Your primary station usually fixed and message capable</option> | |
<option value="1">1: generic additional station, digi, mobile, wx, etc</option> | |
<option value="2">2: generic additional station, digi, mobile, wx, etc</option> | |
<option value="3">3: generic additional station, digi, mobile, wx, etc</option> | |
<option value="4">4: generic additional station, digi, mobile, wx, etc</option> | |
<option value="5">5: Other networks (Dstar, Iphones, Androids, Blackberry's etc)</option> | |
<option value="6">6: Special activity, Satellite ops, camping or 6 meters, etc</option> | |
<option value="7">7: walkie talkies, HT's or other human portable</option> | |
<option value="8">8: boats, sailboats, RV's or second main mobile</option> | |
<option value="9">9: Primary Mobile (usually message capable)</option> | |
<option value="10" selected="selected">10: internet, Igates, echolink, winlink, AVRS, APRN, etc</option> | |
<option value="11">11: balloons, aircraft, spacecraft, etc</option> | |
<option value="12">12: APRStt, DTMF, RFID, devices, one-way trackers*, etc</option> | |
<option value="13">13: Weather stations</option> | |
<option value="14">14: Truckers or generally full time drivers</option> | |
<option value="15">15: generic additional station, digi, mobile, wx, etc</option> | |
</select> | |
</div> | |
<div> | |
Passcode: | |
<input id="passcode" name="passcode" type="password"/> | |
</div> | |
<div> | |
Path: | |
<input id="path" name="path" type="test" value="<?php echo $defaultPath;?>"/> | |
<div> | |
Message Type: | |
<select id="data_type" name="data_type" onchange="selectMessageFields(this)"> | |
<option>Select...</option> | |
<!--<option value="28">Current Mic-E Data</option>--> | |
<!--<option value="29">Old Mic-E Data</option>--> | |
<option value="33">Position without timestamp (no APRS messaging)</option> | |
<!--<option value="36">Raw GPS data</option>--> | |
<!--<option value="41">Item</option>--> | |
<option value="47">Position with timestamp (no APRS messaging)</option> | |
<!--<option value="58">Message</option>--> | |
<!--<option value="59">Object</option>--> | |
<!--<option value="60">Station Capabilities</option>--> | |
<option value="61">Position without timestamp (with APRS messaging)</option> | |
<option value="62">Status</option> | |
<!--<option value="63">Query</option>--> | |
<option value="64">Position with timestamp (with APRS messaging)</option> | |
<!--<option value="84">Telemetry data</option>--> | |
<!--<option value="95">Weather Report (without position)</option>--> | |
<!--<option value="123">User-Defined APRS packet format</option>--> | |
<!--<option value="125">Third-party traffic</option>--> | |
</select> | |
</div> | |
<h2>Data</h2> | |
<div id="messageFields"> | |
<input id="data" name="data" type="text"/> | |
</div> | |
<div id="locationFields" style="display:none;"> | |
<h3>Location</h3> | |
<div> | |
Latitude | |
<input id="latitude" name="latitude" type="text"/> | |
</div> | |
<div> | |
Longitude | |
<input id="longitude" name="longitude" type="text"/> | |
</div> | |
</div> | |
<div> | |
<input id="submit" type="submit"/> | |
</div> | |
</form> | |
<?php if(!empty($responseMessage)):?> | |
<h2>Last Result</h2> | |
<pre><?php echo $responseMessage;?></pre> | |
<?php endif;?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment