Glinnes / NMEAParser

A simple and compact NMEA parser for Arduino
Other
14 stars 7 forks source link

Tips to improve stability #3

Open dotMorten opened 4 years ago

dotMorten commented 4 years ago

Found two issues and wanted to share the findings:

in setup() set timeout pretty low:

Serial.setTimeout(10);

In the loop reach in chunks:

char buf[1024];
int readCount;
void loop()
{
  if (Serial1.available()) {
    while((readCount = Serial.readBytes(buf, 1024)) > 0)
    {
      for(int i=0;i<readCount;i++)
        parser << buf[i];
    }
 }

With these two changes, all my parser errors went away. You might want to update the doc to suggest the read approach. Might only be an issue on slow arduino's?

ssozonoff commented 2 years ago

I am also randomly experiencing parse issues so for without any explanation. Seems like the parser in some instances does not "recover" from a failed parse ?? i.e. it will fail systematically on 60+ NMEA sentences. I can power down the system and bring it back up and then it will work.

Thanks for your tips

ssozonoff commented 2 years ago

Hello @dotMorten,

I agree with you.

I have a wind sensor which has a bit of a funky boot sequence.

It has a boot loader which sends some output at 19200 and then switches to the configured baud rate of 38400 and starts sending an MWV sentence, which is a short sentance.

I listen to the serial port until the first CR/LF sequence, which indicates the baud rate change and start of nmea sentences, and discard that data before I start feeding the nmea parser using similar code to what you mention. Generally this works fine but randomly it will fail to parse a single sentence for over 30 samples (i.e. about 30 seconds since data flow is 1Hz). It could be the sensor but I have doubts since

a. Its a commercial sensor already in use b. I have two of these sensors and both exhibit the same issues

Debugging is a little tricky due to the random nature of the problem.The host + sensor are powered up every 9min for 1 minute, 60 samples, and then powered down. So both the host and sensor forgo a full power cycle each time.

Parse error handler is called every time, I am still adding some debug to figure out if its always the same error code but I am assuming it is. If the sensor was sending no data the handler would not be called.

I am going to keep digging.

Thanks, Serge