Cruisers & Sailing Forums (https://www.cruisersforum.com/forums/)
-   OpenCPN (https://www.cruisersforum.com/forums/f134/)
-   -   Converting and sending data to opencpn using a script or program in Unix? (https://www.cruisersforum.com/forums/f134/converting-and-sending-data-to-opencpn-using-a-script-or-program-in-unix-226042.html)

peter- 03-11-2019 06:17

Converting and sending data to opencpn using a script or program in Unix?
 
Hi all

I'm recieving data from my weather station (wind, direction, temp etc) using a 433 mHz dongle that I would like to send to OpenCPN. I have been researching quite a bit but haven't been able to find a solution yet. The problem is basically that I recieve the data on the same computer as I'm running OpenCPN on using a script... but how do I take that data, convert it into NMEA and send it to an artificial port?

Has anyone done something similar, and how did you solve it? Is there a way to run scripts in OpenCPN?

Kind Regards,
Peter

boat_alexandra 03-11-2019 06:54

Re: Converting and sending data to opencpn using a script or program in Unix?
 
You can connect to opencpn using a socket to send the mwv nmea wind sentence.

transmitterdan 03-11-2019 07:07

Re: Converting and sending data to opencpn using a script or program in Unix?
 
Yes, you can do it if you convert your data to NMEA 0183 format and send it over the network. See github.com/transmitterdan/VDRplayer for an example of how to send already properly formatted NMEA data from a text file to OpenCPN via a network connection. You can modify that program to convert your weather station data and send it to OpenCPN or any other similar chart plotting device. They almost all accept NMEA data.

UDP is the preferred comm method but TCP also works.

peter- 03-11-2019 07:43

Re: Converting and sending data to opencpn using a script or program in Unix?
 
Thanks - that could solve my problem but:

1. I dont have a network yet so I would like to do it without hence why I was referring to the artificial serial port as a best guess. Does anything exist like VDRplayer but sending to a serial port rather than a network?

2. Once I get a network installed on my Raspberry Pi Model 3, the Pi will become a hotspot such that I can e.g. connect my tablet with OpenCPN and get all the data there but in a way I guess it won't solve the network problem for the weather data however as all my serial connections goes into my Raspberry Pi which on the same time is my router so I guess I can't really send anything over the network at that point either as I'll just be sending stuff to myself?

Kind Regards,
Peter

peter- 03-11-2019 08:09

Re: Converting and sending data to opencpn using a script or program in Unix?
 
So I found this:
https://en.wikipedia.org/wiki/Pseudoterminal

I'll try to dig around with that for a while, what I need is a virtual serial port.

Alternatively, I'll try to setup a network in my boat and use the VDRplayer, but that would not only require a router but also an additional Raspberry Pi or computer which is starting to potentially overcomplicate the hardware part along with unnessesary electricity consumption.

Kind Regards,
Peter

Hakan 03-11-2019 09:07

Re: Converting and sending data to opencpn using a script or program in Unix?
 
Peter.
If you've everything in the same machine your don't need a external network. Use UDP address LocalHost or 127.0.0.1 and a suitable port. 10110 is common for NMEA0183.

conachair 03-11-2019 09:08

Re: Converting and sending data to opencpn using a script or program in Unix?
 
Quote:

Originally Posted by peter- (Post 3008478)
Thanks - that could solve my problem but:

1. I dont have a network yet so I would like to do it without hence why I was referring to the artificial serial port as a best guess. Does anything exist like VDRplayer but sending to a serial port rather than a network?

What operating system are you using? If it's linux then installing signalk should make it possible.
Quote:

2. Once I get a network installed on my Raspberry Pi Model 3, the Pi will become a hotspot such that I can e.g. connect my tablet with OpenCPN and get all the data there but in a way I guess it won't solve the network problem for the weather data however as all my serial connections goes into my Raspberry Pi which on the same time is my router so I guess I can't really send anything over the network at that point either as I'll just be sending stuff to myself?
Pi should be fine, might need to do a little code to turn the data into signalk or nmea but someone could write that easy enough if you struggle.

povl 03-11-2019 09:08

Re: Converting and sending data to opencpn using a script or program in Unix?
 
You could use a program like Kplex (https://www.stripydog.com/kplex/), which can redirect NMEA data between network ports, files, and serial devices.

I sometimes work on a ship that only transmits relative wind data - and I want to view true wind directions and strengths in OpenCPN. I have written a C program that reads the relative wind data, gyro heading and COG/SOG, and computes true (ground) wind. OpenCPN reads all the nav data from the network, and sends these three sentences to Kplex (via TCP), where they are redirected to a FIFO file. My program reads from the file, writes to a different file, which then is read by Kplex and returned to OpenCPN, where the true wind is displayed in the dashboard. Slightly circuitous, but works perfectly once I figured out how to set it up!

Summary of my settings (for anyone interested):
In OpenCPN:
  • an incoming TCP connection to get nav data onto my computer
  • a bidirectional TCP connection to localhost on port 10110, accepts all incoming sentences, transmits only HDT,RMC,MWV
My .kplex.conf file:
Code:

[file]
filename=/path/to/temp_nmea_in
direction=out
persist=yes
ofilter=+**HDT:+**RMC:+**MWV:-all
[file]
filename=/path/to/temp_nmea_out
direction=in
persist=yes
[tcp]
mode=server
port=10110
direction=both
ofilter=+**MWD:+**MWV:-all

The two files temp_nmea_in and temp_nmea_out were created with the unix "mkfifo" command.

conachair 03-11-2019 09:17

Re: Converting and sending data to opencpn using a script or program in Unix?
 
Quote:

Originally Posted by povl (Post 3008550)
You could use a program like Kplex (Kplex: An NMEA-0183 Multiplexer), which can redirect NMEA data between network ports, files, and serial devices.

Not so much use if the data isn't nmea0183 though, as in this case.

Node-red could have it up and running in a few minutes :cool:

Peter - do you have a sample of the data coming in from the sensor?

povl 03-11-2019 09:27

Re: Converting and sending data to opencpn using a script or program in Unix?
 
Quote:

Originally Posted by conachair (Post 3008554)
Not so much use if the data isn't nmea0183 though, as in this case.

So, write a script that converts the data to a MWV sentence and get this to write to a FIFO; kplex can read those data and send them to OpenCPN via TCP (or UDP, if you prefer). Or you can do it in Node-red. There is more than one way to skin a cat...

conachair 03-11-2019 09:34

Re: Converting and sending data to opencpn using a script or program in Unix?
 
Quote:

Originally Posted by povl (Post 3008560)
There is more than one way to skin a cat...

Simplest prob in signalk, node-red in there already - then do what you want with it, convert to nmea/2k, save to database, send to web, save to a file..

peter- 03-11-2019 10:19

Re: Converting and sending data to opencpn using a script or program in Unix?
 
My data looks like this:

Code:

Temperature: 6.0 C
Wind string: E
Wind Degrees: 90
Wind ave speed: 11.02
Wind gust: 14.69

I'm running as Raspberry Pi with Raspbian Unix. I was looking at something called pseudoterminals but I'll try as mentioned.

Does anyone have a good list over NMEA sentences so I can send the correct syntax? I prefer to convert myself so I have proper control. Anyone know if you can send both wind average and wind gust info over NMEA? I'm using a weather station because it is a very cheap solution compared to other solutions and it is wireless so I didn't have to pull any cables and don't mind climbing the mast once a year to change batteries...

Kind Regards,
Peter

conachair 03-11-2019 10:32

Re: Converting and sending data to opencpn using a script or program in Unix?
 
Quote:

Originally Posted by peter- (Post 3008591)
My data looks like this:

Code:

Temperature: 6.0 C
Wind string: E
Wind Degrees: 90
Wind ave speed: 11.02
Wind gust: 14.69

I'm running as Raspberry Pi with Raspbian Unix. I was looking at something called pseudoterminals but I'll try as mentioned.

Does anyone have a good list over NMEA sentences so I can send the correct syntax? Anyone know if you can send both wind average and wind gust info over NMEA?

If you are on a Pi try installing the not quite yet released openplotter V2 -
OpenPlotter 2 roadmap

I did it couple days ago, very easy and looks great so far, just a few bits missing.
That will install node red when installing the wonderful signalk. So you should be able to set up a serial port as a node-red input , then turn the data into nmea.

transmitterdan 03-11-2019 11:50

Converting and sending data to opencpn using a script or program in Unix?
 
If you are only using one computer then UDP is still the easiest method. It works on all platforms supported by O. You donít need any serial port. Just send your data messages to localhost or 127.0.0.1. All computers have this capability.

peter- 03-11-2019 11:59

Re: Converting and sending data to opencpn using a script or program in Unix?
 
So you to make sure that I understand it correctly:

Step 1: Have a script that pulls the data from my weather station 433MHz and saves it to a file.
Step 2: Use node-red to pickup the file and inject it into signalk
Step 3: Convert it to NMEA in Signalk and save to another file
Step 4: Use node-red to inject into OpenCPN.


I think the following would be easier to:
Step 1: Read weather station data, convert into NMEA (such as $GPMWV,318.00,R,14.80,N,A*1D) and save in file.
Step 2: Injection file into OpenCPN using node-red and http:/ / localhost : 1880]

Am I understanding this correctly?


Kind Regards,
Peter


All times are GMT -7. The time now is 17:34.

Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2020, vBulletin Solutions, Inc.


ShowCase vBulletin Plugins by Drive Thru Online, Inc.