Cruisers Forum
 


Join CruisersForum Today

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 20-02-2020, 13:10   #1
Registered User

Join Date: Feb 2020
Boat: Dehler 35 CWS
Posts: 3
OpenCPN Dashboard - NMEA VWR sentence

Hello All,


Very happy with our new OpenCPN setup, brilliant program, many compliments to dev!
One think I came across however was that the dashboard was not able to read my old windsensor's IIVWR sentence, allthough the dashboard plugin usermanual describes it explicitely. The sentence was visible in the NMEA debug window, but the windmeter kept showing zero.

I suspect that there is a bug in the plugin, since the very first time I was trying this, wind was coming from Starboard, making the VWR sentence have an "R". At that time I did had readings in the dashboard gauges.

Later however the wind kept coming from port side, VWR showing an "L" and all meters kept showing zero.
I studied the manuals and source code of the NMEA converter plugin but this plugin seems not to be designed to convert on old VWR sentence into something more modern. The plug in would need some redesign in order to be able to do this.
So I decided to write a small python script. This script starts when my computer with OpenCPN starts (Raspberry Pi) using crontab.
The script reads the serial USB port. If it reads VWR, it converts this into a more accepted MWV sentence. Simple math. And just because it is fun I also add a new checksum.
All other sentences are just left untouched and passed through.
The sentences are broadcasted not via the same USB port (since 1 port can only be used by 1 process as far as I know, and not by OpenCPN anymore) but via UDP to localhost (127.0.0.1) via a random port (5005).
OpenCPN gets a new connection selecting exactly these settings and voila, I have VWR sentence (and all other sentences, which are useless in my case). And the dashboard windmeter eats them happily.
For completeness I put my python code below. Unfortunately the forum software does not keep the required indentation for python.

Maybe the maintainers of OpenCPN could have a look on the dashboard code to read old VWR sentence, since I think something is wrong there. However, my work around works just as well and I can imagine that it is very hard to keep thinks up and running for each and every ancient NMEA sentence.



Best regards,


Mark




#Python function to convert NMEA old VWR sentence into MWV
#MWV fields:wind angle 0-359 deg, R(=relative) or T(=true), wind speed, windspeed units (K=knots), status (A=valid, V=invalid, checksum
#VWR fields: wind angle 0-180, L or R, speed, N=knots

import serial
import time
import socket
import struct
import sys

ser = serial.Serial('/dev/ttyUSB0', 4800, timeout=1)

UDP_IP = "127.0.0.1"
UDP_PORT = 5005
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

def calc_checksum(sentence):
checksum = 0

try:
message_for_checksum = sentence.split("*")[0].split("$")[1]

for i in message_for_checksum:
checksum ^= ord(i)

except IndexError:
print('invalid NMEA string')

except:
print('geen idee wat er nu aan de hand is:', sys.exc_info()[0])

return ("%0.2X" % checksum)


def convertIIVWR(IIVWRsentence):

fields = IIVWRsentence.split(",")
print(fields)
#fields[0] = IIVWR
windangle = int(fields[1])##relative angle 0-180 degrees
#fields[2] = L or R
windspeed = fields[3]
if fields[2] == "L" and windangle > 0:
windangle = str(360 - int(fields[1]))


MWVsentence = "$MWV," + windangle + ".0,R," + windspeed + ",N,A*"

checksum = calc_checksum(MWVsentence)
MWVsentence = "$" + MWVsentence + checksum
return MWVsentence


if __name__ == "__main__":
while True:
time.sleep(.5)
message_string = ser.readline().decode("utf-8")
print(calc_checksum(message_string))
print(message_string)

if "IIVWR" in message_string:
try:
message_string = convertIIVWR(message_string)
print(message_string)
except:
pass
sock.sendto(message_string.encode(), (UDP_IP, UDP_PORT))
__________________

Sindbad2p0 is offline   Reply With Quote
Old 20-02-2020, 13:52   #2
Registered User

Join Date: Dec 2009
Location: Norway
Boat: Saxe Ocean
Posts: 20
Re: OpenCPN Dashboard - NMEA VWR sentence

Kudos for creativity, but did you have a look at the NMEA-Converter plugin?
https://opencpn.org/wiki/dokuwiki/do...nmea_converter
__________________

SamH is offline   Reply With Quote
Old 21-02-2020, 08:35   #3
Registered User

Join Date: Feb 2020
Boat: Dehler 35 CWS
Posts: 3
Re: OpenCPN Dashboard - NMEA VWR sentence

Hello!


I did study the NMEA converter plug-in:


Quote:
I studied the manuals and source code of the NMEA converter plugin but this plugin seems not to be designed to convert on old VWR sentence into something more modern. The plug in would need some redesign in order to be able to do this.
Sindbad2p0 is offline   Reply With Quote
Old 22-02-2020, 15:57   #4
Registered User

Join Date: Nov 2012
Location: Orust Sweden
Boat: Najad 34
Posts: 2,792
Re: OpenCPN Dashboard - NMEA VWR sentence

Mark..
VWR would work in Dashboard although the code presume wind speed is given in knots, third position.

Do you've some of your VWR example messages we could check and try?
Håkan
Hakan is offline   Reply With Quote
Old 23-02-2020, 04:33   #5
Registered User

Join Date: Feb 2020
Boat: Dehler 35 CWS
Posts: 3
Re: OpenCPN Dashboard - NMEA VWR sentence

Hello Hakan,


Herewith a sentence:


$IIVWR,066,L,16.3,N,,,,


Speed in knots. No checksum. In the connection dialog of opencpn I switched this off.


I am curious to learn what goes wrong at my side.


best regards,


Mark
Sindbad2p0 is offline   Reply With Quote
Old 23-02-2020, 10:18   #6
Registered User

Join Date: Nov 2012
Location: Orust Sweden
Boat: Najad 34
Posts: 2,792
Re: OpenCPN Dashboard - NMEA VWR sentence

Mark..
I'll check and come back.
One note so far: I'm not sure the "No checksum" option in "Connections" are working good. Have heard somthing about that here. It may need some tweaking.

Håkan
Hakan is offline   Reply With Quote
Old 23-02-2020, 11:13   #7
Registered User

Join Date: Nov 2012
Location: Orust Sweden
Boat: Najad 34
Posts: 2,792
Re: OpenCPN Dashboard - NMEA VWR sentence

Mark..
Your sentence is working fine as long you add a checksum.
If I try without the checksum option it's not working. Also If I deselect [] Use Checksum and "Apply"-"OK" next time I return to "Connections" it's there selected again. Some bug I suppose.


Håkan
Attached Thumbnails
Click image for larger version

Name:	VWR.jpg
Views:	26
Size:	95.2 KB
ID:	209292  
__________________

Hakan is offline   Reply With Quote
Reply

Tags
enc, nmea, opencpn

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opencpn - nmea sentence generator new_to_cuiser OpenCPN 28 17-10-2017 17:43
Opencpn crashes when receiving WIMDA nmea sentence, conachair OpenCPN 25 03-10-2017 03:18
NMEA sentence for the dashboard Nick_Currawong OpenCPN 8 31-05-2017 21:54
OpenCPN and NMEA sentence dmoore OpenCPN 8 21-12-2012 13:47
MOB NMEA sentence Cavalier Marine Electronics 13 27-08-2012 10:12

Advertise Here


All times are GMT -7. The time now is 03:01.


Google+
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Social Knowledge Networks
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2020, vBulletin Solutions, Inc.

ShowCase vBulletin Plugins by Drive Thru Online, Inc.