Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: aconno_I2C Lis2dh12 WatchdogTimer
Diff: modem.cpp
- Revision:
- 30:7e90ddd7ed12
- Parent:
- 27:fa76f5a08195
- Child:
- 31:c84fc6d8eaa3
--- a/modem.cpp Sun Dec 23 23:50:39 2018 +0000
+++ b/modem.cpp Mon Dec 24 02:01:38 2018 +0000
@@ -139,6 +139,12 @@
{
//CHECK WE ARE NOT ALREADY ON NETOWRK
if (!GLOBAL_registeredOnNetwork) {
+
+ ATsendCMD("AT+QCFG=\"nwscanseq\",1"); //2G priority
+ //ATsendCMD("AT+QCFG=\"nwscanseq\",2"); //3G priority
+ //ATsendCMD("AT+QCFG=\"nwscanseq\",0"); //AUTO
+ ATwaitForWord("OK",ATTIMEOUT_SHORT);
+
int attempt = 0;
Timer t;
t.start();
@@ -267,9 +273,12 @@
flushSerial();
bool haveGPSFix = false;
bool haveCellFix = false;
-
char locDataOut[100];
-
+ Timer t;
+ t.start();
+ uint32_t startmillis;
+ uint32_t runtime;
+
if (accuracy >= 2) {
//Enable External LNA power - IS DISABLED BY DEFAULT
ATsendCMD("AT+QGPSCFG=\"lnacontrol\",1");
@@ -279,13 +288,11 @@
ATsendCMD("AT+QGPS=1");
ATwaitForWord("OK",ATTIMEOUT_SHORT);
- Timer t;
- t.start();
//TRY UNTIL TIMEOUT
uint8_t GPS_fixstage = 0;
uint8_t GPS_fixcount = 0;
- uint32_t startmillis = t.read_ms();
- uint32_t runtime = 0;
+ startmillis = t.read_ms();
+ runtime = 0;
while(!haveGPSFix && runtime < (timeout_seconds*1000)) {
watchdogKick();
Thread::wait(5000); //this goes first
@@ -333,12 +340,7 @@
//SHALL WE GET CELL LOCATION
if (!haveGPSFix && accuracy >= 1) {
- //PRIORITISE 2G connection (reason being uses less power in some instances and can get cell tower tirangulation)
- //ATsendCMD("AT+QCFG=\"nwscanseq\",0"); // 0 - auto, 1 - 2g priority, 2 - 3g priority
- //ATwaitForWord("OK",ATTIMEOUT_SHORT);
- //ATsendCMD("AT+QCFG=\"nwscanmode\",1"); // 0 - auto, 1 - 2g, 2 - 3g
- //ATwaitForWord("OK",ATTIMEOUT_SHORT);
-
+
_w_disable = 1; //turn off airplane mode
registerOnNetwork(2, 90000);
@@ -349,14 +351,19 @@
int mcc;
int mnc;
- ATsendCMD("AT+QENG=\"servingcell\"");
- ATwaitForWord("+QENG: \"servingcell\"",ATTIMEOUT_SHORT);
-
- if ((matchCount = _uart.scanf(",\"NOCONN\",\"%[^\"]\",%d,%d,%[^,],%[^,]",&type,&mcc,&mnc,&lac,&cellID)) == 5 ) {
- //sprintf(locDataOut,",h:%d.%d.%s.%s\0",mcc,mnc,lac,cellID);
- sprintf(locDataOut,",h:41806.2252.234.30\0");
- haveCellFix = true;
- //DEBUG("\ncellOut:%s\n",locDataOut);
+ startmillis = t.read_ms();
+ runtime = 0;
+ while(!haveCellFix && runtime < 15000) {
+ runtime = (t.read_ms() - startmillis);
+ ATsendCMD("AT+QENG=\"servingcell\"");
+ if (ATwaitForWord("+QENG: \"servingcell\",\"NOCONN\",",ATTIMEOUT_SHORT)) {
+ if ((matchCount = _uart.scanf("\"%[^\"]\",%d,%d,%[^,],%[^,]",&type,&mcc,&mnc,&lac,&cellID)) == 5 ) {
+ //sprintf(locDataOut,",h:%d.%d.%s.%s\0",mcc,mnc,lac,cellID);
+ sprintf(locDataOut,",h:41806.2252.234.30\0");
+ haveCellFix = true;
+ //DEBUG("\ncellOut:%s\n",locDataOut);
+ }
+ }
}
//example from mulbs