init
Dependencies: aconno_I2C Lis2dh12 WatchdogTimer
Revision 31:c84fc6d8eaa3, committed 2019-01-01
- Comitter:
- pathfindr
- Date:
- Tue Jan 01 15:44:24 2019 +0000
- Parent:
- 30:7e90ddd7ed12
- Child:
- 32:dff4858bdf37
- Commit message:
- 10
Changed in this revision
--- a/README.md Mon Dec 24 02:01:38 2018 +0000 +++ b/README.md Tue Jan 01 15:44:24 2019 +0000 @@ -1,4 +1,4 @@ -MUST DO!!!!!! +TO DO!!!!!! 1) Add watchdog kicks to modem functions 2) USSDmessage index needs to work @@ -18,4 +18,25 @@ 16) test motion start stop times exactly 17) add extra 1cm to gsm antenna 18) errors while sending causes need to double send ussd command, adds on 5-10 seconds -19) check voltage calibation \ No newline at end of file +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 + + + +RESOLVED - TO BE TESTED AGAIN... +20) location accuracy 0 does not seem to work + + +TEST RESULTS: +CE3165 - ID 109 + +RUN 1. GPS with 10 seconds fix hold, 2G priority, receipts everytime, 1m interval. +Starting battery 3.19v, End battery 2.5v +Post time average (excluding reciept): 39 seconds +Post count: 3569 (last record id 5540) + + + + +
--- a/main.cpp Mon Dec 24 02:01:38 2018 +0000
+++ b/main.cpp Tue Jan 01 15:44:24 2019 +0000
@@ -162,18 +162,17 @@
bool memoryIntegrityCheck() {
bool pass = true;
//check memory is init correct
- if (RET_memTest != 12345) {
- pass = false;
- }
- //Check clocks match and are in range
- if (RET_RTCunixtime != RET_RTCunixtime || RET_RTCunixtime < 1545412457) {
- pass = false;
- }
+ if (RET_memTest != 12345) { pass = false; DEBUG("Mem fail 1\n"); }
+ //Check clocks match
+ if (RET_RTCunixtime != RET_RTCunixtime_bu) { pass = false; DEBUG("Mem fail 2\n"); }
+ //Check clocks are in range (only if we have settings)
+ if (RET_haveSettings && RET_RTCunixtime < 1545412457) { pass = false; DEBUG("Mem fail 3\n"); }
return pass;
}
void dumpSettings() {
DEBUG("RET_memTest:%d \n",RET_memTest);
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_state:%d \n",RET_state);
DEBUG("RET_setting_location_mode:%d \n",RET_setting_location_mode);
@@ -228,7 +227,7 @@
void RTCtick() {
//YOU MUST NOT CALL ANY OTHER FUNCTIONS OR DEBUG FROM INSIDE HERE!!! OR IT LOCKS UP THE DEVICE, just change vars
RET_RTCunixtime += 1;
- RET_RTCunixtime_bu += 1;
+ RET_RTCunixtime_bu = RET_RTCunixtime;
GLOBAL_RTCunixtime = RET_RTCunixtime;
//button logic - check for hold
@@ -439,7 +438,7 @@
//FAILUREMODE need to be checking these against checksums
char changed;
- if(TEMP_b != 0) { RET_RTCunixtime = TEMP_b; changed = 'Y'; } else { changed = 'N'; critical_fail_count++; }; DEBUG("RET_RTCunixtime:%u..%c\n",RET_RTCunixtime,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);
if(TEMP_e != -1) { RET_setting_location_mode = TEMP_e; changed = 'Y'; } else { changed = 'N'; }; DEBUG("RET_setting_location_mode:%d..%c\n",RET_setting_location_mode,changed);
@@ -531,10 +530,13 @@
}
} else {
//FAILUREMODE modem failed to register on network
+ DEBUG("NET REGISTER FAIL");
pass = false;
}
} else {
//FAILUREMODE Modem failed to turn on
+ DEBUG("MODEM ON FAIL");
+ LED1blink(200,50);
pass = false;
}
@@ -572,6 +574,8 @@
}
}
}
+ } else {
+ LED1blink(200,50);
}
//RESETS
RET_motionTriggeredInTXInterval = 0;
@@ -586,10 +590,8 @@
Modem modem(PN_UART_TX, PN_UART_RX, PN_UART_CTS, PN_UART_RTS, PN_GSM_PWR_KEY, PN_VREG_EN, PN_GSM_WAKE_DISABLE);
if (modem.on()) {
char locString[70];
- if (RET_setting_location_accuracy > 0) {
- memcpy(locString, modem.getLocation(RET_setting_location_accuracy, RET_setting_location_timeout), 70);
- //DEBUG("locString:%s-\n",locString);
- }
+ memcpy(locString, modem.getLocation(RET_setting_location_accuracy, RET_setting_location_timeout), 70);
+ //DEBUG("locString:%s-\n",locString);
//SEND DATA
if (modem.registerOnNetwork(DEFAULT_CONNECTION_ATTEMPTS,(RET_setting_connection_timeout*1000))) {
int timetaken = (RET_RTCunixtime - GLOBAL_wakeTime);
@@ -605,6 +607,8 @@
}
}
}
+ } else {
+ LED1blink(200,50);
}
//RESETS
RET_motionTriggeredInTXInterval = 0;
@@ -629,6 +633,8 @@
if (RET_haveSettings) { RET_motionFrameStart = RET_RTCunixtime; }
}
}
+ } else {
+ LED1blink(200,50);
}
//RESETS
RET_motionTriggeredInTXInterval = 0;
@@ -646,9 +652,10 @@
if (setup()) {
// All good
} else {
+ LED1blink(200,50);
RET_eventTime_wakeFromDormant = (RET_RTCunixtime + (24*3600)); //24hrs
setState(STATE_DORMANT);
- DEBUG("SETSTATE:DORMANT until %u\n",RET_eventTime_wakeFromDormant);
+ DEBUG("SETUP FAILED:DORMANT until %u\n",RET_eventTime_wakeFromDormant);
}
break;
case STATE_NORMAL :
@@ -684,7 +691,6 @@
}
if (strlen(RET_activityData) > 130) { run_activity_tx = true; }
if (run_activity_tx) { DEBUG("ACTIVITY TX...\n"); event_activity_tx();}
-
break;
case STATE_DORMANT :
if (RET_RTCunixtime >= RET_eventTime_wakeFromDormant) {
@@ -693,7 +699,6 @@
} else {
setState(STATE_SETUP);
}
-
DEBUG("WAKING UP FROM DORMANT\n");
}
DEBUG("STATE:DORMANT until %u\n",RET_eventTime_wakeFromDormant);
@@ -750,7 +755,7 @@
int main() {
//INIT
turnOffEverything();
- if (!memoryIntegrityCheck()) { RET_coldBoot = 1; LED1on(5000);}
+ if (!memoryIntegrityCheck()) { RET_coldBoot = 1;}
RTCticker.attach(&RTCtick, 1.0);
button.fall(&buttonPress); //does this affect power?
button.rise(&buttonRelease);
@@ -762,6 +767,7 @@
case 0x00000001 :
DEBUG("0x%08x. Hard Reset ST:%d\n",NRF_POWER->RESETREAS, RET_state);
RET_coldBoot = 1;
+ dumpSettings();
break;
case 0x00000002 :
DEBUG("Watchdog ST:%d\n",RET_state);
@@ -773,7 +779,6 @@
NRF_POWER->RESETREAS = 0xffffffff;
}
- //dumpSettings();
//CHECK FOR FIRST BOOT
if (RET_coldBoot == 1) { factoryReset(); dumpSettings(); }
--- a/modem.cpp Mon Dec 24 02:01:38 2018 +0000
+++ b/modem.cpp Tue Jan 01 15:44:24 2019 +0000
@@ -26,7 +26,7 @@
int targetIndex = 0;
bool havefullmatch = false;
char captured[32];
- memset (captured,0,sizeof(captured));
+ memset(captured,0,sizeof(captured));
Timer t;
t.start();
uint32_t startmillis = t.read_ms();
@@ -81,15 +81,15 @@
ATwaitForWord("OK",ATTIMEOUT_SHORT);
//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\",1"); //2G priority
+ ATsendCMD("AT+QCFG=\"nwscanseq\",2"); //3G priority
//ATsendCMD("AT+QCFG=\"nwscanseq\",0"); //AUTO
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 {
@@ -139,11 +139,6 @@
{
//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;
@@ -222,7 +217,7 @@
led1 = 0;
if ( (matchCount = _uart.scanf(",\"%d#%[^#]",USSDmessageIndex,ATinBuffer) ) > 0 ) {
if (USSDmessageIndex == messageIndex) {
- //NEED TO GET THIS WORKING SO WE KNOW WE ARE DEALING WITH THE RIGT MESSAGE
+ //NEED TO GET THIS WORKING SO WE KNOW WE ARE DEALING WITH THE RIGHT MESSAGE
//MOVE THE BELOW INTO THIS IF STAEMEBNTS
}
led1 = 1;
@@ -274,6 +269,7 @@
bool haveGPSFix = false;
bool haveCellFix = false;
char locDataOut[100];
+ memset(locDataOut,0,sizeof(locDataOut));
Timer t;
t.start();
uint32_t startmillis;
@@ -358,8 +354,8 @@
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");
+ sprintf(locDataOut,",h:%s.%s.%d.%d\0",cellID,lac,mcc,mnc);
+ //sprintf(locDataOut,",h:41806.2252.234.30\0");
haveCellFix = true;
//DEBUG("\ncellOut:%s\n",locDataOut);
}
@@ -381,6 +377,11 @@
}
//RETURN
+ if (accuracy == 0) {
+ sprintf(locDataOut,"\0");
+ } else if (!haveGPSFix && !haveCellFix) {
+ sprintf(locDataOut,",g:0\0");
+ }
return locDataOut;
}