# NMEA Checksum calculation

**URL:** <https://discourse.nodered.org/t/nmea-checksum-calculation/77002>\
**Category:** General\
**Created:** [28 March 2023 03:18 UTC](https://discourse.nodered.org/t/nmea-checksum-calculation/77002 "2023-03-28T03:18:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arnie419](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/arnie419/32/78066_2.png) [@Arnie419](https://discourse.nodered.org/u/Arnie419)\
**Post date:** [28 March 2023 03:18 UTC](https://discourse.nodered.org/t/nmea-checksum-calculation/77002/1 "2023-03-28T03:18:08Z")

</div>

Am rebuildng an exisintg NMEA sentence from a weathersensor into another NMEA format but when doing the checksum at the final end of the NMEA sentence i do get small letters while the NMEA standard describes that every checksum must consist capital letters.  
I will show here the difference:  
This is a sentence generated by a NMEA simulator which is good:  
$WIMTA,22.5,C_1E (Capital letter at the end)  
This is a sentence generated by Node Red checksum calculator, which gives me a small letter:  
$WIMTA,22.5,C_1e (small letter at the end)

OpenCPN will accept this sentence but actually is not according official checksum format to NMEA standards.  
Is there any option to change this small letter into capital in the following code??

```auto
var checksum = 0;

msg.payload = "WIMTA," + msg.payload.value + ",C"

for (var i = 0; i < msg.payload.length; i++) {

checksum = checksum ^ msg.payload.charCodeAt(i);

}

msg.payload = "$" + msg.payload + "*" + checksum.toString(16);

return msg;

```

Hope somebody can help me.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [28 March 2023 06:00 UTC](https://discourse.nodered.org/t/nmea-checksum-calculation/77002/2 "2023-03-28T06:00:17Z")

</div>

> [@Arnie419](#):
>
> Is there any option to change this small letter into capital in the following code??

toUpperCase() should work.

```auto
msg.payload = "$" + msg.payload + "*" + checksum.toString(16).toUpperCase()

```

---

<div class="post-metadata">

**Author:** ![Arnie419](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/arnie419/32/78066_2.png) [@Arnie419](https://discourse.nodered.org/u/Arnie419)\
**Post date:** [28 March 2023 06:50 UTC](https://discourse.nodered.org/t/nmea-checksum-calculation/77002/3 "2023-03-28T06:50:27Z")

</div>

That worked 👍  
Many thanks for that.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [27 May 2023 06:50 UTC](https://discourse.nodered.org/t/nmea-checksum-calculation/77002/4 "2023-05-27T06:50:31Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
