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
Why the wind instuments output MWV and not VMR
#5
I played a little bit with node-red and finally I've got some expected output...
I managed to make node-red to "read" environment.wind.speedApparent and environment.wind.speedApparent and send as MWV sentence. 
It is made for MWV but will be very easy to change it to VWR, as you need. Just edit the MWV function

The node-red code, bellow. Just copy and paste it into node-red clipboard.
Code:
[{"id":"e4d4603d.6a578","type":"signalk-subscribe","z":"ee22123e.a5ff8","name":"windApparent","mode":"sendAll","flatten":true,"context":"vessels.self","path":"environment.wind.*Apparent","source":"","period":1000,"x":110,"y":40,"wires":[["e4f6bc29.01868"]],"outputLabels":["angle"]},{"id":"e4f6bc29.01868","type":"function","z":"ee22123e.a5ff8","name":"MWV","func":"var S = context.get(\"S\") || 0; //get from context or default to 0\nvar A = context.get(\"A\") || 0; //get from context or default to 0\n\nswitch (msg.topic){\n    case \"environment.wind.speedApparent\":\n        S = msg.payload; //payload NOT paydoad  :)\n        context.set(\"S\", S); //store in context for next time \n        break;\n    case \"environment.wind.angleApparent\":\n        A = msg.payload; //payload NOT paydoad  :)\n        context.set(\"A\", A); //store in context for next time \n        break;\n}\n\nmsg.temp = \"WIMWV,\" + A.toFixed(2) + \",R,\" + S.toFixed(2) + \",N,A\";\n\nvar nmea = msg.temp;\nvar checksum = 0; \n\nfor(var i = 0; i < nmea.length; i++) { \n  checksum = checksum ^ nmea.charCodeAt(i); \n}\nchecksum = checksum.toString(16);    //convert to hex\nnmea = '$' + nmea + '*' + checksum;  //make the full nmea sentence again\n\nmessage =  nmea + '\\r\\n';\n\nmsg.topic = \"WIMWV\";\nmsg.payload  = message;\nreturn msg;\n\n","outputs":1,"noerr":0,"x":290,"y":40,"wires":[["f6e4875e.141ea8"]]},{"id":"cbb96f97.6bade","type":"debug","z":"ee22123e.a5ff8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":450,"y":100,"wires":[]},{"id":"1fa02e62.c03462","type":"signalk-send-nmea0183","z":"ee22123e.a5ff8","name":"","nmea0183Event":"nmea0183out","x":490,"y":140,"wires":[]},{"id":"f6e4875e.141ea8","type":"delay","z":"ee22123e.a5ff8","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":270,"y":140,"wires":[["1fa02e62.c03462","cbb96f97.6bade"]]}]

I also have to thanks to PaddyB for his help guiding me in the right direction.
Any comments and critics are welcome, this is my first node-red code and any hints will be appreciate it.

Fair winds,
Seb
- SV Haimana
Reply


Messages In This Thread
RE: Why the wind instuments output MWV and not VMR - by sebba - 2020-01-26, 08:37 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)