NMEA Checksum Calculator

This function node expects a string in msg.payload sentence without "$" and "*".

For example: msg.payload = GPGLL,3751.65,S,14507.36,E

It will then calculate the checksum, convert the checksum from Decimal to HEX and add this together with the "$" and "*" to msg.payload.


var checksum = 0; for(var i = 0; i < msg.payload.length; i++) { checksum = checksum ^ msg.payload.charCodeAt(i); } msg.payload = "$" + msg.payload + "*" + checksum.toString(16); return msg;

[{"id":"89015d31.788b8","type":"inject","z":"a7b2390e.90d3a8","name":"NMEA Sentence","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"GPGLL,3751.65,S,14507.36,E","payloadType":"str","x":200,"y":1020,"wires":[["41184f92.f8d73"]]},{"id":"41184f92.f8d73","type":"function","z":"a7b2390e.90d3a8","name":"","func":"var checksum = 0;\nfor(var i = 0; i < msg.payload.length; i++) {\n  checksum = checksum ^ msg.payload.charCodeAt(i);\n}\nmsg.payload = \"$\" + msg.payload + \"*\" +  checksum.toString(16);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":1020,"wires":[["116b1aa3.dc3d75"]]},{"id":"116b1aa3.dc3d75","type":"debug","z":"a7b2390e.90d3a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":630,"y":1020,"wires":[]}]

Flow Info

Created 2 years, 8 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • debug (x1)
  • function (x1)
  • inject (x1)

Tags

  • NMEA
  • Checksum
  • $
  • *
  • Hex
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option