Jan Korycan / Mbed 2 deprecated StarterKit_M2X_UDP

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

Fork of StarterKit_M2X_DevLab by Jan Korycan

Revision:
14:6034f6896f22
Parent:
10:a8495b430849
Child:
15:c63a080c6814
--- a/config_me.h	Mon Dec 11 20:02:13 2017 +0000
+++ b/config_me.h	Thu Apr 05 03:17:45 2018 +0000
@@ -1,13 +1,86 @@
-// Configure all M2X related values here
-
-char deviceId[33] = "beefbeefbeefbeefbeefbeefbeefbeef"; // Device you want to post to
-char m2xKey[33]   = "cafecafecafecafecafecafecafecafe"; // Your M2X API Key or Master API Key
-
 const char* hStreamName = "humidity";                      // Humidity stream ID
 const char* tStreamName = "temp";                          // Temperature stream ID
 const char* accelStreamNames[] = { "accelX", "accelY", "accelZ" };  // Accelerometer stream IDs
 
-int commandDelay = 10;                               // how many seconds we should wait between polling for a command
-int commandPolls = 6;                                // how many times we should poll for a command
-// these two also define how often we will be sending the data to M2X, 
-// the interval is commandPolls * commandDelay seconds, the default is 60 seconds (6 * 10 = 60s)
\ No newline at end of file
+class Configuration {
+public:
+    char    deviceId[33],   // Device you want to post to
+            m2xKey[33],     // Your M2X API Key or Master API Key
+            udpHost[30],
+            devIMEI[16];
+            
+    bool    enableM2X,
+            enableCommands,
+            enableUDP,
+            m2xConfigured;
+                        
+    int     commandDelay,   // how many seconds we should wait between polling for a command
+            commandPolls,   // how many times we should poll for a command
+            udpPort;
+            
+    double  locLat,
+            locLong;
+
+    Configuration(): deviceId(""),
+                    m2xKey(""),
+                    enableM2X(true), 
+                    enableCommands(false),                    
+                    enableUDP(false),
+                    commandDelay(10),
+                    commandPolls(6)
+    {
+        if (cfg.read("/sd/config.ini")) {
+            cfg.getValue("Device_ID", deviceId, sizeof(deviceId));
+            cfg.getValue("M2X_Key", m2xKey, sizeof(m2xKey));
+            cfg.getValue("UDP_Host", udpHost, sizeof(udpHost));
+            cfg.getValue("IMEI", devIMEI, sizeof(devIMEI));
+            
+            char buff[15];
+            int aux;
+            
+            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;
+            
+            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;
+
+            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);
+            
+            cfg.getValue("Latitude", buff, sizeof(buff));
+            lon = atof(buff);
+            
+            if ((lat >= -90) && (lat <= 90) && (lon >= -180) && (lon <= 180)) {
+                locLat = lat;
+                locLong = lon;
+            }
+        }
+        
+        m2xConfigured = *deviceId && *m2xKey;
+        
+        enableCommands &= enableM2X;
+    };
+        
+private:
+    ConfigFile cfg;
+};
\ No newline at end of file