I used to do it with Arduino with thise code
Code: Select all
int8_t get_GPS() {
int8_t counter, answer;
long previous;
// First get the NMEA string
// Clean the input buffer
while ( Serial2.available() > 0) Serial2.read();
// request Basic string
Serial2.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 (Serial2.available() != 0) {
frame[counter] = Serial2.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 longitudine");
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;
}
but with ESP32 it works just sometimes and sometimes give me "Guru Meditation Error: Core 1 panic'ed (LoadProhibited)"
I think is becouse of my code..
Please help me to fix it im getting creazy..i've tryed also a lot of library ('TinyGPS, TinyGPS++ ecc) but i didn't get to make them work..
and i prefere to fix this code couse i've already set all my variables in the rest of the code..
(but it's ok also with library if some one has ever used it and know how to do)
Thank you very much and sorry for my english..i'm from Italy