diff --git a/examples/AllFunctions/AllFunctions.ino b/examples/AllFunctions/AllFunctions.ino index a731d87..4fce7d6 100644 --- a/examples/AllFunctions/AllFunctions.ino +++ b/examples/AllFunctions/AllFunctions.ino @@ -319,20 +319,20 @@ void loop() { #if TINY_GSM_TEST_GSM_LOCATION && defined TINY_GSM_MODEM_HAS_GSM_LOCATION String location = modem.getGsmLocation(); - DBG("GSM Based Location:", location); - float lat = 0; - float lon = 0; + DBG("GSM Based Location String:", location); + float lat = 0; + float lon = 0; float accuracy = 0; - int year = 0; - int month = 0; - int day = 0; - int hour = 0; - int min = 0; - int sec = 0; + int year = 0; + int month = 0; + int day = 0; + int hour = 0; + int min = 0; + int sec = 0; if (modem.getGsmLocation(&lat, &lon, &accuracy, &year, &month, &day, &hour, &min, &sec)) { - DBG("Latitude:", lat); - DBG("Longitude:", lon); + DBG("Latitude:", String(lat, 8)); + DBG("Longitude:", String(lon, 8)); DBG("Accuracy:", accuracy); DBG("Year:", year); DBG("Month:", month); @@ -348,33 +348,35 @@ void loop() { #if TINY_GSM_TEST_GPS && defined TINY_GSM_MODEM_HAS_GPS modem.enableGPS(); String gps_raw = modem.getGPSraw(); - DBG("GPS/GNSS Based Location:", gps_raw); - float lat = 0; - float lon = 0; - float speed = 0; - int alt = 0; - int vsat = 0; - int usat = 0; - int year = 0; - int month = 0; - int day = 0; - int hour = 0; - int min = 0; - int sec = 0; - if (getGPS(&lat, &lon, &speed, &alt, &vsat, &usat, &year, &month, &day, &hour, - &minute, &second)) { - DBG("Latitude:", lat); - DBG("Longitude:", lon); - DBG("Speed:", speed); - DBG("Altitude:", alt); - DBG("Visible Satellites:", vsat); - DBG("Used Satellites:", usat); - DBG("Year:", year); - DBG("Month:", month); - DBG("Day:", day); - DBG("Hour:", hour); - DBG("Minute:", min); - DBG("Second:", sec); + DBG("GPS/GNSS Based Location String:", gps_raw); + float lat2 = 0; + float lon2 = 0; + float speed2 = 0; + int alt2 = 0; + int vsat2 = 0; + int usat2 = 0; + float accuracy2 = 0; + int year2 = 0; + int month2 = 0; + int day2 = 0; + int hour2 = 0; + int min2 = 0; + int sec2 = 0; + if (modem.getGPS(&lat2, &lon, &speed2, &alt2, &vsat2, &usat2, &accuracy2, + &year2, &month2, &day2, &hour2, &min2, &sec2)) { + DBG("Latitude:", String(lat2, 8)); + DBG("Longitude:", String(lon2, 8)); + DBG("Speed:", speed2); + DBG("Altitude:", alt2); + DBG("Visible Satellites:", vsat2); + DBG("Used Satellites:", usat2); + DBG("Accuracy:", accuracy2); + DBG("Year:", year2); + DBG("Month:", month2); + DBG("Day:", day2); + DBG("Hour:", hour2); + DBG("Minute:", min2); + DBG("Second:", sec2); } else { DBG("Couldn't get GPS/GNSS location"); } diff --git a/examples/FileDownload/FileDownload.ino b/examples/FileDownload/FileDownload.ino index f20e187..ec1e5b5 100644 --- a/examples/FileDownload/FileDownload.ino +++ b/examples/FileDownload/FileDownload.ino @@ -49,7 +49,9 @@ // Chips without internal buffering (A6/A7, ESP8266, M590) // need enough space in the buffer for the entire response // else data will be lost (and the http library will fail). +#if !defined(TINY_GSM_RX_BUFFER) #define TINY_GSM_RX_BUFFER 1024 +#endif // See all AT commands, if wanted // #define DUMP_AT_COMMANDS diff --git a/examples/HttpClient/HttpClient.ino b/examples/HttpClient/HttpClient.ino index 1bff394..98d222f 100644 --- a/examples/HttpClient/HttpClient.ino +++ b/examples/HttpClient/HttpClient.ino @@ -54,7 +54,9 @@ // Chips without internal buffering (A6/A7, ESP8266, M590) // need enough space in the buffer for the entire response // else data will be lost (and the http library will fail). +#if !defined(TINY_GSM_RX_BUFFER) #define TINY_GSM_RX_BUFFER 650 +#endif // See all AT commands, if wanted // #define DUMP_AT_COMMANDS diff --git a/examples/more/Hologram_Dash/Hologram_Dash.ino b/examples/more/Hologram_Dash/Hologram_Dash.ino index ae4543a..59d3dce 100644 --- a/examples/more/Hologram_Dash/Hologram_Dash.ino +++ b/examples/more/Hologram_Dash/Hologram_Dash.ino @@ -12,7 +12,9 @@ #define TINY_GSM_MODEM_UBLOX // Increase RX buffer if needed -// #define TINY_GSM_RX_BUFFER 512 +#if !defined(TINY_GSM_RX_BUFFER) +#define TINY_GSM_RX_BUFFER 512 +#endif #include diff --git a/src/TinyGsmClientSIM7000.h b/src/TinyGsmClientSIM7000.h index af72f95..161368b 100644 --- a/src/TinyGsmClientSIM7000.h +++ b/src/TinyGsmClientSIM7000.h @@ -451,25 +451,44 @@ class TinyGsmSim7000 : public TinyGsmModem, // *secondWithSS = atof(dtSBuff); streamSkipUntil(','); // Throw away the final comma - *lat = streamGetFloat(','); // Latitude - *lon = streamGetFloat(','); // Longitude - if (alt != NULL) *alt = streamGetFloat(','); // MSL Altitude - if (speed != NULL) *speed = streamGetFloat(','); // Speed Over Ground - streamSkipUntil(','); // Course Over Ground - streamSkipUntil(','); // Fix Mode - streamSkipUntil(','); // Reserved1 - streamSkipUntil(','); // Horizontal Dilution Of Precision - if (accuracy != NULL) - *accuracy = streamGetFloat(','); // Position Dilution Of Precision - streamSkipUntil(','); // Vertical Dilution Of Precision - streamSkipUntil(','); // Reserved2 - if (vsat != NULL) *vsat = streamGetInt(','); // GNSS Satellites in View - if (usat != NULL) *usat = streamGetInt(','); // GNSS Satellites Used - streamSkipUntil(','); // GLONASS Satellites Used - streamSkipUntil(','); // Reserved3 - streamSkipUntil(','); // C/N0 max - streamSkipUntil(','); // HPA - streamSkipUntil('\n'); // VPA + *lat = streamGetFloat(','); // Latitude + *lon = streamGetFloat(','); // Longitude + if (alt != NULL) { // MSL Altitude. Unit is meters + *alt = streamGetFloat(','); + } else { + streamSkipUntil(','); + } + if (speed != NULL) { // Speed Over Ground. Unit is knots. + *speed = streamGetFloat(','); + } else { + streamSkipUntil(','); + } + streamSkipUntil(','); // Course Over Ground. Degrees. + streamSkipUntil(','); // Fix Mode + streamSkipUntil(','); // Reserved1 + streamSkipUntil(','); // Horizontal Dilution Of Precision + if (accuracy != NULL) { // Position Dilution Of Precision + *accuracy = streamGetFloat(','); + } else { + streamSkipUntil(','); + } + streamSkipUntil(','); // Vertical Dilution Of Precision + streamSkipUntil(','); // Reserved2 + if (vsat != NULL) { // GNSS Satellites in View + *vsat = streamGetInt(','); + } else { + streamSkipUntil(','); + } + if (usat != NULL) { // GNSS Satellites Used + *usat = streamGetInt(','); + } else { + streamSkipUntil(','); + } + streamSkipUntil(','); // GLONASS Satellites Used + streamSkipUntil(','); // Reserved3 + streamSkipUntil(','); // C/N0 max + streamSkipUntil(','); // HPA + streamSkipUntil('\n'); // VPA waitResponse(); diff --git a/src/TinyGsmClientSIM7600.h b/src/TinyGsmClientSIM7600.h index f011cae..5de82ff 100644 --- a/src/TinyGsmClientSIM7600.h +++ b/src/TinyGsmClientSIM7600.h @@ -433,8 +433,6 @@ class TinyGsmSim7600 : public TinyGsmModem, int* vsat = 0, int* usat = 0, float* accuracy = 0, int* year = 0, int* month = 0, int* day = 0, int* hour = 0, int* minute = 0, int* second = 0) { - // String buffer = ""; - sendAT(GF("+CGNSSINFO")); if (waitResponse(GF(GSM_NL "+CGNSSINFO:")) != 1) { return false; } @@ -479,16 +477,25 @@ class TinyGsmSim7600 : public TinyGsmModem, // *secondWithSS = atof(dtSBuff); streamSkipUntil(','); // Throw away the final comma - if (alt != NULL) - *alt = streamGetFloat(','); // MSL Altitude. Unit is meters - if (speed != NULL) - *speed = streamGetFloat(','); // Speed Over Ground. Unit is knots. - streamSkipUntil(','); // Course. Degrees. - streamSkipUntil(','); // After set, will report GPS every x seconds - if (accuracy != NULL) - *accuracy = streamGetFloat(','); // Position Dilution Of Precision - streamSkipUntil(','); // Horizontal Dilution Of Precision - streamSkipUntil(','); // Vertical Dilution Of Precision + if (alt != NULL) { // MSL Altitude. Unit is meters + *alt = streamGetFloat(','); + } else { + streamSkipUntil(','); + } + if (speed != NULL) { // Speed Over Ground. Unit is knots. + *speed = streamGetFloat(','); + } else { + streamSkipUntil(','); + } + streamSkipUntil(','); // Course Over Ground. Degrees. + streamSkipUntil(','); // After set, will report GPS every x seconds + if (accuracy != NULL) { // Position Dilution Of Precision + *accuracy = streamGetFloat(','); + } else { + streamSkipUntil(','); + } + streamSkipUntil(','); // Horizontal Dilution Of Precision + streamSkipUntil(','); // Vertical Dilution Of Precision streamSkipUntil('\n'); // TODO(?) is one more field reported?? waitResponse(); diff --git a/src/TinyGsmClientSIM808.h b/src/TinyGsmClientSIM808.h index 61e6d8b..1bd74b5 100644 --- a/src/TinyGsmClientSIM808.h +++ b/src/TinyGsmClientSIM808.h @@ -26,20 +26,14 @@ class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS { protected: // enable GPS bool enableGPSImpl() { - // uint16_t state; - sendAT(GF("+CGNSPWR=1")); if (waitResponse() != 1) { return false; } - return true; } bool disableGPSImpl() { - // uint16_t state; - sendAT(GF("+CGNSPWR=0")); if (waitResponse() != 1) { return false; } - return true; } @@ -96,25 +90,44 @@ class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS { // *secondWithSS = atof(dtSBuff); streamSkipUntil(','); // Throw away the final comma - *lat = streamGetFloat(','); // Latitude - *lon = streamGetFloat(','); // Longitude - if (alt != NULL) *alt = streamGetFloat(','); // MSL Altitude - if (speed != NULL) *speed = streamGetFloat(','); // Speed Over Ground - streamSkipUntil(','); // Course Over Ground - streamSkipUntil(','); // Fix Mode - streamSkipUntil(','); // Reserved1 - streamSkipUntil(','); // Horizontal Dilution Of Precision - if (accuracy != NULL) - *accuracy = streamGetFloat(','); // Position Dilution Of Precision + *lat = streamGetFloat(','); // Latitude + *lon = streamGetFloat(','); // Longitude + if (alt != NULL) { // MSL Altitude. Unit is meters + *alt = streamGetFloat(','); + } else { + streamSkipUntil(','); + } + if (speed != NULL) { // Speed Over Ground. Unit is knots. + *speed = streamGetFloat(','); + } else { + streamSkipUntil(','); + } + streamSkipUntil(','); // Course Over Ground. Degrees. + streamSkipUntil(','); // Fix Mode + streamSkipUntil(','); // Reserved1 + streamSkipUntil(','); // Horizontal Dilution Of Precision + if (accuracy != NULL) { // Position Dilution Of Precision + *accuracy = streamGetFloat(','); + } else { + streamSkipUntil(','); + } streamSkipUntil(','); // Vertical Dilution Of Precision streamSkipUntil(','); // Reserved2 - if (vsat != NULL) *vsat = streamGetInt(','); // GNSS Satellites in View - if (usat != NULL) *usat = streamGetInt(','); // GNSS Satellites Used - streamSkipUntil(','); // GLONASS Satellites Used - streamSkipUntil(','); // Reserved3 - streamSkipUntil(','); // C/N0 max - streamSkipUntil(','); // HPA - streamSkipUntil('\n'); // VPA + if (vsat != NULL) { // GNSS Satellites in View + *vsat = streamGetInt(','); + } else { + streamSkipUntil(','); + } + if (usat != NULL) { // GNSS Satellites Used + *usat = streamGetInt(','); + } else { + streamSkipUntil(','); + } + streamSkipUntil(','); // GLONASS Satellites Used + streamSkipUntil(','); // Reserved3 + streamSkipUntil(','); // C/N0 max + streamSkipUntil(','); // HPA + streamSkipUntil('\n'); // VPA waitResponse(); diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index 0d84f8f..ae86c90 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -538,21 +538,33 @@ class TinyGsmSaraR4 *lat = streamGetFloat(','); // Estimated latitude, in degrees *lon = streamGetFloat(','); // Estimated longitude, in degrees - if (alt != NULL) - *alt = streamGetFloat(','); // Estimated altitude, in meters - only for - // GNSS positioning, 0 in case of CellLocate - if (accuracy != NULL) { + + if (alt != NULL) { // Estimated altitude, in meters - only for GNSS + // positioning, 0 in case of CellLocate + *alt = streamGetFloat(','); + } else { + streamSkipUntil(','); + } + if (accuracy != NULL) { // Maximum possible error, in meters (0 - 20000000) *accuracy = streamGetFloat(','); - } // Maximum possible error, in meters (0 - 20000000) - if (speed != NULL) *speed = streamGetFloat(','); // Speed over ground m/s3 + } else { + streamSkipUntil(','); + } + if (speed != NULL) { // Speed over ground m/s3 + *speed = streamGetFloat(','); + } else { + streamSkipUntil(','); + } streamSkipUntil(','); // Course over ground in degree (0 deg - 360 deg) streamSkipUntil(','); // Vertical accuracy, in meters streamSkipUntil(','); // Sensor used for the position calculation - streamSkipUntil(','); // Number of satellite used to calculate the position - if (usat != NULL) - *usat = streamGetInt( - ','); // Number of satellite used to calculate the position - streamSkipUntil(','); // Antenna status + if (vsat != NULL) vsat = 0; // Number of satellites viewed not reported + if (usat != NULL) { // Number of satellite used to calculate the position + *usat = streamGetInt(','); + } else { + streamSkipUntil(','); + } + streamSkipUntil(','); // Antenna status streamSkipUntil('\n'); // Jamming status // final ok diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index a5c2b21..203d554 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -505,21 +505,33 @@ class TinyGsmUBLOX *lat = streamGetFloat(','); // Estimated latitude, in degrees *lon = streamGetFloat(','); // Estimated longitude, in degrees - if (alt != NULL) - *alt = streamGetFloat(','); // Estimated altitude, in meters - only for - // GNSS positioning, 0 in case of CellLocate - if (accuracy != NULL) { + + if (alt != NULL) { // Estimated altitude, in meters - only for GNSS + // positioning, 0 in case of CellLocate + *alt = streamGetFloat(','); + } else { + streamSkipUntil(','); + } + if (accuracy != NULL) { // Maximum possible error, in meters (0 - 20000000) *accuracy = streamGetFloat(','); - } // Maximum possible error, in meters (0 - 20000000) - if (speed != NULL) *speed = streamGetFloat(','); // Speed over ground m/s3 + } else { + streamSkipUntil(','); + } + if (speed != NULL) { // Speed over ground m/s3 + *speed = streamGetFloat(','); + } else { + streamSkipUntil(','); + } streamSkipUntil(','); // Course over ground in degree (0 deg - 360 deg) streamSkipUntil(','); // Vertical accuracy, in meters streamSkipUntil(','); // Sensor used for the position calculation - streamSkipUntil(','); // Number of satellite used to calculate the position - if (usat != NULL) - *usat = streamGetInt( - ','); // Number of satellite used to calculate the position - streamSkipUntil(','); // Antenna status + if (vsat != NULL) *vsat = 0; // Number of satellites viewed not reported + if (usat != NULL) { // Number of satellite used to calculate the position + *usat = streamGetInt(','); + } else { + streamSkipUntil(','); + } + streamSkipUntil(','); // Antenna status streamSkipUntil('\n'); // Jamming status // final ok diff --git a/src/TinyGsmGSMLocation.tpp b/src/TinyGsmGSMLocation.tpp index 1bcfb01..3518712 100644 --- a/src/TinyGsmGSMLocation.tpp +++ b/src/TinyGsmGSMLocation.tpp @@ -95,8 +95,11 @@ class TinyGsmGSMLocation { } *lat = thisModem().streamGetFloat(','); // Latitude *lon = thisModem().streamGetFloat(','); // Longitude - if (accuracy != NULL) - *accuracy = thisModem().streamGetInt(','); // Positioning accuracy + if (accuracy != NULL) { // Positioning accuracy + *accuracy = thisModem().streamGetInt(','); + } else { + thisModem().streamSkipUntil(','); + } // Date & Time char dtSBuff[5] = {'\0'};