init

Dependencies:   aconno_I2C Lis2dh12 WatchdogTimer

Files at this revision

API Documentation at this revision

Comitter:
pathfindr
Date:
Tue Jan 01 20:46:39 2019 +0000
Parent:
31:c84fc6d8eaa3
Child:
33:760005331b4c
Commit message:
11

Changed in this revision

README.md Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
modem.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/README.md	Tue Jan 01 15:44:24 2019 +0000
+++ b/README.md	Tue Jan 01 20:46:39 2019 +0000
@@ -21,7 +21,7 @@
 19) check voltage calibation
 21) when setup fails it does not go into dormant mode, could be ram retention
 22) force CL locations to 6 decimal - needs to be done on web api
-
+23) 3g cell tower data is not being recognised and converted to location by server
 
 
 RESOLVED - TO BE TESTED AGAIN...
@@ -38,5 +38,6 @@
 
 
 
-
- 
+DA98C4 - ID 43
+RUN 1.   GPS with 10 seconds fix hold, 3G priority, receipts everytime, 1m interval.
+Starting battery 3.22
--- a/main.cpp	Tue Jan 01 15:44:24 2019 +0000
+++ b/main.cpp	Tue Jan 01 20:46:39 2019 +0000
@@ -54,6 +54,7 @@
 static long long        RET_imei                                        __attribute__((section("noinit"),zero_init));
 //SETTINGS
 static int              RET_setting_firmware                            __attribute__((section("noinit"),zero_init)); //must be int to support negative value
+static uint32_t         RET_setting_minimumupdate_hrs                   __attribute__((section("noinit"),zero_init));
 static uint8_t          RET_setting_location_mode                       __attribute__((section("noinit"),zero_init));
 static uint8_t          RET_setting_location_accuracy                   __attribute__((section("noinit"),zero_init));
 static uint32_t         RET_setting_location_tx_interval_mins           __attribute__((section("noinit"),zero_init));
@@ -81,6 +82,7 @@
 static time_t           RET_buttonHoldTime                              __attribute__((section("noinit"),zero_init));
 static time_t           RET_RTCunixtime                                 __attribute__((section("noinit"),zero_init));
 static time_t           RET_SetupRunAt                                  __attribute__((section("noinit"),zero_init));
+static time_t           RET_SettingsGotAt                               __attribute__((section("noinit"),zero_init));
 //MOTION STATE
 static bool             RET_motionTriggered                             __attribute__((section("noinit"),zero_init));
 static bool             RET_motionTriggeredInTXInterval                 __attribute__((section("noinit"),zero_init));
@@ -174,6 +176,7 @@
     DEBUG("RET_RTCunixtime:%u \n",RET_RTCunixtime);
     DEBUG("RET_RTCunixtime_bu:%u \n",RET_RTCunixtime_bu);
     DEBUG("RET_setting_firmware:%d \n",RET_setting_firmware);
+    DEBUG("RET_setting_minimumupdate_hrs:%d \n",RET_setting_minimumupdate_hrs);
     DEBUG("RET_state:%d \n",RET_state);
     DEBUG("RET_setting_location_mode:%d \n",RET_setting_location_mode);
     DEBUG("RET_setting_location_accuracy:%d \n",RET_setting_location_accuracy);
@@ -285,8 +288,10 @@
     RET_RTCunixtime = 0;
     RET_RTCunixtime_bu = 0;
     RET_SetupRunAt = 0;
+    RET_SettingsGotAt = 0;
     //SETTINGS
     RET_setting_firmware = 0;
+    RET_setting_minimumupdate_hrs = 0;
     RET_setting_location_mode = DEFAULT_LOCATION_MODE;
     RET_setting_location_accuracy = DEFAULT_LOCATION_ACCURACY;
     RET_setting_location_tx_interval_mins = DEFAULT_LOCATION_TX_INTERVAL_MINS;
@@ -429,15 +434,17 @@
 bool saveSettings(char* settingsBuffer) {
     int matchCount = 0;
     int critical_fail_count = 0;
-    time_t TEMP_b = 0; int TEMP_c = -1; int TEMP_d = -1; int TEMP_e = -1; int TEMP_f = -1; int TEMP_g = -1; int TEMP_h = -1; int TEMP_i = -1; int TEMP_j = -1; 
+    int TEMP_a = -1; time_t TEMP_b = 0; int TEMP_c = -1; int TEMP_d = -1; int TEMP_e = -1; int TEMP_f = -1; int TEMP_g = -1; int TEMP_h = -1; int TEMP_i = -1; int TEMP_j = -1; 
     int TEMP_k = -1; int TEMP_l = -1; int TEMP_m = -1; int TEMP_n = -1; int TEMP_o = -1; int TEMP_p = -1; int TEMP_q = -1; int TEMP_r = -1; int TEMP_s = -1;
-    if ( (matchCount = sscanf(settingsBuffer,"b:%u,c:%d,d:%d,e:%d,f:%d,g:%d,h:%d,i:%d,j:%d,k:%d,l:%d,m:%d,n:%d,o:%d,p:%d,q:%d,r:%d,s:%d",
-    &TEMP_b,&TEMP_c,&TEMP_d,&TEMP_e,&TEMP_f,&TEMP_g,&TEMP_h,&TEMP_i,&TEMP_j,&TEMP_k,&TEMP_l,&TEMP_m,&TEMP_n,&TEMP_o,&TEMP_p,&TEMP_q,&TEMP_r,&TEMP_s) ) > 0 ) {
-        DEBUG("FROMSERVER: b:%u,c:%d,d:%d,e:%d,f:%d,g:%d,h:%d,i:%d,j:%d,k:%d,l:%d,m:%d,n:%d,o:%d,p:%d,q:%d,r:%d,s:%d\n",
-        TEMP_b,TEMP_c,TEMP_d,TEMP_e,TEMP_f,TEMP_g,TEMP_h,TEMP_i,TEMP_j,TEMP_k,TEMP_l,TEMP_m,TEMP_n,TEMP_o,TEMP_p,TEMP_q,TEMP_r,TEMP_s);
+    if ( (matchCount = sscanf(settingsBuffer,"a:%d,b:%u,c:%d,d:%d,e:%d,f:%d,g:%d,h:%d,i:%d,j:%d,k:%d,l:%d,m:%d,n:%d,o:%d,p:%d,q:%d,r:%d,s:%d",
+    &TEMP_a,&TEMP_b,&TEMP_c,&TEMP_d,&TEMP_e,&TEMP_f,&TEMP_g,&TEMP_h,&TEMP_i,&TEMP_j,&TEMP_k,&TEMP_l,&TEMP_m,&TEMP_n,&TEMP_o,&TEMP_p,&TEMP_q,&TEMP_r,&TEMP_s) ) > 0 ) {
+        DEBUG("FROMSERVER: a:%d,b:%u,c:%d,d:%d,e:%d,f:%d,g:%d,h:%d,i:%d,j:%d,k:%d,l:%d,m:%d,n:%d,o:%d,p:%d,q:%d,r:%d,s:%d\n",
+        TEMP_a,TEMP_b,TEMP_c,TEMP_d,TEMP_e,TEMP_f,TEMP_g,TEMP_h,TEMP_i,TEMP_j,TEMP_k,TEMP_l,TEMP_m,TEMP_n,TEMP_o,TEMP_p,TEMP_q,TEMP_r,TEMP_s);
         
         //FAILUREMODE need to be checking these against checksums
         char changed;
+        
+        if(TEMP_a != -1) { RET_setting_minimumupdate_hrs = TEMP_a;                 changed = 'Y'; } else { changed = 'N'; }; DEBUG("RET_setting_minimumupdate_hrs:%u..%c\n",RET_setting_minimumupdate_hrs,changed);
         if(TEMP_b != 0) { RET_RTCunixtime = TEMP_b; RET_RTCunixtime_bu = TEMP_b;   changed = 'Y'; } else { changed = 'N'; critical_fail_count++; }; DEBUG("RET_RTCunixtime:%u..%c\n",RET_RTCunixtime,changed);
         if(TEMP_c != -1) { RET_setting_firmware = TEMP_c;                          changed = 'Y'; } else { changed = 'N'; RET_setting_firmware = -1;}; DEBUG("RET_setting_firmware:%d..%c\n",RET_setting_firmware,changed);
         if(TEMP_d != -1) { setState(TEMP_d);                                       changed = 'Y'; } else { changed = 'N'; critical_fail_count++; }; DEBUG("RET_state:%d..%c\n",RET_state,changed);
@@ -466,7 +473,8 @@
         if (critical_fail_count == 0) { 
             DEBUG("GOT SETTINGS OK\n"); 
             saveEventTimes();
-            RET_haveSettings = true;     
+            RET_haveSettings = true;
+            RET_SettingsGotAt = RET_RTCunixtime;
             return true;
         } else {
             DEBUG("CRITICAL FAILS:%d\n",critical_fail_count);
@@ -518,7 +526,7 @@
         if (modem.registerOnNetwork(DEFAULT_CONNECTION_ATTEMPTS,(RET_setting_connection_timeout*1000))) {
             int timetaken = (RET_RTCunixtime - GLOBAL_wakeTime);
             char bytestosend[160];
-            snprintf(bytestosend,sizeof(bytestosend),"(%s,a:setup,f:%d,v:%.2f,t:%.1f,e:%d,z:SETUP-%s,c:1%s)\0",GLOBAL_defaultApi,FW_VERSION,voltage,temperature,timetaken,GLOBAL_exceptionString,locString);
+            snprintf(bytestosend,sizeof(bytestosend),"(%s,a:setup,f:%d,v:%.2f,t:%.1f,e:%d,z:SETUP-%s,c:1,s:1%s)\0",GLOBAL_defaultApi,FW_VERSION,voltage,temperature,timetaken,GLOBAL_exceptionString,locString);
             char result[180];
             snprintf(result,sizeof(result),"%s",modem.USSDmessage(bytestosend, true, 2, GLOBAL_defaultApi));
             if (result != "err") {
@@ -562,7 +570,7 @@
         if (modem.registerOnNetwork(DEFAULT_CONNECTION_ATTEMPTS,(RET_setting_connection_timeout*1000))) {
             int timetaken = (RET_RTCunixtime - GLOBAL_wakeTime);
             char bytestosend[160];
-            snprintf(bytestosend,sizeof(bytestosend),"(%s,a:loc,f:%d,t:%.1f,v:%.2f,z:TEST-%s,e:%d,c:1%s)\0",GLOBAL_defaultApi,FW_VERSION,temperature,voltage,GLOBAL_exceptionString,timetaken,locString);
+            snprintf(bytestosend,sizeof(bytestosend),"(%s,a:loc,f:%d,t:%.1f,v:%.2f,z:TEST-%s,e:%d,c:1,s:1%s)\0",GLOBAL_defaultApi,FW_VERSION,temperature,voltage,GLOBAL_exceptionString,timetaken,locString);
             char result[180];
             bool getSettings = true;
             snprintf(result,sizeof(result),"%s",modem.USSDmessage(bytestosend, getSettings, 2, GLOBAL_defaultApi));
@@ -595,10 +603,14 @@
         //SEND DATA
         if (modem.registerOnNetwork(DEFAULT_CONNECTION_ATTEMPTS,(RET_setting_connection_timeout*1000))) {
             int timetaken = (RET_RTCunixtime - GLOBAL_wakeTime);
+            
+            //Check if we should wait for settings back
+            bool getSettings = true;
+            if (  ((RET_RTCunixtime - RET_SettingsGotAt)/3600) < RET_setting_minimumupdate_hrs  ) { getSettings = false;}
+            
             char bytesToSend[160];
-            snprintf(bytesToSend,sizeof(bytesToSend),"(%s,a:loc,f:%d,t:%.1f,v:%.2f,z:LOC-%s,e:%d,c:1%s)\0",GLOBAL_defaultApi,FW_VERSION,temperature,voltage,GLOBAL_exceptionString,timetaken,locString);
+            snprintf(bytesToSend,sizeof(bytesToSend),"(%s,a:loc,f:%d,t:%.1f,v:%.2f,z:LOC-%s,e:%d,c:1,s:%d%s)\0",GLOBAL_defaultApi,FW_VERSION,temperature,voltage,GLOBAL_exceptionString,timetaken,getSettings,locString);
             char result[180];
-            bool getSettings = true;
             snprintf(result,sizeof(result),"%s",modem.USSDmessage(bytesToSend, getSettings, 2, GLOBAL_defaultApi));
             if (result != "err") {
                 //DEBUG("\nfromserver: %s \n",result);
--- a/modem.cpp	Tue Jan 01 15:44:24 2019 +0000
+++ b/modem.cpp	Tue Jan 01 20:46:39 2019 +0000
@@ -82,14 +82,14 @@
             
             //PRIORITISE 2G connection (reason being uses less power in some instances and can get cell tower tirangulation)
             //ATsendCMD("AT+QCFG=\"nwscanseq\",1"); //2G priority
-            ATsendCMD("AT+QCFG=\"nwscanseq\",2"); //3G priority
-            //ATsendCMD("AT+QCFG=\"nwscanseq\",0"); //AUTO
-            ATwaitForWord("OK",ATTIMEOUT_SHORT);
+            //ATsendCMD("AT+QCFG=\"nwscanseq\",2"); //3G priority
+            //ATsendCMD("AT+QCFG=\"nwscanseq\",0"); //AUTO - default
+            //ATwaitForWord("OK",ATTIMEOUT_SHORT);
             
             //CONNECTION TYPE
             //ATsendCMD("AT+QCFG=\"nwscanmode\",1"); //2G only connection
-            ATsendCMD("AT+QCFG=\"nwscanmode\",2"); //3G only connection
-            ATwaitForWord("OK",ATTIMEOUT_SHORT);
+            //ATsendCMD("AT+QCFG=\"nwscanmode\",2"); //3G only connection
+            //ATwaitForWord("OK",ATTIMEOUT_SHORT);
             
             return true;
         } else {
@@ -241,7 +241,7 @@
     int messageLength = strlen(message);
     if (messageLength > USSD_MAXLENGTH) {
         char message_failsafe[100];
-        snprintf(message_failsafe,sizeof(message_failsafe),"(%s,z:TOOBIG,c:%d)\0",api,messageIndex);
+        snprintf(message_failsafe,sizeof(message_failsafe),"(%s,z:TOOBIG,s:1,c:%d)\0",api,messageIndex);
         result = USSDsend(message_failsafe, maxAttempts);
     } else {
         result = USSDsend(message, maxAttempts);
@@ -364,7 +364,11 @@
                 
         //example from mulbs
         /*
+        2g
         +QENG: "servingcell","NOCONN","2G",234,30,8CC,A34E,20,668,0,-80,0,5,4,26,26,1,-,-,-,-,-,-,-,-,-,"-"
+        3g
+        +QENG: "servingcell","NOCONN","3G",234,20,8A,CE735F,10588,52,-97,-99,11,25,16,128,-,-,-,-,-,"-",-
+        
         +QENG: "neighbourcell","2G",234,30,8CC,A34D,20,656,-89,17,17,0,0
         +QENG: "neighbourcell","2G",234,30,8CC,678,61,686,-104,2,2,0,0
         +QENG: "neighbourcell","2G",234,30,8CC,4303,32,676,-104,2,2,0,0
@@ -380,7 +384,7 @@
     if (accuracy == 0) {
         sprintf(locDataOut,"\0");
     } else if (!haveGPSFix && !haveCellFix) {
-        sprintf(locDataOut,",g:0\0");
+        sprintf(locDataOut,"\0");
     }
     return locDataOut;
 }