Skip to content

Instantly share code, notes, and snippets.

@bergie
Last active July 24, 2026 04:31
Show Gist options
  • Select an option

  • Save bergie/b075768c4ec7eb519bdcd8c3e1b7bca9 to your computer and use it in GitHub Desktop.

Select an option

Save bergie/b075768c4ec7eb519bdcd8c3e1b7bca9 to your computer and use it in GitHub Desktop.
Reticulum interface discovery location_cmd for Signal K
#!/bin/env python3
import urllib.request
import json
import sys
# Replace with your actual Signal K server address and port
# (e.g., http://localhost:3000/signalk/v1/api/vessels/self/navigation/position)
SIGNALK_URL = "http://192.168.2.105/signalk/v1/api/vessels/self/navigation/position"
def fetch_signalk_position(url):
try:
# 1. Fetch the JSON document
req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
with urllib.request.urlopen(req) as response:
if response.status == 200:
raw_data = response.read().decode('utf-8')
# 2. Parse the JSON document
parsed_data = json.loads(raw_data)
# 3. Extract the position payload
# Signal K REST API often nests the data inside a 'value' object.
# If you queried the '.../position/value' endpoint directly, it won't be nested.
# Using .get("value", parsed_data) safely handles both scenarios.
position = parsed_data.get("value", parsed_data)
lat = position.get("latitude")
lon = position.get("longitude")
# Altitude might not be present from all GPS sources, defaulting to 0.0
alt = position.get("altitude", 0.0)
# 4. Format and write the string to STDOUT
if lat is not None and lon is not None:
formatted_string = f"{lat}, {lon}, {alt}\n"
sys.stdout.write(formatted_string)
sys.stdout.flush()
else:
sys.stderr.write("Error: 'latitude' or 'longitude' not found in the response payload.\n")
else:
sys.stderr.write(f"Failed with HTTP Status: {response.status}\n")
except urllib.error.URLError as e:
sys.stderr.write(f"Connection Error: {e.reason}\n")
except json.JSONDecodeError:
sys.stderr.write("JSON Parse Error: The response from the server was not valid JSON.\n")
except Exception as e:
sys.stderr.write(f"An unexpected error occurred: {e}\n")
if __name__ == "__main__":
fetch_signalk_position(SIGNALK_URL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment