Sending Weather Data to APRS-IS Using Bash and OpenWeatherMap API
As radio amateurs, integrating real-world sensor data into APRS can be both useful and fun. In this guide, I’ll show you how to use a Bash script to automatically fetch your local weather data from OpenWeatherMap and send it to the APRS-IS network.
This method is especially useful for stations that don’t have a dedicated weather station but want to share weather conditions based on their location.
🧰 What You’ll Need
- A Linux machine or server (I’m using Debian)
- Your APRS callsign and passcode
- An OpenWeatherMap API key (free)
- Coordinates of your QTH
jq
andnetcat
installed
🔐 Step 1: Get Your API Keys
APRS-IS Passcode
If you don’t already have a passcode, you can generate it based on your callsign. For example, you can use my free generator here:
OpenWeatherMap API Key
- Go to https://openweathermap.org/api
- Sign up for a free account.
- Copy your API key from the dashboard.
🗺️ Step 2: Determine Your Coordinates
You’ll need your latitude and longitude in decimal format.
Example for Kuala Lumpur:
- Latitude:
3.1390
- Longitude:
101.6869
📜 Step 3: The Bash Script
Here’s the full script:
#!/bin/bash
# === USER CONFIGURATION ===
CALLSIGN="PJUWX-13" # Your APRS callsign (with SSID)
PASSCODE="12031" # Your APRS-IS passcode
LAT="3.1390" # Latitude (decimal format)
LON="101.6869" # Longitude (decimal format)
OPENWEATHER_API_KEY="your_api_key" # Replace with your OpenWeatherMap API key
SERVER="rotate.aprs2.net" # APRS-IS server
PORT="14580" # APRS-IS port
COMMENT="9M2PJU WX Station 🐧" # Comment sent with weather data
# === FETCH WEATHER DATA ===
weather_json=$(curl -s "https://api.openweathermap.org/data/2.5/weather?lat=$LAT&lon=$LON&units=metric&appid=$OPENWEATHER_API_KEY")
temp=$(echo "$weather_json" | jq '.main.temp' | xargs printf "%.0f")
humidity=$(echo "$weather_json" | jq '.main.humidity')
pressure=$(echo "$weather_json" | jq '.main.pressure')
# === FORMAT WEATHER PACKET ===
lat_aprs=$(printf "%02d%05.2fN" "${LAT%.*}" "$(echo "${LAT#*.} * 60 / 1" | bc -l)")
lon_aprs=$(printf "%03d%05.2fE" "${LON%.*}" "$(echo "${LON#*.} * 60 / 1" | bc -l)")
WX_PACKET="${CALLSIGN}>APRS,TCPIP*:@$(date -u +%d%H%Mz)!${lat_aprs}/${lon_aprs}_.../...g...t$(printf "%03d" $temp)r...p...P...h${humidity}b$(printf "%05d" $((pressure * 10))) ${COMMENT}"
# === SEND TO APRS-IS ===
(
echo "user $CALLSIGN pass $PASSCODE vers PJUWX-Bash 1.0"
echo "$WX_PACKET"
sleep 1
) | nc "$SERVER" "$PORT"
echo "✅ Sent: $WX_PACKET"
Save this as send_weather_aprs.sh
, and make it executable:
chmod +x send_weather_aprs.sh
🧪 What This Script Does
- Fetches Weather Data from OpenWeatherMap using your coordinates and API key.
- Extracts:
- Temperature (°C)
- Humidity (%)
- Pressure (hPa)
- Formats your position in APRS format (degrees and minutes).
- Builds an APRS packet with a weather report.
- Sends the packet using Netcat (
nc
) to the APRS-IS network.
🕒 Automate It with Cron (Optional)
To send updates every 20 minutes, add it to your crontab:
crontab -e
Then add:
*/20 * * * * /path/to/send_weather_aprs.sh
📡 Example APRS Packet
PJUWX-13>APRS,TCPIP*:@220945z0313.14N/10141.21E_.../...g...t031r...p...P...h78b10032 9M2PJU WX Station 🐧
💡 Things to Improve
This is a simple example to get you started. You could extend this by:
- Adding wind speed and direction
- Including rainfall (requires API with more data or sensors)
- Sending packets via RF using a TNC instead of APRS-IS
- Switching to Python for better formatting and error handling
🎯 Conclusion
This script is a lightweight, no-hardware solution to send real-time weather data to APRS using just Bash and a public API. Whether you’re setting up a portable station or just want to contribute environmental data from your QTH, this is a great way to get started.
Feel free to modify, share, or expand upon it!
Post Comment