MultiTech Dragonfly with ROHM Sensor board sending data to IBM BlueMix Quickstart

Dependencies:   mbed mtsas FXAS21002 FXOS8700 mbed-rtos

Fork of AvnetWorking_IBM_QuickStart by Paul Jaeger

Revision:
4:d16e07588838
Parent:
3:ff2bf7a1ece8
Child:
5:dbedb2422089
--- a/main.cpp	Fri Aug 12 18:16:13 2016 +0000
+++ b/main.cpp	Fri Aug 12 19:24:41 2016 +0000
@@ -73,9 +73,9 @@
 
 
 //char BlueMix_HEADER[] = "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n";
-char BlueMix_HEADER[] = "Content-Type: application/json";
+//char BlueMix_HEADER[] = "Content-Type: application/json";
 
-const char BlueMix_URL[] = "http://" ORG ".internetofthings.ibmcloud.com/api/v0002/device/types/" DEVICE_TYPE "/devices/" DEVICE_ID "/events/" EVENT;
+//const char BlueMix_URL[] = "http://" ORG ".internetofthings.ibmcloud.com/api/v0002/device/types/" DEVICE_TYPE "/devices/" DEVICE_ID "/events/" EVENT;
 //  replace typeID and deviceId with "" and delete ()
 //  replace $eventId =  IBM will define in class.
 
@@ -186,44 +186,47 @@
         }
     }
 
+    Timer post_timer;
+    post_timer.start();
+    int timeStamp;
+    int countingLoop = 0;
+    Timer loop_timer;
+    loop_timer.start();
 
     logInfo("setting APN");
     if (radio->setApn(apn) != MTS_SUCCESS)
         logError("failed to set APN to \"%s\"", apn);
     logInfo("APN set successful");
 
-    Timer post_timer;
-    post_timer.start();
-    int timeStamp;
-    int countingLoop = 0;
-    
-    logInfo("Entering loop");
-    while (true) {
-        if (post_timer.read_ms() > post_interval_ms ) {            // can this be changed to seconds?
-            timeStamp = post_timer.read_ms();
-            logDebug("timer read %d", timeStamp);
-            logDebug("timer value %d",  post_interval_ms );
-            logDebug("loop count value %d",  countingLoop );
+    logInfo("bringing up the link");                  //added to the program to create a connection outside of the while(1) loop.
+    if (! radio->connect()) {
+        logError("failed to bring up the link");
+        //return 0;
+    } else {
+
+        logInfo("Entering loop");
+        while (countingLoop < 25 ) {
+            if (post_timer.read_ms() > post_interval_ms  ) {            // can this be changed to seconds?
+                timeStamp = post_timer.read_ms();
+                logDebug("timer read %d", timeStamp);
+                logDebug("timer value %d",  post_interval_ms );
+                logDebug("loop count value %d",  countingLoop );
 
 #ifdef RPR0521      //als digital
-            ReadRPR0521_ALS ();
-            int sensor_data = RPR0521_ALS[0];
-            int proximity_data = RPR0521_ALS[1];
+                ReadRPR0521_ALS ();
+                int sensor_data = RPR0521_ALS[0];
+                int proximity_data = RPR0521_ALS[1];
 #else
-            int sensor_data = -1;
-            int proximity_data = -1;
+                int sensor_data = -1;
+                int proximity_data = -1;
 #endif
-            logDebug("\r\nPosting Light Reading: %d Proximity Reading: %d",sensor_data,proximity_data);
-            
-            logDebug("https://quickstart.internetofthings.ibmcloud.com");
-            
+                logDebug("\r\nPosting Light Reading: %d Proximity Reading: %d",sensor_data,proximity_data);
+
+                logDebug("https://quickstart.internetofthings.ibmcloud.com");
+
 //            http_tx.clear();
 
-            logInfo("bringing up the link");
-            if (! radio->connect()) {
-                logError("failed to bring up the link");
-                //return 0;
-            } else {
+                logInfo("bringing up the link");
 
                 // HTTPClient object used for HTTP requests.
                 HTTPClient http;
@@ -262,7 +265,7 @@
                     logInfo("HTTPS POST to Bluemix succeeded [%d]\r\n%s", http.getHTTPResponseCode(), http_rx_buf);
 
                 //logInfo("finished - bringing down link");
-                radio->disconnect();
+//                radio->disconnect();
                 post_timer.reset();
                 countingLoop +=1;
             }
@@ -270,9 +273,18 @@
 
         //return 0;
     }
-    //radio->disconnect();
+    radio->disconnect();
+    timeStamp = loop_timer.read_ms();
+    logInfo("loop timer = %d", timeStamp);
+
+    logInfo("\r\n\n\nEnd Of Line\r\n");
 }
 
+
+/***********************************************
+  *   below are the call routines
+/***********************************************/
+
 bool init_mtsas()
 {
     io = new mts::MTSSerialFlowControl(RADIO_TX, RADIO_RX, RADIO_RTS, RADIO_CTS);