init
Dependencies: aconno_I2C Lis2dh12 WatchdogTimer
Diff: main.cpp
- Revision:
- 17:ba55c026b1d6
- Parent:
- 16:3bf5f1a5f869
- Child:
- 18:22edaa7e74b1
--- a/main.cpp Mon Dec 17 22:47:13 2018 +0000
+++ b/main.cpp Mon Dec 17 23:36:10 2018 +0000
@@ -292,25 +292,13 @@
//------------------------------------------------------------------------------
bool saveSettings(char* settingsBuffer) {
//process result
- int matchCount = 0;
- char TEMP_a[6];
- int TEMP_b = 0;
- int TEMP_c = 0;
- int TEMP_d = 0;
- int TEMP_e = 0;
- int TEMP_f = 0;
- int TEMP_g = 0;
- int TEMP_h = 0;
- int TEMP_i = 0;
- int TEMP_j = 0;
- int TEMP_k = 0;
- int TEMP_l = 0;
- int TEMP_m = 0;
- int TEMP_n = 0;
- time_t TEMP_o = 0;
- if ( (matchCount = sscanf(settingsBuffer,"a:%c%c%c%c%c%c,b:%d,c:%d,d:%d,e:%d,f:%d,g:%d,h:%d,i:%d,j:%d,k:%d,l:%d,m:%d,n:%d,0:%u",
- &TEMP_a[0],&TEMP_a[1],&TEMP_a[2],&TEMP_a[3],&TEMP_a[4],&TEMP_a[5],&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) ) > 0 ) {
- DEBUG("VALUES: a:%s,b:%d,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\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);
+ int matchCount = 0;
+ char TEMP_a[6]; 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,"a:%c%c%c%c%c%c,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[0],&TEMP_a[1],&TEMP_a[2],&TEMP_a[3],&TEMP_a[4],&TEMP_a[5],&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("VALUES: a:%s,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);
RET_haveSettings = true;
return true;
} else {
@@ -332,9 +320,10 @@
GLOBAL_imei = RET_imei;
DEBUG("imei: %lld \n",RET_imei);
if (modem.registerOnNetwork(3,60000)) {
- char* bytestosend;
- sprintf(bytestosend,"(im:%lld,%s,v:%.2f,fr:1,z:SETUP,c:1)\0",GLOBAL_imei,GLOBAL_defaultApi,GLOBAL_voltage);
- char* result = modem.USSDmessage(bytestosend, false, 2, GLOBAL_defaultApi);
+ char bytestosend[160];
+ snprintf(bytestosend,sizeof(bytestosend),"(%s,im:%lld,v:%.2f,fr:1,z:SETUP,c:1)\0",GLOBAL_defaultApi,GLOBAL_imei,GLOBAL_voltage);
+ char result[180];
+ snprintf(result,sizeof(result),"%s",modem.USSDmessage(bytestosend, true, 2, GLOBAL_defaultApi));
if (result != "err") {
DEBUG("result: %s \n",result);
saveSettings(result);
@@ -347,10 +336,10 @@
//FAILUREMODE Modem failed to turn on
}
- //while (1) {
- // Thread::wait(60000);
- // watchdog.kick();
- //}
+ while (1) {
+ Thread::wait(60000);
+ watchdog.kick();
+ }
//RESULT
if (pass) {