diff --git a/examples/AllFunctions/AllFunctions.ino b/examples/AllFunctions/AllFunctions.ino index 1120e53..a731d87 100644 --- a/examples/AllFunctions/AllFunctions.ino +++ b/examples/AllFunctions/AllFunctions.ino @@ -401,9 +401,9 @@ void loop() { #endif #if TINY_GSM_TEST_BATTERY && defined TINY_GSM_MODEM_HAS_BATTERY - uint8_t chargeState = -99; - int8_t percent = -99; - uint16_t milliVolts = -9999; + uint8_t chargeState = -99; + int8_t percent = -99; + uint16_t milliVolts = -9999; modem.getBattStats(chargeState, percent, milliVolts); DBG("Battery charge state:", chargeState); DBG("Battery charge 'percent':", percent); diff --git a/src/TinyGsmClientSIM5360.h b/src/TinyGsmClientSIM5360.h index c28a83e..7f3d132 100644 --- a/src/TinyGsmClientSIM5360.h +++ b/src/TinyGsmClientSIM5360.h @@ -405,7 +405,7 @@ class TinyGsmSim5360 : public TinyGsmModem, // Follows all messaging functions per template /* - * Location functions + * GSM Location functions */ protected: // SIM5360 and SIM7100 can return a GSM-based location from CLBS as per the diff --git a/src/TinyGsmClientSIM7000.h b/src/TinyGsmClientSIM7000.h index 61d2d8e..af72f95 100644 --- a/src/TinyGsmClientSIM7000.h +++ b/src/TinyGsmClientSIM7000.h @@ -384,7 +384,7 @@ class TinyGsmSim7000 : public TinyGsmModem, // Follows all messaging functions per template /* - * GPS location functions + * GPS/GNSS/GLONASS location functions */ protected: // enable GPS @@ -412,9 +412,9 @@ class TinyGsmSim7000 : public TinyGsmModem, // get GPS informations bool getGPSImpl(float* lat, float* lon, 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* minute = 0, - int* second = 0) { + 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) { bool fix = false; sendAT(GF("+CGNSINF")); @@ -459,9 +459,10 @@ class TinyGsmSim7000 : public TinyGsmModem, streamSkipUntil(','); // Fix Mode streamSkipUntil(','); // Reserved1 streamSkipUntil(','); // Horizontal Dilution Of Precision - streamSkipUntil(','); // Position Dilution Of Precision - streamSkipUntil(','); // Vertical Dilution Of Precision - streamSkipUntil(','); // Reserved2 + 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 diff --git a/src/TinyGsmClientSIM7600.h b/src/TinyGsmClientSIM7600.h index 78bebbd..f011cae 100644 --- a/src/TinyGsmClientSIM7600.h +++ b/src/TinyGsmClientSIM7600.h @@ -396,13 +396,13 @@ class TinyGsmSim7600 : public TinyGsmModem, // Follows all messaging functions per template /* - * Location functions + * GSM Location functions */ protected: // Can return a GSM-based location from CLBS as per the template /* - * GPS location functions + * GPS/GNSS/GLONASS location functions */ protected: // enable GPS @@ -430,9 +430,9 @@ class TinyGsmSim7600 : public TinyGsmModem, // get GPS informations bool getGPSImpl(float* lat, float* lon, 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* minute = 0, - int* second = 0) { + 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")); @@ -450,7 +450,7 @@ class TinyGsmSim7600 : public TinyGsmModem, streamSkipUntil(','); // E/W Indicator, E=east or W=west // Date. Output format is ddmmyy - char dtSBuff[5] = {'\0'}; + char dtSBuff[7] = {'\0'}; stream.readBytes(dtSBuff, 2); // Two digit day dtSBuff[2] = '\0'; // null terminate buffer if (day != NULL) *day = atoi(dtSBuff); // Convert to int @@ -484,10 +484,11 @@ class TinyGsmSim7600 : public TinyGsmModem, if (speed != NULL) *speed = streamGetFloat(','); // Speed Over Ground. Unit is knots. streamSkipUntil(','); // Course. Degrees. - streamSkipUntil(','); // After set, will report GPS every x seconds - streamSkipUntil(','); // Position Dilution Of Precision - streamSkipUntil(','); // Horizontal Dilution Of Precision - streamSkipUntil(','); // Vertical Dilution Of Precision + 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 streamSkipUntil('\n'); // TODO(?) is one more field reported?? waitResponse(); diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index f0abd1e..9b9c81f 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -404,7 +404,7 @@ class TinyGsmSim800 // Follows all messaging functions per template /* - * Location functions + * GSM Location functions */ protected: // Depending on the exacty model and firmware revision, should return a @@ -412,7 +412,7 @@ class TinyGsmSim800 // TODO(?): Check number of digits in year (2 or 4) /* - * GPS location functions + * GPS/GNSS/GLONASS location functions */ protected: // No functions of this type supported diff --git a/src/TinyGsmClientSIM808.h b/src/TinyGsmClientSIM808.h index 8017fc0..61e6d8b 100644 --- a/src/TinyGsmClientSIM808.h +++ b/src/TinyGsmClientSIM808.h @@ -21,7 +21,7 @@ class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS { /* - * GPS location functions + * GPS/GNSS/GLONASS location functions */ protected: // enable GPS @@ -57,9 +57,9 @@ class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS { // get GPS informations // works only with ans SIM808 V2 bool getGPSImpl(float* lat, float* lon, 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* minute = 0, - int* second = 0) { + 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) { bool fix = false; sendAT(GF("+CGNSINF")); @@ -104,7 +104,8 @@ class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS { streamSkipUntil(','); // Fix Mode streamSkipUntil(','); // Reserved1 streamSkipUntil(','); // Horizontal Dilution Of Precision - streamSkipUntil(','); // Position 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 diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index 65dab14..0d84f8f 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -16,6 +16,7 @@ #include "TinyGsmBattery.tpp" #include "TinyGsmGPRS.tpp" +#include "TinyGsmGPS.tpp" #include "TinyGsmGSMLocation.tpp" #include "TinyGsmModem.tpp" #include "TinyGsmSMS.tpp" @@ -46,6 +47,7 @@ class TinyGsmSaraR4 public TinyGsmSSL, public TinyGsmBattery, public TinyGsmGSMLocation, + public TinyGsmGPS, public TinyGsmSMS, public TinyGsmTemperature, public TinyGsmTime { @@ -56,6 +58,7 @@ class TinyGsmSaraR4 friend class TinyGsmSSL; friend class TinyGsmBattery; friend class TinyGsmGSMLocation; + friend class TinyGsmGPS; friend class TinyGsmSMS; friend class TinyGsmTemperature; friend class TinyGsmTime; @@ -422,17 +425,40 @@ class TinyGsmSaraR4 size_t len) TINY_GSM_ATTR_NOT_IMPLEMENTED; /* - * Location functions + * GSM/GPS/GNSS/GLONASS Location functions + * NOTE: u-blox modules use the same function to get location data from both + * GSM tower triangulation and from dedicated GPS/GNSS/GLONASS receivers. The + * only difference in which sensor the data is requested from. */ protected: - String getGsmLocationRawImpl() { + bool enableGPSImpl() { + // AT+UGPS=[,[,]] + // - 0: GNSS receiver powered off, 1: on + // - 0: no aiding (default) + // - 3: GPS + SBAS (default) + sendAT(GF("+UGPS=1,0,3")); + if (waitResponse(10000L, GF(GSM_NL "+UGPS:")) != 1) { return false; } + return waitResponse(10000L) == 1; + } + bool disableGPSImpl() { + sendAT(GF("+UGPS=0")); + if (waitResponse(10000L, GF(GSM_NL "+UGPS:")) != 1) { return false; } + return waitResponse(10000L) == 1; + } + String getUbloxLocationRaw(int8_t sensor) { // AT+ULOC=,,,, // - 2: single shot position - // - 2: use cellular CellLocate® location information + // - 0: use the last fix in the internal database and stop the GNSS + // receiver + // - 1: use the GNSS receiver for localization + // - 2: use cellular CellLocate® location information + // - 3: ?? use the combined GNSS receiver and CellLocate® service + // information ?? - Docs show using sensor 3 and it's + // documented for the +UTIME command but not for +ULOC // - 0: standard (single-hypothesis) response // - Timeout period in seconds // - Target accuracy in meters (1 - 999999) - sendAT(GF("+ULOC=2,2,0,120,1")); + sendAT(GF("+ULOC=2,"), sensor, GF(",0,120,1")); // wait for first "OK" if (waitResponse(10000L) != 1) { return ""; } // wait for the final result - wait full timeout time @@ -442,21 +468,35 @@ class TinyGsmSaraR4 res.trim(); return res; } + String getGsmLocationRawImpl() { + return getUbloxLocationRaw(2); + } + String getGPSrawImpl() { + return getUbloxLocationRaw(1); + } - bool getGsmLocationImpl(float* lat, float* lon, float* accuracy = 0, - int* year = 0, int* month = 0, int* day = 0, - int* hour = 0, int* minute = 0, int* second = 0) { + bool getUbloxLocation(int8_t sensor, float* lat, float* lon, float* speed = 0, + int* alt = 0, 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) { // AT+ULOC=,,,, // - 2: single shot position // - 2: use cellular CellLocate® location information + // - 0: use the last fix in the internal database and stop the GNSS + // receiver + // - 1: use the GNSS receiver for localization + // - 3: ?? use the combined GNSS receiver and CellLocate® service + // information ?? - Docs show using sensor 3 and it's documented + // for the +UTIME command but not for +ULOC // - 0: standard (single-hypothesis) response // - Timeout period in seconds // - Target accuracy in meters (1 - 999999) - sendAT(GF("+ULOC=2,2,0,120,1")); + sendAT(GF("+ULOC=2,"), sensor, GF(",0,120,1")); // wait for first "OK" if (waitResponse(10000L) != 1) { return false; } // wait for the final result - wait full timeout time - if (waitResponse(120000L, GF(GSM_NL "+UULOC:")) != 1) { return false; } + if (waitResponse(120000L, GF(GSM_NL "+UULOC: ")) != 1) { return false; } // +UULOC: ,