From e180ec881a203bd17b694f979259e9f2c70fe4a2 Mon Sep 17 00:00:00 2001 From: Chuck Allen Date: Sun, 12 Aug 2018 09:17:34 -0700 Subject: [PATCH 1/2] Added calls to cell engineering data and suppression of unsolicited SMS messages --- Adafruit_FONA.cpp | 92 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/Adafruit_FONA.cpp b/Adafruit_FONA.cpp index 9a78181..f2b45e8 100644 --- a/Adafruit_FONA.cpp +++ b/Adafruit_FONA.cpp @@ -141,6 +141,98 @@ boolean Adafruit_FONA::begin(Stream &port) { return true; } +/* ~~~~~~~~~~~~~~~~~~~~~ ADDED CELL ANTENNA LOCATION SUPPORT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +if you want the module to keep you updated with the lac and cid, +you can get that with at+creg=2 or at+cgreg=2 (they appear to do the same thing), +and the module will report whenever you are shoved to another tower. + +also, set at+cnetscan=1 and then at+cnetscan will show you all towers +the fona can see at present along with signal strength. +// ~~~~~~~~~~~~~~~~~~~~~ ADDED CELL ANTENNA LOCATION SUPPORT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + +boolean Adafruit_FONA::getCELLLoc(uint16_t *errorcode, char *buff, uint16_t maxlen) { + // Set mode = 2 (Because nothing else seems to work) + getReply(F("AT+CENG=2"), (uint16_t)20000); + readline(); // eat OK + + // CENG: does a Read and should give us what we need - and it does + char *p = replybuffer+6; // Skip the first 6 characters + while((int)strlen(p) < 10) // This is my attempt to make sure we get data rather than a status message + { + getReply(F("AT+CENG:"), (uint16_t)20000); + + if (! parseReply(F("+CENG: "), errorcode)) + return false; + } + + // Copy the response into user's buffer + uint16_t lentocopy = min(maxlen-1, (int)strlen(p)); + strncpy(buff, p, lentocopy+1); + + // Set mode = 0 (turns off engineering mode) + endCELLLoc(0); + + return true; +} +/* +// Will report more or less the same as CENG, but a bit more detail +boolean Adafruit_FONA::getCELLLoc(uint16_t *errorcode, char *buff, uint16_t maxlen) { + // Set mode = 2 (Becuase nothing else seems to work) + getReply(F("AT+CNETSCAN=1"), (uint16_t)20000); + readline(); // eat OK + getReply(F("AT+CNETSCAN"), (uint16_t)20000); + // CENG: does a Read and should give us what we need - and it does, on occasion + char *p = replybuffer+6; // Skip the first 6 characters + while((int)strlen(p) < 10) // This is my attempt to make sure we get data rather than a status message + { + getReply(F("AT+CNETSCAN:"), (uint16_t)20000); + + if (! parseReply(F("+CNETSCAN: "), errorcode)) + return false; + } + + // Copy the response into user's buffer + uint16_t lentocopy = min(maxlen-1, (int)strlen(p)); + strncpy(buff, p, lentocopy+1); + + // Set mode = 0 (turns off engineering mode) + endCELLLoc(0); + + return true; +} +*/ +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// Provide a call to turn it off as well +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +boolean Adafruit_FONA::endCELLLoc(uint16_t *errorcode) { + + getReply(F("AT+CENG=0"), (uint16_t)20000); + readline(); // eat OK + + if (! parseReply(F("+CENG: "), errorcode)) + return false; + + return true; +} + +// ~~~~~~~~~~~~~~~~~~~~~ ADDED CELL ANTENNA LOCATION SUPPORT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// ~~~~~~~~~~~~~~~~~~~~~ ADDED CELL ANTENNA LOCATION SUPPORT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +// ~~~~~~~~~~~~~~~~~~~~~ ADDED URC SUPPRESSION SUPPORT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// ~~~~~~~~~~~~~~~~~~~~~ ADDED URC SUPPRESSION SUPPORT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// Disable URC (Unsolicited Response Codes) from FONA +// They screw up transactional sequences by being "Unsolicited" +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +boolean Adafruit_FONA::setURCMode(boolean stat) { + if(! stat) getReply(F("AT+CNMI=0"), (uint16_t)20000); + if( stat) getReply(F("AT+CNMI=3"), (uint16_t)20000); + readline(); // eat OK + return true; +} +// ~~~~~~~~~~~~~~~~~~~~~ ADDED URC SUPPRESSION SUPPORT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// ~~~~~~~~~~~~~~~~~~~~~ ADDED URC SUPPRESSION SUPPORT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + /********* Serial port ********************************************/ From d6e71ba1b00f2c835f040fae99250dcc508ea972 Mon Sep 17 00:00:00 2001 From: Chuck Allen Date: Sun, 12 Aug 2018 09:20:33 -0700 Subject: [PATCH 2/2] Added template calls to cell engineering data and suppression of unsolicited SMS messages --- Adafruit_FONA.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Adafruit_FONA.h b/Adafruit_FONA.h index 78f5050..5c94395 100644 --- a/Adafruit_FONA.h +++ b/Adafruit_FONA.h @@ -138,6 +138,14 @@ class Adafruit_FONA : public FONAStreamType { boolean getGSMLoc(float *lat, float *lon); void setGPRSNetworkSettings(FONAFlashStringPtr apn, FONAFlashStringPtr username=0, FONAFlashStringPtr password=0); + // ~~~~~~~~~~~~~~~~~~~~~ ADDED CELL ANTENNA LOCATION SUPPORT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + boolean getCELLLoc(uint16_t *errorcode, char *buff, uint16_t maxlen); + boolean endCELLLoc(uint16_t *errorcode); + // ~~~~~~~~~~~~~~~~~~~~~ ADDED CELL ANTENNA LOCATION SUPPORT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // ~~~~~~~~~~~~~~~~~~~~~ ADDED URC SUPPRESSION SUPPORT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + boolean setURCMode(boolean stat); + // ~~~~~~~~~~~~~~~~~~~~~ ADDED URC SUPPRESSION SUPPORT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // GPS handling boolean enableGPS(boolean onoff); int8_t GPSstatus(void);