A quick how-to with the aprs.fi API

September 11, 2012

APRS lets users share information (GPS tracks, WX info, etc.) both over the internet and over the air via amateur radio. (See Wikipedia for more about APRS.)

aprs.fi is the go-to site to see current APRS activity in your (or any) area. They also have an API that lets users tie into all this great data.

In the example below I've written a small PHP script that demonstrates how to pull data from the API and display that data in your terminal window.


ini_set( "user_agent", "Midnight Cheese (+http://midnightcheese.com/)" );

echo "\n\nFetching APRS data...\n\n";

function display_APRS() {
	$json_url = "http://api.aprs.fi/api/get?apikey=0000&name=KBNA,KF4KFQ,AG4FW,WR1Q&what=wx&format=json";
	$json = file_get_contents( $json_url, 0, null, null );
	$json_output = json_decode( $json, true);
	$station_array = $json_output[ 'entries' ];
	foreach ( $station_array as $station ) {
		$name = $station[ 'name' ];
		$temp = $station[ 'temp' ];
		$temp = ( ( 9 / 5 ) * $temp ) + 32; // Convert celsius to fahrenheit.
		echo "Temperature is ".$temp."°F at ".$name."\n";
	echo "\n\n";



In this case we're requesting a list of weather information posted by a handful of different operators. The API returns the data in JSON which is then parsed and displayed. The final output is displayed below.

Fetching APRS data...

Temperature is 82.04°F at KBNA
Temperature is 84.92°F at KF4KFQ
Temperature is 78.08°F at AG4FW
Temperature is 82.94°F at WR1Q

Objects on the aprs.fi map.

Lots of APRS objects displayed on the aprs.fi map.

For more content like this, subscribe to Amateur Radio Weekly, a weekly summary of the most relevant content in the world of Ham Radio. ♦