Alex Alex / Mbed 2 deprecated Antarctic

Dependencies:   mbed mbed-STM32F103C8T6 MLX90614 Watchdog DS1820

Files at this revision

API Documentation at this revision

Comitter:
spin7ion
Date:
Tue Sep 29 19:48:56 2020 +0000
Parent:
8:245231755415
Child:
10:51960145754a
Commit message:
Some fixes

Changed in this revision

config.h 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
--- a/config.h	Tue Sep 29 17:45:22 2020 +0000
+++ b/config.h	Tue Sep 29 19:48:56 2020 +0000
@@ -7,10 +7,10 @@
 #define STATE_SENDING_TELEMETRY 4
 #define STATE_SLEEPING 5
 
-#define SLEEP_CHECK_TIME 60
-#define SLEEP_TIME_S 60*5
+#define SLEEP_CHECK_TIME 5
+#define SLEEP_TIME_S 60
 #define WATCHDOG_INTERVAL_S SLEEP_TIME_S+5
-#define FIX_CHECK_TIME_S 60
+#define FIX_CHECK_TIME_S 5
 #define FIX_MAX_TRIES 3
 
 #define PIN_SDA     PB_9
@@ -22,7 +22,7 @@
 #define PIN_RX      PA_3
 
 
-#define DEBUG_SIM 1
+#define DEBUG_SIM 0
 #define DEBUG_PC 1
 
 #define NBIOT_TELEMETRY_URL "http://iotsandbox.mts.ru:8080/api/v1/msyDlNiOZVAzKkkmVNVU/telemetry"
\ No newline at end of file
--- a/main.cpp	Tue Sep 29 17:45:22 2020 +0000
+++ b/main.cpp	Tue Sep 29 19:48:56 2020 +0000
@@ -159,7 +159,7 @@
 }
 
 bool enableGPS(bool powerUp) {
-    pc.printf("Powering GPS:");
+    pc.printf("Powering GPS %s:",powerUp?"up":"down");
     if(powerUp){
         _parser->send("AT+CGNSPWR=1"); //GPS power on
     } else {
@@ -195,7 +195,7 @@
           curLine = nextLine ? (nextLine+1) : NULL;
         }
         return fix>0;
-    }    
+    } 
     return false;
 }
 
@@ -207,9 +207,9 @@
     #if DEBUG_PC
     pc.baud(115200);
     pc.printf("Starting\r\n");
-    if (wd.WatchdogCausedReset())
+    if (wd.WatchdogCausedReset()) {
         pc.printf("Watchdog caused reset.\r\n");
-    
+    }
     #endif
     
     wd.Configure(WATCHDOG_INTERVAL_S);       // sets the timeout interval
@@ -219,7 +219,7 @@
     _parser = new ATCmdParser(_serial);
     _parser->debug_on( DEBUG_SIM );
     _parser->set_delimiter( "\r\n" );
-    _parser->set_timeout (1000*60);
+    _parser->set_timeout (WATCHDOG_INTERVAL_S/2);
     wait(0.5);
     
     enableGPS(0);
@@ -261,10 +261,14 @@
                 enableGPS(0);
                 state=STATE_COLLECTING_TELEMETRY; 
             } else {
+                #if DEBUG_PC
+                pc.printf("No fix at %d try\n", fixTries);
+                #endif
                 fixTries++;
                 if (fixTries>FIX_MAX_TRIES) {
                     //fix not achieved in given tries, send as is
                     enableGPS(0);
+                    wd.Service();
                     state=STATE_COLLECTING_TELEMETRY;
                 } else {
                     wd.Service();
@@ -295,13 +299,14 @@
             //Form JSON as {"tempIR":1,"temps":[1,...,10],"latitude":37,"longitude":51,"altitude":21,"validGeo":true}
             
             
-            snprintf(bufferString,2048,"{\"tempIR\":%f,\"latitude\":%f,\"longitude\":%f,\"altitude\":%f,\"validGeo\":%s,", IRtemp, latitude, longitude, altitude, fix ? "true" : "false");
+            snprintf(bufferString,2048,"{\"tempIR\":%f,\"latitude\":%f,\"longitude\":%f,\"altitude\":%f,\"validGeo\":%s,temps:[", IRtemp, latitude, longitude, altitude, fix ? "true" : "false");
             
             index = strlen(bufferString);
             
             for(i=0;i<SENSORS_COUNT;i++){
-                index += snprintf(&bufferString[index], 128-index, "%f", stickTemperatures[i]);
+                index += snprintf(&bufferString[index], 2048-index, i==0?"%f":",%f", stickTemperatures[i]);
             }
+            strcat (bufferString,"]}");
             
             
             state=STATE_SENDING_TELEMETRY;
@@ -328,12 +333,12 @@
         
         wd.Service();
         
-        #if DEBUG_PC
+        /*#if DEBUG_PC
             for(i=0;i<SENSORS_COUNT;i++){
                 pc.printf("temp[%d] = %3.1f C\r\n", i, stickTemperatures[i]);     // read temperature    
             }
             pc.printf("Temperature : %4.2f C2\r\n",IRtemp);
-        #endif
+        #endif*/
 
         //Feed the watchdog
         wd.Service();