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.
#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
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)
checksum = 0
message_for_checksum = sentence.split("*").split("$")
for i in message_for_checksum:
checksum ^= ord(i)
print('invalid NMEA string')
print('geen idee wat er nu aan de hand is:', sys.exc_info())
return ("%0.2X" % checksum)
fields = IIVWRsentence.split(",")
#fields = IIVWR
windangle = int(fields)##relative angle 0-180 degrees
#fields = L or R
windspeed = fields
if fields == "L" and windangle > 0:
windangle = str(360 - int(fields))
MWVsentence = "$MWV," + windangle + ".0,R," + windspeed + ",N,A*"
checksum = calc_checksum(MWVsentence)
MWVsentence = "$" + MWVsentence + checksum
if __name__ == "__main__":
message_string = ser.readline().decode("utf-8")
if "IIVWR" in message_string:
message_string = convertIIVWR(message_string)
sock.sendto(message_string.encode(), (UDP_IP, UDP_PORT))