Parsing NMEA sentences without library

Hi i'm trying to get GPS data from my SIM808, without use of librarys..
i've found this code it works quite good but i need some improvement becouse some times it gives some
error.. especially if use it with esp32 or mega 2560..
With esp32 it give me an error wich seems to be "application attempted to dereference a NULL pointer".
And with mega it restart the board (i see "serial begin ok" every loop).

Please can someone help me..or if someone have already done something like this i will appreciate so much.. this is the code i'm using

#define mySerial Serial2

char frame[100];
byte GNSSrunstatus;;
byte Fixstatus;
char UTCdatetime[18];
char latitude[11];
char logitude[11];
char altitude[8];
char speedOTG[6];
char course[6];
byte fixmode;
char HDOP[4];
char PDOP[4];
char VDOP[4];
char satellitesinview[2];
char GNSSsatellitesused[2];
char GLONASSsatellitesused[2];
char cn0max[2];
char HPA[6];
char VPA[6];
float latGPS;
float longGPS;


void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.println("Serial begin ok");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("AT");
  mySerial.println("AT+CGNSPWR=1");
  delay(10000);
}

void loop() { // run over and over
  get_GPS();
  delay(10000);
}


int8_t get_GPS() {

  int8_t counter, answer;
  long previous;

  // First get the NMEA string
  // Clean the input buffer
  while ( mySerial.available() > 0) mySerial.read();
  // request Basic string
  mySerial.println("AT+CGNSINF"); //sendATcommand("AT+CGNSINF", "AT+CGNSINF\r\n\r\n", 2000);

  counter = 0;
  answer = 0;
  memset(frame, '\0', sizeof(frame));    // Initialize the string
  previous = millis();
  // this loop waits for the NMEA string
  do {

    if (mySerial.available() != 0) {
      frame[counter] = mySerial.read();
      counter++;
      // check if the desired answer is in the response of the module
      if (strstr(frame, "OK") != NULL)
      {
        answer = 1;
      }
    }
    // Waits for the asnwer with time out
  }
  while ((answer == 0) && ((millis() - previous) < 2000));
  frame[counter - 3] = '\0';

  // Parses the string
  strtok_single(frame, ": ");
  GNSSrunstatus = atoi(strtok_single(NULL, ","));;// Gets GNSSrunstatus
  Fixstatus = atoi(strtok_single(NULL, ",")); // Gets Fix status
  strcpy(UTCdatetime, strtok_single(NULL, ",")); // Gets UTC date and time
  strcpy(latitude, strtok_single(NULL, ",")); // Gets latitude
  strcpy(logitude, strtok_single(NULL, ",")); // Gets longitude
  strcpy(altitude, strtok_single(NULL, ",")); // Gets MSL altitude
  strcpy(speedOTG, strtok_single(NULL, ",")); // Gets speed over ground
  strcpy(course, strtok_single(NULL, ",")); // Gets course over ground
  fixmode = atoi(strtok_single(NULL, ",")); // Gets Fix Mode
  strtok_single(NULL, ",");
  strcpy(HDOP, strtok_single(NULL, ",")); // Gets HDOP
  strcpy(PDOP, strtok_single(NULL, ",")); // Gets PDOP
  strcpy(VDOP, strtok_single(NULL, ",")); // Gets VDOP
  strtok_single(NULL, ",");
  strcpy(satellitesinview, strtok_single(NULL, ",")); // Gets GNSS Satellites in View
  strcpy(GNSSsatellitesused, strtok_single(NULL, ",")); // Gets GNSS Satellites used
  strcpy(GLONASSsatellitesused, strtok_single(NULL, ",")); // Gets GLONASS Satellites used
  strtok_single(NULL, ",");
  strcpy(cn0max, strtok_single(NULL, ",")); // Gets C/N0 max
  strcpy(HPA, strtok_single(NULL, ",")); // Gets HPA
  strcpy(VPA, strtok_single(NULL, "\r")); // Gets VPA

  //converto stringa in numero per poterla confrontare
  longGPS = atof (logitude); 
  latGPS = atof (latitude);
       
  Serial.println("mia float latitudine");
  Serial.println(latGPS,6);
  Serial.println("mia float latitudine");
  Serial.println(longGPS,6);
  Serial.println("UTCdatetime");
  Serial.println(UTCdatetime);
  Serial.println("latitude"); 
  Serial.println(latitude);
  Serial.println("logitude");
  Serial.println(logitude);
   return answer;  
}


/* strtok_fixed - fixed variation of strtok_single */
static char *strtok_single(char *str, char const *delims)
{
    static char  *src = NULL;
    char  *p,  *ret = 0;
    if (str != NULL)
        src = str;
    if (src == NULL || *src == '\0')    // Fix 1
        return NULL;
    ret = src;                          // Fix 2
    if ((p = strpbrk(src, delims)) != NULL)
    {
        *p  = 0;
        src = ++p;
    }
    else
        src += strlen(src);
    return ret;
}

this is the string that i get using "AT+CGNSINF"

22:40:55.059 -> AT+CGNSINF
22:40:55.059 -> +CGNSINF: 1,1,20200407204053.000,45.817337,10.957775,699.400,0.24,27.5,1,,1.0,1.3,0.9,,10,9,,,39,,

Thank you very much!

What happens if this loop

  do {

    if (mySerial.available() != 0) {
      frame[counter] = mySerial.read();
      counter++;
      // check if the desired answer is in the response of the module
      if (strstr(frame, "OK") != NULL)
      {
        answer = 1;
      }
    }
    // Waits for the asnwer with time out
  }
  while ((answer == 0) && ((millis() - previous) < 2000));
  frame[counter - 3] = '\0';

times out and counter is 0. You are then accessing frame[-3] which is some random place in memory.

Later in your code

  GNSSrunstatus = atoi(strtok_single(NULL, ","));;// Gets GNSSrunstatus

what happens when strok_single() returns NULL? You still try to convert it.
And this continues does the list of variables.

You need to make your handling more robust in case you don't get a good, complete message

Thanks for your kind response :slight_smile:
I'm sorry i'm not really good in programming so please let me know if i'm in the right direction

blh64:
times out and counter is 0. You are then accessing frame[-3] which is some random place in memory.

Here i should just check if counter > 3 ?

blh64:
what happens when strok_single() returns NULL? You still try to convert it.
And this continues does the list of variables.

there is already a check that string must be different to NULL, is this not enough?
How can i fix it?

static char *strtok_single(char *str, char const *delims)
{
    static char  *src = NULL;
    char  *p,  *ret = 0;
    if (str != NULL)
        src = str;
    if (src == NULL || *src == '\0')    // Fix 1
        return NULL;
    ret = src;                          // Fix 2
    if ((p = strpbrk(src, delims)) != NULL)
    {
        *p  = 0;
        src = ++p;
    }

Thank you very much! :slight_smile:

If you get a short message, at some point, the parsed string will be empty "" so your line marked 'Fix 1' will be true and it clearly returns NULL. You have two choices.

  1. either test the return value before using it in your main code
  2. don't return NULL. You could, instead return an empty string ("") which is not the same thing.

blh64:
2. don't return NULL. You could, instead return an empty string ("") which is not the same thing.

Ok i tried this..is enough to sobstiutue NULL with "" right? I've made like this

static char *strtok_single(char *str, char const *delims)
{
    static char  *src = NULL;
    char  *p,  *ret = 0;
    if (str != NULL)
        src = str;
    if (src == NULL || *src == '\0')    // Fix 1
        return "";
    ret = src;                          // Fix 2
    if ((p = strpbrk(src, delims)) != NULL)
    {
        *p  = 0;
        src = ++p;
    }
    else
        src += strlen(src);
    return ret;
}

Is it correct?

It still seems to have problems becouse every loop it goes again to void setup.. is it for the issue of the counter?
How can i fix that?

Thank you very much!

ilteo85:
It still seems to have problems becouse every loop it goes again to void setup.. is it for the issue of the counter?
How can i fix that?

Thank you very much!

You would test to make sure counter >= 3 before using counter-3 as the index.

It seems not to work..also now every loop it goes to void setup again :frowning: this is the code that i've used with your suggestion (i hope i did'it well)

#define mySerial Serial2

char frame[100];
byte GNSSrunstatus;;
byte Fixstatus;
char UTCdatetime[18];
char latitude[11];
char logitude[11];
char altitude[8];
char speedOTG[6];
char course[6];
byte fixmode;
char HDOP[4];
char PDOP[4];
char VDOP[4];
char satellitesinview[2];
char GNSSsatellitesused[2];
char GLONASSsatellitesused[2];
char cn0max[2];
char HPA[6];
char VPA[6];
float latGPS;
float longGPS;


void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.println("Serial begin ok");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("AT");
  mySerial.println("AT+CGNSPWR=1");
  delay(10000);
  Serial.println("back to void setup");
}

void loop() { // run over and over
  get_GPS();
  delay(10000);
}


int8_t get_GPS() {

  int8_t counter, answer;
  long previous;

  // First get the NMEA string
  // Clean the input buffer
  while ( mySerial.available() > 0) mySerial.read();
  // request Basic string
  mySerial.println("AT+CGNSINF"); //sendATcommand("AT+CGNSINF", "AT+CGNSINF\r\n\r\n", 2000);

  counter = 0;
  answer = 0;
  memset(frame, '\0', sizeof(frame));    // Initialize the string
  previous = millis();
  // this loop waits for the NMEA string
  do {

    if (mySerial.available() != 0) {
      frame[counter] = mySerial.read();
      counter++;
      // check if the desired answer is in the response of the module
      if (strstr(frame, "OK") != NULL)
      {
        answer = 1;
      }
    }
    // Waits for the asnwer with time out
  }
  while ((answer == 0) && ((millis() - previous) < 2000));
  if (counter >= 3){
  frame[counter - 3] = '\0';

  // Parses the string
  strtok_single(frame, ": ");
  GNSSrunstatus = atoi(strtok_single(NULL, ","));;// Gets GNSSrunstatus
  Fixstatus = atoi(strtok_single(NULL, ",")); // Gets Fix status
  strcpy(UTCdatetime, strtok_single(NULL, ",")); // Gets UTC date and time
  strcpy(latitude, strtok_single(NULL, ",")); // Gets latitude
  strcpy(logitude, strtok_single(NULL, ",")); // Gets longitude
  strcpy(altitude, strtok_single(NULL, ",")); // Gets MSL altitude
  strcpy(speedOTG, strtok_single(NULL, ",")); // Gets speed over ground
  strcpy(course, strtok_single(NULL, ",")); // Gets course over ground
  fixmode = atoi(strtok_single(NULL, ",")); // Gets Fix Mode
  strtok_single(NULL, ",");
  strcpy(HDOP, strtok_single(NULL, ",")); // Gets HDOP
  strcpy(PDOP, strtok_single(NULL, ",")); // Gets PDOP
  strcpy(VDOP, strtok_single(NULL, ",")); // Gets VDOP
  strtok_single(NULL, ",");
  strcpy(satellitesinview, strtok_single(NULL, ",")); // Gets GNSS Satellites in View
  strcpy(GNSSsatellitesused, strtok_single(NULL, ",")); // Gets GNSS Satellites used
  strcpy(GLONASSsatellitesused, strtok_single(NULL, ",")); // Gets GLONASS Satellites used
  strtok_single(NULL, ",");
  strcpy(cn0max, strtok_single(NULL, ",")); // Gets C/N0 max
  strcpy(HPA, strtok_single(NULL, ",")); // Gets HPA
  strcpy(VPA, strtok_single(NULL, "\r")); // Gets VPA
  

  //converto stringa in numero per poterla confrontare
  longGPS = atof (logitude); 
  latGPS = atof (latitude);
       
  Serial.println("mia float latitudine");
  Serial.println(latGPS,6);
  Serial.println("mia float latitudine");
  Serial.println(longGPS,6);
  Serial.println("UTCdatetime");
  Serial.println(UTCdatetime);
  Serial.println("latitude"); 
  Serial.println(latitude);
  Serial.println("logitude");
  Serial.println(logitude);
  return answer;
  }
}


/* strtok_fixed - fixed variation of strtok_single */
static char *strtok_single(char *str, char const *delims)
{
    static char  *src = NULL;
    char  *p,  *ret = 0;
    if (str != NULL)
        src = str;
    if (src == NULL || *src == '\0')    // Fix 1
        return "";
    ret = src;                          // Fix 2
    if ((p = strpbrk(src, delims)) != NULL)
    {
        *p  = 0;
        src = ++p;
    }
    else
        src += strlen(src);
    return ret;
}

Please let me know how can i improve yjank you very much :slight_smile:

I'm curious about the "without a library" requirement here. Why? There's nothing special about libraries, there're just C++ code.

If it is a learning exercise, great. In that case, why not look at the source code of a well-written GPS library to understand what the author did. You don't have to (and should not) just copy it. Instead understand it and learn from it. Looking at code written by somebody who knows what they're doing is a good way to learn both the language and best coding practices.

ilteo85:
Hi i'm trying to get GPS data from my SIM808, without use of librarys.

I would concur with the other comments, what is your specific reason for attempting to do this supposadly without libraries ?

Your programme already includes libraries that are part of the Arduino IDE, are you for instance attempting to write this program without the Serial library ?

Why are you truncating your frame at counter-3? What is the response coming back from the GPS? Is is something like "+CGNSINF: 1,1,20200407204053.000,45.817337......OK\n"

It really wont impact any of the conversions. You should also not try any of the parsing if you get a timeout from the GPS vs. getting a response.

This code does two things:

  1. improves your reception so you only parse if you get something
  2. changes the strtok_single() function to return an empty string without all the warnings.
  3. It also reports what get received (okay... 3 things)
#define mySerial Serial2

char frame[100];
byte GNSSrunstatus;;
byte Fixstatus;
char UTCdatetime[18];
char latitude[11];
char logitude[11];
char altitude[8];
char speedOTG[6];
char course[6];
byte fixmode;
char HDOP[4];
char PDOP[4];
char VDOP[4];
char satellitesinview[2];
char GNSSsatellitesused[2];
char GLONASSsatellitesused[2];
char cn0max[2];
char HPA[6];
char VPA[6];
float latGPS;
float longGPS;


void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.println("Serial begin ok");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("AT");
  mySerial.println("AT+CGNSPWR=1");
  delay(10000);
  Serial.println("back to void setup");
}

void loop() { // run over and over
  get_GPS();
  delay(10000);
}


int8_t get_GPS() {

  int8_t counter, answer;
  long previous;

  // First get the NMEA string
  // Clean the input buffer
  while ( mySerial.available() > 0) mySerial.read();
  // request Basic string
  mySerial.println("AT+CGNSINF"); //sendATcommand("AT+CGNSINF", "AT+CGNSINF\r\n\r\n", 2000);

  counter = 0;
  answer = 0;
  memset(frame, '\0', sizeof(frame));    // Initialize the string
  previous = millis();
  // this loop waits for the NMEA string
  do {

    if (mySerial.available() != 0) {
      frame[counter++] = mySerial.read();
      if (counter >= sizeof(frame))
      {
        counter--;   // make sure we do not overrun the buffer
      }
      previous = millis();  // reset timer
      // check if the desired answer is in the response of the module
      if (strstr(frame, "OK") != NULL)
      {
        answer = 1;
      }
    }
    // Waits for the asnwer with time out
  }
  while ((answer == 0) && ((millis() - previous) < 2000));
  // do some error checking
  if ( answer == 0 )
  {
    Serial.print( "GPS timeout" );
    return;
  }
  Serial.print( "Received: '" );
  Serial.print(frame);
  Serial.println( "'" );
  //if (counter >= 3)
  //{
  //frame[counter - 3] = '\0';

  // Parses the string
  strtok_single(frame, ": ");
  GNSSrunstatus = atoi(strtok_single(NULL, ","));;// Gets GNSSrunstatus
  Fixstatus = atoi(strtok_single(NULL, ",")); // Gets Fix status
  strcpy(UTCdatetime, strtok_single(NULL, ",")); // Gets UTC date and time
  strcpy(latitude, strtok_single(NULL, ",")); // Gets latitude
  strcpy(logitude, strtok_single(NULL, ",")); // Gets longitude
  strcpy(altitude, strtok_single(NULL, ",")); // Gets MSL altitude
  strcpy(speedOTG, strtok_single(NULL, ",")); // Gets speed over ground
  strcpy(course, strtok_single(NULL, ",")); // Gets course over ground
  fixmode = atoi(strtok_single(NULL, ",")); // Gets Fix Mode
  strtok_single(NULL, ",");
  strcpy(HDOP, strtok_single(NULL, ",")); // Gets HDOP
  strcpy(PDOP, strtok_single(NULL, ",")); // Gets PDOP
  strcpy(VDOP, strtok_single(NULL, ",")); // Gets VDOP
  strtok_single(NULL, ",");
  strcpy(satellitesinview, strtok_single(NULL, ",")); // Gets GNSS Satellites in View
  strcpy(GNSSsatellitesused, strtok_single(NULL, ",")); // Gets GNSS Satellites used
  strcpy(GLONASSsatellitesused, strtok_single(NULL, ",")); // Gets GLONASS Satellites used
  strtok_single(NULL, ",");
  strcpy(cn0max, strtok_single(NULL, ",")); // Gets C/N0 max
  strcpy(HPA, strtok_single(NULL, ",")); // Gets HPA
  strcpy(VPA, strtok_single(NULL, "\r")); // Gets VPA


  //converto stringa in numero per poterla confrontare
  longGPS = atof (logitude);
  latGPS = atof (latitude);

  Serial.println("mia float latitudine");
  Serial.println(latGPS, 6);
  Serial.println("mia float latitudine");
  Serial.println(longGPS, 6);
  Serial.println("UTCdatetime");
  Serial.println(UTCdatetime);
  Serial.println("latitude");
  Serial.println(latitude);
  Serial.println("logitude");
  Serial.println(logitude);
}


/* strtok_fixed - fixed variation of strtok_single */
static char *strtok_single(char *str, char const *delims)
{
  static char empty[] = {0};
  static char  *src = NULL;
  char  *p,  *ret = 0;
  if (str != NULL)
    src = str;
  if (src == NULL || *src == '\0')    // Fix 1
    return empty;
  ret = src;                          // Fix 2
  if ((p = strpbrk(src, delims)) != NULL)
  {
    *p  = 0;
    src = ++p;
  }
  else
    src += strlen(src);
  return ret;
}

gfvalvo:
I'm curious about the "without a library" requirement here. Why? There's nothing special about libraries, there're just C++ code.

I used to use this code with arduino and it's a part of a code that i've already implemented with use of latitude longitude for Theft Protection (for my hives).
It was more easy for me if it was possible to "repair" this code.. but it will be ok also with librarys iwill bring latitude and longitude from library and convert them to float for my sketch..

But i have problem also with librarys.. i've tryed tinygps and tinygps++ but both can't comunicate with my GPS..
and says "check wiring".. wiring is right becouse i use Serial2 for comunication so TX of GPS is connect with RX of Mega an RX of GPS with TX of MEGA but steel don't works :frowning:

I'm using SIM808 as GPS and MEGA 2560..

That's the skatch i take from TinyGPS++ examples.. i just change serial communication with GPS

#include <TinyGPS++.h>
#define ss Serial2
/*
   This sample code demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
   It requires the use of SoftwareSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
//static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
//SoftwareSerial ss(RXPin, TXPin);

void setup()
{
  Serial.begin(115200);
  ss.begin(GPSBaud);

  Serial.println(F("FullExample.ino"));
  Serial.println(F("An extensive example of many interesting TinyGPS++ features"));
  Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  Serial.println(F("by Mikal Hart"));
  Serial.println();
  Serial.println(F("Sats HDOP  Latitude   Longitude   Fix  Date       Time     Date Alt    Course Speed Card  Distance Course Card  Chars Sentences Checksum"));
  Serial.println(F("           (deg)      (deg)       Age                      Age  (m)    --- from GPS ----  ---- to London  ----  RX    RX        Fail"));
  Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------------"));
}

void loop()
{
  static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;

  printInt(gps.satellites.value(), gps.satellites.isValid(), 5);
  printFloat(gps.hdop.hdop(), gps.hdop.isValid(), 6, 1);
  printFloat(gps.location.lat(), gps.location.isValid(), 11, 6);
  printFloat(gps.location.lng(), gps.location.isValid(), 12, 6);
  printInt(gps.location.age(), gps.location.isValid(), 5);
  printDateTime(gps.date, gps.time);
  printFloat(gps.altitude.meters(), gps.altitude.isValid(), 7, 2);
  printFloat(gps.course.deg(), gps.course.isValid(), 7, 2);
  printFloat(gps.speed.kmph(), gps.speed.isValid(), 6, 2);
  printStr(gps.course.isValid() ? TinyGPSPlus::cardinal(gps.course.deg()) : "*** ", 6);

  unsigned long distanceKmToLondon =
    (unsigned long)TinyGPSPlus::distanceBetween(
      gps.location.lat(),
      gps.location.lng(),
      LONDON_LAT, 
      LONDON_LON) / 1000;
  printInt(distanceKmToLondon, gps.location.isValid(), 9);

  double courseToLondon =
    TinyGPSPlus::courseTo(
      gps.location.lat(),
      gps.location.lng(),
      LONDON_LAT, 
      LONDON_LON);

  printFloat(courseToLondon, gps.location.isValid(), 7, 2);

  const char *cardinalToLondon = TinyGPSPlus::cardinal(courseToLondon);

  printStr(gps.location.isValid() ? cardinalToLondon : "*** ", 6);

  printInt(gps.charsProcessed(), true, 6);
  printInt(gps.sentencesWithFix(), true, 10);
  printInt(gps.failedChecksum(), true, 9);
  Serial.println();
  
  smartDelay(1000);

  if (millis() > 5000 && gps.charsProcessed() < 10)
    Serial.println(F("No GPS data received: check wiring"));
}

// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

static void printFloat(float val, bool valid, int len, int prec)
{
  if (!valid)
  {
    while (len-- > 1)
      Serial.print('*');
    Serial.print(' ');
  }
  else
  {
    Serial.print(val, prec);
    int vi = abs((int)val);
    int flen = prec + (val < 0.0 ? 2 : 1); // . and -
    flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
    for (int i=flen; i<len; ++i)
      Serial.print(' ');
  }
  smartDelay(0);
}

static void printInt(unsigned long val, bool valid, int len)
{
  char sz[32] = "*****************";
  if (valid)
    sprintf(sz, "%ld", val);
  sz[len] = 0;
  for (int i=strlen(sz); i<len; ++i)
    sz[i] = ' ';
  if (len > 0) 
    sz[len-1] = ' ';
  Serial.print(sz);
  smartDelay(0);
}

static void printDateTime(TinyGPSDate &d, TinyGPSTime &t)
{
  if (!d.isValid())
  {
    Serial.print(F("********** "));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
    Serial.print(sz);
  }
  
  if (!t.isValid())
  {
    Serial.print(F("******** "));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
    Serial.print(sz);
  }

  printInt(d.age(), d.isValid(), 5);
  smartDelay(0);
}

static void printStr(const char *str, int len)
{
  int slen = strlen(str);
  for (int i=0; i<len; ++i)
    Serial.print(i<slen ? str[i] : ' ');
  smartDelay(0);
}

blh64:
This code does two things:

  1. improves your reception so you only parse if you get something
  2. changes the strtok_single() function to return an empty string without all the warnings.
  3. It also reports what get received (okay... 3 things)
[/quote]

It seems to works GREAT!!!!!!!!!!! thank you so much!!!! I've just comment "return" after Serial.print("GPS Timeout")  becouse it gives me error.. but without this return it seems to work great!!!!
I will now test it also with ESP32.. i'll let you know!

Thank you!!!!!!

ilteo85:
But i have problem also with librarys.. i've tryed tinygps and tinygps++ but both can't comunicate with my GPS..

I think I'd fix the comms problems before embarking on the project of writing an NMEA sentence parser. But, I guess some people like to do things the hard way.

gfvalvo:
I think I'd fix the comms problems before embarking on the project of writing an NMEA sentence parser. But, I guess some people like to do things the hard way.

Without that library it works grat sir so it's not comms problems..maybe i had to set something in some file of the library (in the sketch i've modify as you can see in the post before) but i didn't find any solution to that..

Anyway now seems to work everithing well..i will just let it go for a while also on my ESP32 before say it works for sure but i'm optimistic about that..

Thank's to all :slight_smile:

It works since 2 hours without problems also on ESP32 (i used to get Guru meditation error).. thank you very much..now i can go further with other parts of the project.. next step i'll get data from other boards thrugh esp-now than use always my sim808 to send them on mysql.. but i wont discuss it here now i will try to solve it and eventually open another discussion..

I will update this to [SOLVED]
thank's again :slight_smile: