diff --git a/Sim800L.cpp b/Sim800L.cpp index 2d94b4f..a5775cf 100644 --- a/Sim800L.cpp +++ b/Sim800L.cpp @@ -251,53 +251,54 @@ String Sim800L::getOperator() } -bool Sim800L::calculateLocation() -{ - /* - Type: 1 To get longitude and latitude - Cid = 1 Bearer profile identifier refer to AT+SAPBR - */ - - uint8_t type = 1; - uint8_t cid = 1; - - - this->print("AT+CIPGSMLOC="); - this->print(type); - this->print(","); - this->print(cid); - this->print("\r"); - - - String data = _readSerial(20000); - - if (data.indexOf("ER")!=(-1)) return false; - - uint8_t indexOne; - uint8_t indexTwo; - - indexOne = data.indexOf(":") + 1; - indexTwo = data.indexOf(","); - - _locationCode = data.substring(indexOne , indexTwo); - - indexOne = data.indexOf(",") + 1; - indexTwo = data.indexOf("," , indexOne); - - _longitude = data.substring(indexOne , indexTwo); - - indexOne = data.indexOf(",", indexTwo) + 1; - indexTwo = data.indexOf("," , indexOne); - - _latitude = data.substring(indexOne , indexTwo); - - return true; - -} - -String Sim800L::getLocationCode() { - return _locationCode; - /* +bool Sim800L::calculateLocation() +{ + /* + Type: 1 To get longitude and latitude + Cid = 1 Bearer profile identifier refer to AT+SAPBR + */ + + uint8_t type = 1; + uint8_t cid = 1; + + + this->print("AT+CIPGSMLOC="); + this->print(type); + this->print(","); + this->print(cid); + this->print("\r"); + + + String data = _readSerial(20000); + + if (data.indexOf("ER")!=(-1)) return false; + + uint8_t indexOne; + uint8_t indexTwo; + + indexOne = data.indexOf(":") + 1; + indexTwo = data.indexOf(","); + + _locationCode = data.substring(indexOne, indexTwo); + + indexOne = data.indexOf(",") + 1; + indexTwo = data.indexOf(",", indexOne); + + _longitude = data.substring(indexOne, indexTwo); + + indexOne = data.indexOf(",", indexTwo) + 1; + indexTwo = data.indexOf(",", indexOne); + + _latitude = data.substring(indexOne, indexTwo); + + return true; + +} + +String Sim800L::getLocationCode() +{ + return _locationCode; + /* Location Code: 0 Success 404 Not Found @@ -307,15 +308,17 @@ String Sim800L::getLocationCode() { 603 DNS Error 604 Stack Busy 65535 Other Error - */ + */ } -String Sim800L::getLongitude() { - return _longitude; +String Sim800L::getLongitude() +{ + return _longitude; } -String Sim800L::getLatitude() { - return _latitude; +String Sim800L::getLatitude() +{ + return _latitude; } diff --git a/Sim800L.h b/Sim800L.h index 9eaf536..214fda0 100644 --- a/Sim800L.h +++ b/Sim800L.h @@ -84,9 +84,9 @@ class Sim800L : public SoftwareSerial String _buffer; bool _sleepMode; uint8_t _functionalityMode; - String _locationCode; - String _longitude; - String _latitude; + String _locationCode; + String _longitude; + String _latitude; String _readSerial(); String _readSerial(uint32_t timeout); @@ -119,11 +119,11 @@ class Sim800L : public SoftwareSerial String getOperatorsList(); String getOperator(); - - bool calculateLocation(); - String getLocationCode(); - String getLongitude(); - String getLatitude(); + + bool calculateLocation(); + String getLocationCode(); + String getLongitude(); + String getLatitude(); bool answerCall(); void callNumber(char* number);