This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
OpenPlotter data to Python
#1
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
Reply
#2
Inputs are also outputs , have a look here >> https://github.com/SignalK/signalk-serve...tting-Data
Reply
#3
Thanks for that link.  While it mainly refers to serial communications I notice that TCP can also be bi-directional. I'll keep experimenting.
Reply
#4
(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]
Reply
#5
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 !
Reply
#6
(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?
Reply
#7
(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
Reply
#8
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.
Reply
#9
(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.)
Reply
#10
(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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)