OpenMarine
OpenPlotter data to Python - 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: OpenPlotter data to Python (/showthread.php?tid=3258)

Pages: 1 2


OpenPlotter data to Python - Jodel - 2021-02-06

Hi,
I am experimenting with trying to get data from OpenPlotter into a Python program.   I can do it by adding an output connection in Opencpn using UDP on a specified port. I am wondering if this is the correct way?  
Adding a connection in Signalk always adds an input (not output) to Signalk.  There seem to be no option to define an output like in Opencpn.  Is it better to take the data directly from SignalK?  If so is there a simple way to tell it to stream all its data in NMEA format to a udp port?


Jodel


RE: OpenPlotter data to Python - PaddyB - 2021-02-07

Inputs are also outputs , have a look here >> https://github.com/SignalK/signalk-server/wiki/Events-and-Outputting-Data


RE: OpenPlotter data to Python - Jodel - 2021-02-07

Thanks for that link.  While it mainly refers to serial communications I notice that TCP can also be bi-directional. I'll keep experimenting.


RE: OpenPlotter data to Python - PaddyB - 2021-02-07

(2021-02-07, 06:28 PM)Jodel Wrote: Thanks for that link.  While it mainly refers to serial communications I notice that TCP can also be bi-directional. I'll keep experimenting.

Yes didn't notice that it only referred to serial. 
Why not use the default tcp connection? Connect to port 10110 on localhost, all nmea goes out of that, it's what feeds opencpn. No problem connecting in addition to opencpn, I just tried it in node red >
[Image: oSXwRDg.png]


RE: OpenPlotter data to Python - Jodel - 2021-02-07

Thanks.  That worked perfectly.  I was expecting to have to configure connections on Signalk, not realising that it was there already.  
In case anyone is interested, the Python to get a stream of all the NMEA data is as follows:

import socket

HOST = '127.0.0.1'  # The server's hostname or IP address
PORT = 10110        # The port used by the server

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))

while True:
    data = s.recv(1024)
    print (repr(data))

This produces a stream of NMEA like this:

Python 3.7.3 (/usr/bin/python3)
>>> %Run ReadTCP.py
b'$IIMWV,353,T,13.95,N,A*2E\r\n'
b'$IIVWT,007,L,13.95,N,07.18,M,,*2D\r\n'
b'$IIHDT,,T*0C\r\n'
b'$GPWCV,,N,,D*5F\r\n'
b'$GPXTE,A,A,,R,N,D*06\r\n'
b'$GPZDA,112924,,,,00,*45\r\n'
b'$IIDBT,016.76,f,005.11,M,002.76,F*21\r\n'
b'$GPGLL,5959.272,N,02326.085,E,112924,A,D*40\r\n'
b'$GPGSV,,,,,,,,,,,,,,,,,,,*79\r\n'
b'$IIHDM,,M*0C\r\n'
b'$IIHDT,,T*0C\r\n'
b'$IIMWD,,,,,13.29,N,06.84,M*5E\r\n'

Not sure where the " b' " comes from !


RE: OpenPlotter data to Python - PaddyB - 2021-02-07

(2021-02-07, 10:15 PM)Jodel Wrote: Not sure where the " b' " comes from !

I think python does that to show that the data is coming in as bytes?


RE: OpenPlotter data to Python - Jodel - 2021-02-07

(2021-02-07, 10:32 PM)PaddyB Wrote:
(2021-02-07, 10:15 PM)Jodel Wrote: Not sure where the " b' " comes from !

I think python does that to show that the data is coming in as bytes?

Yes, that seem to be why the b is there. Thanks


RE: OpenPlotter data to Python - tkurki - 2021-02-08

Why nmea0183 over tcp and not JSON over WebSocket? Python has the tools for both, and with SK data you skip the decoding part and are set for future n2k and non nmea data extension. Kinda the fundamental idea with Signal K. OpenCPN already supports sk input and is moving further in that direction.

With ws you’d have optional ssl and access control.

There’s also https://github.com/ph1l/python-signalk-client, but it is inactive or abandoned.


RE: OpenPlotter data to Python - Jodel - 2021-02-08

(2021-02-08, 07:10 AM)tkurki Wrote: Why nmea0183 over tcp and not JSON over WebSocket? Python has the tools for both, and with SK data you skip the decoding part and are set for future n2k and non nmea data extension. Kinda the fundamental idea with Signal K. OpenCPN already supports sk input and is moving further in that direction.

With ws you’d have optional ssl and access control.

There’s also https://github.com/ph1l/python-signalk-client, but it is inactive or abandoned.

Thanks, I will try that approach as well.
Where I am hoping to get to eventually is to get a Raspberry Pi Pico and run Micro Python on it.  I was hoping to attach a suitable small display to show data such as Bearing to Waypoint, Track and speed etc.. 
A monochrome display that was sunlight readable would be ideal. Something like a normal cockpit display (approx 100 mm.)


RE: OpenPlotter data to Python - PaddyB - 2021-02-08

(2021-02-08, 12:42 PM)Jodel Wrote: Thanks, I will try that approach as well.
Where I am hoping to get to eventually is to get a Raspberry Pi Pico and run Micro Python on it.  I was hoping to attach a suitable small display to show data such as Bearing to Waypoint, Track and speed etc.. 
A monochrome display that was sunlight readable would be ideal. Something like a normal cockpit display (approx 100 mm.)

Aother option is to send the data as mqtt from node-red on the Pi. 

Though I still need to get a websocket up and running in micropython so please update, always interesting  Smile