I’ve managed to make some excellent improvements to the AssetTracker library. I’ve still got my debug statements in there, but you can take a look at it (and run the default example) here:
Let’s see if I can remember the major things I did to the original library:
1] If there is a carriage return, turn it into a linefeed. (Either character will end a sentence.)
2] Never actually add a carriage return or linefeed into the string to be parsed. This greatly helps to standardize the offsets in a line.
3] If a string is blank (just a CR or LF) don’t promote it for processing.
4] Minor change to the handling of ‘$’ which probably is not necessary but made me feel better.
5] Changed the offset for ‘’ to reflect lack of CR/LF in the string to be parsed
6] Changed the offset for the checksum to reflect the lack of CR/LF in the string to be parsed
7] If a line does not have a '’ in the right place, immediately reject it instead of always turning it over for parsing.
It looks like it is now processing strings pretty solid. Actually, I’m also not seeing any of the crazy bad lines anymore! That’s odd. My sample output below. Again, I’ve changed my GPS coordinates to preserve my privacy. If you try to verify the checksum by hand, it won’t add up.
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$PGACK,103*40<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$PGACK,105*46<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$PMTK011,MTKGPS*08<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221056.656,A,2206.2358,N,03356.2144,W,0.16,337.85,230316,,,A*70<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221106.677,A,2206.2322,N,03356.2057,W,0.38,101.63,230316,,,A*7A<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221116.643,A,2206.2367,N,03356.2145,W,0.11,330.46,230316,,,A*73<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221127.000,A,2206.2369,N,03356.2140,W,0.32,92.63,230316,,,A*46<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
22.103947,-33.936897
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221137.000,A,2206.2351,N,03356.2139,W,0.39,130.30,230316,,,A*76<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221147.000,A,2206.2337,N,03356.2134,W,0.69,141.61,230316,,,A*7B<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221208.000,A,2206.2339,N,03356.2126,W,0.67,139.61,230316,,,A*7F<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221228.000,A,2206.2345,N,03356.2128,W,0.43,72.72,230316,,,A*42<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
22.103909,-33.936882
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221238.000,A,2206.2355,N,03356.2133,W,0.19,74.46,230316,,,A*46<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221258.000,A,2206.2349,N,03356.2119,W,0.62,131.31,230316,,,A*79<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221318.000,A,2206.2345,N,03356.2116,W,0.42,99.57,230316,,,A*4E<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221329.000,A,2206.2360,N,03356.2124,W,0.26,88.65,230316,,,A*49<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
22.103935,-33.936867
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221339.000,A,2206.2360,N,03356.2115,W,0.36,40.17,230316,,,A*4A<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221349.000,A,2206.2368,N,03356.2108,W,0.26,110.34,230316,,,A*7D<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221429.000,A,2206.2348,N,03356.2087,W,0.22,169.67,230316,,,A*74<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
22.103916,-33.936813
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRM.60,91<END
------------------------------------------------
DEBUG: Checksum missing, character in checksum position is: 0
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221450.000,A,2206.2349,N,03356.2111,W,0.33,149.92,230316,,,A*7D<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221510.000,A,2206.2350,N,03356.2109,W,0.26,98.86,230316,,,A*45<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221520.000,A,2206.2349,N,03356.2100,W,0.47,106.51,230316,,,A*7C<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221530.000,A,2206.2345,N,03356.2085,W,0.47,138.50,230316,,,A*71<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
22.103909,-33.936813
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221540.000,A,2206.2335,N,03356.2076,W,0.26,197.92,230316,,,A*71<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221550.000,A,2206.2329,N,03356.2079,W,0.36,84.17,230316,,,A*4D<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221600.000,A,2206.2330,N,03356.2067,W,0.11,209.84,230316,,,A*74<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
22.103882,-33.936783
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221640.000,A,2206.2309,N,03356.2093,W,0.40,98.60,230316,,,A*45<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221700.000,A,2206.2316,N,03356.2087,W,0.16,293.69,230316,,,A*78<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
22.103863,-33.936813
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221750.000,A,2206.2358,N,03356.2124,W,0.42,26.98,230316,,,A*4C<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221800.000,A,2206.2360,N,03356.2124,W,0.10,147.35,230316,,,A*7B<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221830.000,A,2206.2350,N,03356.2121,W,0.23,72.09,230316,,,A*46<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
22.103920,-33.936867
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221840.000,A,2206.2353,N,03356.2114,W,0.10,30.24,230316,,,A*4D<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221850.000,A,2206.2356,N,03356.2112,W,0.43,116.32,230316,,,A*7B<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,221910.000,A,2206.2347,N,03356.2093,W,0.02,195.96,230316,,,A*76<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
22.103909,-33.936813
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222010.000,A,2206.2348,N,03356.2112,W,0.22,85.35,230316,,,A*40<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222020.000,A,2206.2349,N,03356.2105,W,0.39,79.22,230316,,,A*4B<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222030.000,A,2206.2351,N,03356.2092,W,0.15,151.17,230316,,,A*7F<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
22.103920,-33.936813
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222050.000,A,2206.2343,N,03356.2086,W,0.23,180.94,230316,,,A*7D<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222110.000,A,2206.2341,N,03356.2093,W,0.31,31.89,230316,,,A*4A<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222120.000,A,2206.2348,N,03356.2088,W,0.19,26.37,230316,,,A*43<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222130.000,A,2206.2353,N,03356.2085,W,0.18,127.85,230316,,,A*7D<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
22.103924,-33.936813
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222150.000,A,2206.2350,N,03356.2082,W,0.18,28.74,230316,,,A*4F<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222200.000,A,2206.2354,N,03356.2080,W,0.43,173.62,230316,,,A*79<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222220.000,A,2206.2338,N,03356.2088,W,0.22,302.36,230316,,,A*7B<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
22.103897,-33.936813
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222240.000,A,2206.2352,N,03356.2106,W,0.24,270.66,230316,,,A*71<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222310.000,A,2206.2345,N,03356.2118,W,0.10,287.10,230316,,,A*72<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222320.000,A,2206.2346,N,03356.2121,W,0.59,85.12,230316,,,A*47<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222330.000,A,2206.2365,N,03356.2142,W,0.14,73.71,230316,,,A*47<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
22.103943,-33.936897
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222340.000,A,2206.2373,N,03356.2131,W,0.42,86.11,230316,,,A*4C<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222400.000,A,2206.2380,N,03356.2092,W,0.40,109.82,230316,,,A*75<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222430.000,A,2206.2384,N,03356.2061,W,0.59,114.15,230316,,,A*74<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
22.103970,-33.936768
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222440.000,A,2206.2373,N,03356.2025,W,0.46,123.12,230316,,,A*76<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222450.000,A,2206.2373,N,03356.2019,W,0.57,75.13,230316,,,A*4B<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222500.000,A,2206.2378,N,03356.2006,W,0.23,135.46,230316,,,A*7C<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222510.000,A,2206.2376,N,03356.2007,W,0.10,195.95,230316,,,A*76<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222520.000,A,2206.2374,N,03356.2008,W,0.36,130.67,230316,,,A*7E<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
22.103954,-33.936684
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222540.000,A,2206.2361,N,03356.1994,W,0.23,167.96,230316,,,A*7B<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222550.000,A,2206.2355,N,03356.1994,W,0.15,123.87,230316,,,A*78<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222600.000,A,2206.2353,N,03356.1991,W,0.34,186.90,230316,,,A*77<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222620.000,A,2206.2336,N,03356.1986,W,0.58,120.15,230316,,,A*7B<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222630.000,A,2206.2352,N,03356.2016,W,0.54,88.98,230316,,,A*41<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
22.103920,-33.936684
DEBUG: Evaluating NMEA sentence ----------------------
BEGIN>$GPRMC,222640.000,A,2206.2357,N,03356.2005,W,0.37,130.18,230316,,,A*7E<END
------------------------------------------------
DEBUG: Checksum is good
DEBUG: Continuing with NMEA sentence parser
PS: If you visit the link at GitHub, sorry if my changes are ugly. My primary role is not that of a programmer, and I really don’t have a great understanding of the language that the Electron uses.