Initial commit

Dependencies:   ConfigFile FXOS8700CQ M2XStreamClient-JMF MODSERIAL SDFileSystem WNCInterface jsonlite mbed-rtos mbed

Fork of StarterKit_M2X_DevLab by Jan Korycan

Files at this revision

API Documentation at this revision

Comitter:
korycanjan
Date:
Thu Apr 05 19:04:26 2018 +0000
Parent:
15:c63a080c6814
Commit message:
Configuration updates.

Changed in this revision

config_me.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
diff -r c63a080c6814 -r 358604977188 config_me.h
--- a/config_me.h	Thu Apr 05 16:41:34 2018 +0000
+++ b/config_me.h	Thu Apr 05 19:04:26 2018 +0000
@@ -38,37 +38,40 @@
             char buff[15];
             int aux;
             
-            cfg.getValue("Enable_M2X", buff, sizeof(buff));
-            enableM2X = strcmp(buff, "1") == 0;
+            if (cfg.getValue("Enable_M2X", buff, sizeof(buff)))
+                enableM2X = strcmp(buff, "1") == 0;
             
-            cfg.getValue("M2X_Commmands", buff, sizeof(buff));
-            enableCommands = strcmp(buff, "1") == 0;
-                        
-            cfg.getValue("Enable_UDP", buff, sizeof(buff));
-            enableUDP = strcmp(buff, "1") == 0;
+            if (cfg.getValue("M2X_Commmands", buff, sizeof(buff)))
+                enableCommands = strcmp(buff, "1") == 0;
+            
+            if (cfg.getValue("Enable_UDP", buff, sizeof(buff)))
+                enableUDP = strcmp(buff, "1") == 0;
             
-            cfg.getValue("Command_Wait", buff, sizeof(buff));
-            aux = atoi(buff);
-            if ((aux > 0) && (aux < 3600))
-                commandDelay = aux;
-                
-            cfg.getValue("Command_Polls", buff, sizeof(buff));
-            aux = atoi(buff);
-            if ((aux > 0) && (aux < 10))
-                commandPolls = aux;
+            if (cfg.getValue("Command_Wait", buff, sizeof(buff))) {
+                aux = atoi(buff);
+                if ((aux > 0) && (aux < 3600))
+                    commandDelay = aux;
+            };
 
-            cfg.getValue("UDP_Port", buff, sizeof(buff));
-            aux = atoi(buff);
-            if ((aux > 0) && (aux < 65535))
-                udpPort = aux;
+            if (cfg.getValue("Command_Polls", buff, sizeof(buff))) {
+                aux = atoi(buff);
+                if ((aux > 0) && (aux < 10))
+                    commandPolls = aux;
+            };
+
+            if (cfg.getValue("UDP_Port", buff, sizeof(buff))) {
+                aux = atoi(buff);
+                if ((aux > 0) && (aux < 65535))
+                    udpPort = aux;
+            };
                 
             double lat, lon;
             
-            cfg.getValue("Latitude", buff, sizeof(buff));
-            lat = atof(buff);
+            if (cfg.getValue("Latitude", buff, sizeof(buff)))
+                lat = atof(buff);
             
-            cfg.getValue("Latitude", buff, sizeof(buff));
-            lon = atof(buff);
+            if (cfg.getValue("Longitude", buff, sizeof(buff)))
+                lon = atof(buff);
             
             if ((lat >= -90) && (lat <= 90) && (lon >= -180) && (lon <= 180)) {
                 locLat = lat;
@@ -78,7 +81,7 @@
         
         m2xConfigured = *deviceId && *m2xKey;
         
-        enableCommands &= enableM2X;
+        enableCommands = enableM2X && enableCommands;
     };
     
     void dumpConfig(Serial& pc) {
@@ -97,6 +100,7 @@
         pc.printf("#" CRLF);
         pc.printf("Command_Wait=%d" CRLF, commandDelay);
         pc.printf("Command_Polls=%d" CRLF, commandPolls);
+        pc.printf("# Data will be sent every %d seconds" CRLF, commandPolls * commandDelay);
     }
         
 private:
diff -r c63a080c6814 -r 358604977188 main.cpp
--- a/main.cpp	Thu Apr 05 16:41:34 2018 +0000
+++ b/main.cpp	Thu Apr 05 19:04:26 2018 +0000
@@ -277,20 +277,26 @@
 
 #define MAX_AMOC 16+(7*5)+11+12
 void run_amoc() {
-    pc.printf("Sending data to AMOC." CRLF);
+    pc.printf("Sending data over UDP to %s:%d ... ", conf.udpHost, conf.udpPort);
     WncEndpoint AmocEndpoint;
     WncUDPSocket AmocSocket;
     char buff[MAX_AMOC];
     
     if (!AmocEndpoint.set_address(conf.udpHost, conf.udpPort)) {
-        pc.printf("Cannot resolve AMOC endpoint." CRLF);
+        pc.printf("Cannot resolve UDP endpoint." CRLF);
         return;
     };
     
     snprintf(buff, MAX_AMOC, "'%s',%.2f,%.2f,%.2f,%.2f,%.2f,%2.6f,%3.6f", conf.devIMEI, SENSOR_DATA.Temperature, SENSOR_DATA.Humidity, SENSOR_DATA.AccelX, SENSOR_DATA.AccelY, SENSOR_DATA.AccelZ, conf.locLat, conf.locLong);
         
     int resp = AmocSocket.sendTo(AmocEndpoint, buff, strlen(buff));
-    pc.printf("%d bytes sent to AMOC" CRLF , resp);
+    pc.printf("%d bytes sent." CRLF , resp);
+    if (resp < 0) {
+         unsigned char aux = lastLedColor;
+         SetLedColor(3); //Yellow
+         lastLedColor = aux;
+    } else 
+        SetLedColor(lastLedColor);
 }
     
 
@@ -325,8 +331,10 @@
     pc.printf("Initialize the sensors" CRLF);    
     sensors_init();
     read_sensors();
-    
+
+    pc.printf(CYN);    
     conf.dumpConfig(pc);
+    pc.printf(WHT);    
     
     if (!conf.m2xConfigured) {
         pc.printf(RED "Waiting for SMS configuration" CRLF);
@@ -405,7 +413,8 @@
 #endif
             timeService.getTimestamp(timestamp, &length);
             pc.printf("%s waiting for %d seconds... " CRLF , timestamp, conf.commandDelay * conf.commandPolls);
-        };
+        } else 
+            pc.printf("Sensor values [%.2f,%.2f,%.2f,%.2f,%.2f]. Sleeping for %d seconds." CRLF, SENSOR_DATA.Humidity, SENSOR_DATA.Temperature, SENSOR_DATA.AccelX, SENSOR_DATA.AccelY, SENSOR_DATA.AccelZ, conf.commandDelay * conf.commandPolls);
         
         // save old sensor data, we will use them to check for accelerometer change
         OLD_SENSOR_DATA = SENSOR_DATA;