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:
3:ff2bf7a1ece8
Parent:
2:1df4b48824b1
Child:
4:d16e07588838
--- a/main.cpp	Fri Aug 12 16:15:00 2016 +0000
+++ b/main.cpp	Fri Aug 12 18:16:13 2016 +0000
@@ -151,7 +151,7 @@
     // Disable the battery charger unless a battery is attached.
     bc_nce = 1;
 
-    static int post_interval_ms = 2000; //************* I don't want to wait 30 seconds ************************/
+    static int post_interval_ms = 500; //************* I don't want to wait 30 seconds ************************/
 
     // Change the baud rate of the debug port from the default 9600 to 115200.
     Serial debug(USBTX, USBRX);
@@ -195,13 +195,15 @@
     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 );
 
 #ifdef RPR0521      //als digital
             ReadRPR0521_ALS ();
@@ -211,10 +213,10 @@
             int sensor_data = -1;
             int proximity_data = -1;
 #endif
-            logDebug("\r\nPosting sensor data %d",sensor_data);
-            std::string sensor_data_str = patch::to_string(sensor_data);
-            logDebug("Sensor data string: %s",sensor_data_str.c_str());
-
+            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");
@@ -239,28 +241,12 @@
                 char http_rx_buf[1024];
                 char http_tx_buf[1024];
 
-                //sprintf(http_tx_buf,"\"Light\": \"%d\" \"Proximity\": \"%d\"",sensor_data, proximity_data);
                 memset(http_tx_buf, 0, sizeof(http_tx_buf));
                 memset(http_rx_buf, 0, sizeof(http_rx_buf));
-                snprintf(http_tx_buf, sizeof(http_tx_buf), "{ \"Light\": \"%d\" }", sensor_data);
+                snprintf(http_tx_buf, sizeof(http_tx_buf), "{ \"Light\": \"%d\" , \"Proximity\": \"%d\" }", sensor_data,proximity_data);
                 logDebug("%s",http_tx_buf);
                 HTTPResult res;
 
-//                char http_tx_buf[] = "{  \"temperature\": \"715\" }";
-//                char http_tx_buf[] = "{  \"temperature\": \"" + sensor_data_str.c_str() + "\" }";            //failed to compile
-//                char http_tx_buf[] = "{  \"temperature\": \"715\"";
-//                strcat (http_tx_buf,sensor_data_str.c_str());
-//                strcat (http_tx_buf, "\" }");
-//                logDebug ("\r\n %s %d \r\n", http_tx_buf, sizeof(http_tx_buf));
-
-
-                //string txx_buf = "{  \"temperature\": \"";
-                //strcat (txx_buf,sensor_data_str.c_str());
-                //strcat (txx_buf, "\" }");
-                //logDebug ("\r\n %s %d \r\n", txx_buf.c_str(), txx_buf.size());
-                //http_tx_buf = txx_bug.c_str();
-
-
                 // IHTTPDataIn object - will contain data received from server.
                 HTTPText http_rx(http_rx_buf, sizeof(http_rx_buf));
 
@@ -269,7 +255,7 @@
                 HTTPJson http_tx(http_tx_buf, strlen(http_tx_buf)+1);
 
                 // Make a HTTP POST request to http://httpbin.org/
-                res = http.post("http://quickstart.internetofthings.ibmcloud.com/api/v0002/device/types/dragonflytype/devices/dragonfly01/events/myEvent", http_tx, &http_rx);
+                res = http.post("http://quickstart.internetofthings.ibmcloud.com/api/v0002/device/types/dragonflytype/devices/dragonfly02/events/myEvent", http_tx, &http_rx);
                 if (res != HTTP_OK)
                     logError("HTTPS POST to Bluemix failed [%d][%s]", res, httpResToStr(res));
                 else
@@ -278,6 +264,7 @@
                 //logInfo("finished - bringing down link");
                 radio->disconnect();
                 post_timer.reset();
+                countingLoop +=1;
             }
         }