OpenMarine
Python client to query SignalK server for GPS position - Printable Version

+- OpenMarine (https://forum.openmarine.net)
+-- Forum: OpenPlotter (https://forum.openmarine.net/forumdisplay.php?fid=1)
+--- Forum: How do I...? (https://forum.openmarine.net/forumdisplay.php?fid=3)
+--- Thread: Python client to query SignalK server for GPS position (/showthread.php?tid=4119)



Python client to query SignalK server for GPS position - olewsaa - 2022-06-21

I'm looking for a simple python script to read GPS data from the SignalK server. A simple script asking for a lat/long
string to get the current position, returning and then exit.

I have another RPi serving the SSB radio. This would benefit from having an automated position update with automatic 
conversion to ham radio grid syntax. 
The PAT software has (not fully implemented yet) an entry for gpsd, but my OpenPlotter does not run gpsd, hence the
wish for requesting it from SignalK.


RE: Python client to query SignalK server for GPS position - Sailoog - 2022-06-22

Code:
import ujson, requests
resp = requests.get('http://localhost:3000/signalk/v1/api/vessels/self/navigation/position/value', verify=False)
data = ujson.loads(resp.content)
print(data)
print(data['longitude'])
print(data['latitude'])

this should print:

Code:
{"longitude":24.7344517,"latitude":59.7205103}
24.7344517
59.7205103