Initial Program for MultiTech Dragonfly to communicate to PTC ThingWorx. Sensors are from Rohm version1

Dependencies:   MbedJSONValue mbed mtsas

Fork of UUU_MultiTech_Dragonfly_Sprint by Paul Jaeger

Revision:
4:730b61258422
Parent:
3:f6bceb9e5e1a
Child:
5:a946ef74a8c4
--- a/main.cpp	Thu Sep 24 19:35:46 2015 +0000
+++ b/main.cpp	Fri Sep 25 21:16:02 2015 +0000
@@ -19,9 +19,8 @@
  *   - prints all sensor data to debug port on a periodic basis
  *   - optionally send a SMS containing sensor data when the Grove Button
  *     is pushed (phone number must be configured)
- *   - optionally send sensor data to AT&T M2X cloud platform (user must
- *     create own M2X account and configure a device) if sensor data
- *     crosses established thresholds
+ *   - optionally sends sensor data to AT&T M2X cloud platform (user must
+ *     create own M2X account and configure a device)
  *
  * Setup:
  *   - Correctly insert SIM card into Dragonfly
@@ -58,11 +57,18 @@
 Cellular* radio;
 
 // APN associated with SIM card
-static const std::string apn = "";
+// this APN should work for the AT&T SIM that came with your Dragonfly
+//static const std::string apn = "";
+static const std::string apn = "broadband";
 
 // Phone number to send SMS messages to
 static const std::string phone_number = "1xxxxxxxxxx";
 
+// M2X variables
+static const std::string m2x_device_id = "";
+static const std::string m2x_key = "";
+bool do_cloud_post = false;
+
 // handle to MEMs board object
 static X_NUCLEO_IKS01A1* mems = X_NUCLEO_IKS01A1::Instance();
 
@@ -83,6 +89,10 @@
 int32_t acc_mg[3];
 int32_t gyro_mdps[3];
 
+// http variables
+HTTPClient* http;
+HTTPJson* http_json;
+
 // misc variables
 static char wall_of_dash[] = "--------------------------------------------------";
 bool radio_ok = false;
@@ -119,10 +129,12 @@
     Timer thpm_timer;
     Timer motion_timer;
     Timer print_timer;
+    Timer post_timer;
     
     thpm_timer.start();
     motion_timer.start();
     print_timer.start();
+    post_timer.start();
     
     while (true) {
         if (motion_timer.read_ms() > motion_interval_ms) {
@@ -186,6 +198,17 @@
             }
         }
         
+        if (post_timer.read_ms() > post_interval_ms && do_cloud_post) {
+            if (radio->connect()) {
+                logDebug("posting sensor data");
+                radio->disconnect();
+            } else {
+                logError("establishing PPP link failed");
+            }
+            
+            post_timer.reset();
+        }
+        
         wait_ms(10);
     }
 }