Demo app to read data from temperature sensor connected to STM-F411RE and send values to AT&T M2X Data Service via MTS shield.

Dependencies:   M2XStreamClient SocketModem jsonlite mbed

Fork of STM32_MTS_Wifi_Connect_M2X by AT&T Developer Summit Hackathon 2016

Revision:
17:e54be812a3b3
Parent:
16:921fec88838d
--- a/main.cpp	Tue Aug 19 19:12:11 2014 +0000
+++ b/main.cpp	Fri Sep 05 02:28:21 2014 +0000
@@ -1,10 +1,12 @@
 #include "mbed.h"
 #include "M2XStreamClient.h"
-#include "MTSSerial.h"
-#include "Wifi.h"
 #include "include_me.h"
 #include "math.h"
 
+// set to 1 for cellular shield board
+// set to 0 for wifi shield board
+#define CELL_SHIELD 1
+
 using namespace mts;
 
 /* This example shows how to do a basic connectivity test to AT&T M2X Cloud 
@@ -14,10 +16,10 @@
 
 using namespace mts;
 
-const char key[] = "your_api_key";    // Replace with your M2X API key
-const char feed[] = "your_feed_id";   // Replace with your blueprint Feed ID
-const char stream[] = "your_stream_name"; // Replace with your stream name  
-char name[] = "your_device_location_name"; // Name of current location of datasource
+const char key[] = "<key>";    // Replace with your M2X API key
+const char feed[] = "<feed>";   // Replace with your blueprint Feed ID
+const char stream[] = "<stream>"; // Replace with your stream name  
+char name[] = "<location>"; // Name of current location of datasource
 
 double latitude = 30.3748076;
 double longitude = -97.7386896; // You can also read those values from a GPS
@@ -59,10 +61,66 @@
     float temperature_f;    
           
     //Set the network parameters
-    std::string ssid =  "your_wifi_ssid"; 
-    std::string securityKey = "your_wifi_passphrase"; 
+    std::string ssid =  "<ssid>"; 
+    std::string securityKey = "<password>"; 
     Wifi::SecurityType securityType = Wifi::WPA2;
 
+ printf("starting\n\r");
+ 
+#if CELL_SHIELD
+    MTSSerialFlowControl* serial = new MTSSerialFlowControl(PA_9, PA_10, PA_1, PA_0);
+    serial->baud(115200);
+    printf("serialflow ok\n\r");
+    Transport::setTransport(Transport::CELLULAR);
+    Cellular* cell = Cellular::getInstance();
+    cell->init(serial, PB_5, PA_8); //DCD and DTR pins for STM411
+
+    int max_tries = 5;
+    int i;
+    std::string apn = "wap.cingular";  // set to the appropriate APN (i.e. "m2m.com.attz" for M2X SIMs, wap.cingular)
+
+    i = 0;
+    while (i++ < max_tries) {
+        if (cell->getRegistration() == Cellular::REGISTERED) {
+            printf("registered with tower\n\r");
+            break;
+        } else if (i >= max_tries) {
+            printf("failed to register with tower\n\r");
+        } else {
+            wait(3);
+        }
+    }
+
+    printf("signal strength: %d\n\r", cell->getSignalStrength());
+
+    i = 0;
+    printf("setting APN to %s\n\r", apn.c_str());
+    while (i++ < max_tries) {
+        if (cell->setApn(apn) == SUCCESS) {
+            printf("successfully set APN\n\r");
+            break;
+        } else if (i >= max_tries) {
+            printf("failed to set APN\n\r");
+        } else {
+            wait(1);
+        }
+    }
+
+    i = 0;
+    printf("bringing up PPP link\n\r");
+    while (i++ < max_tries) {
+        if (cell->connect()) {
+            printf("PPP link is up\n\r");
+            break;
+        } else if (i >= max_tries) {
+            printf("failed to bring PPP link up\n\r");
+        } else {
+            wait(1);
+        }
+    }
+#else
+    // WiFi shield
+    
     //Wait for wifi module to boot up
     for (int i = 10; i >= 0; i = i - 2) {
         wait(2);
@@ -70,7 +128,7 @@
     }
 
     //Setup serial interface to WiFi module
-    MTSSerial* serial = new MTSSerial(D8, D2, 256, 4096);   
+    MTSSerial* serial = new MTSSerial(PA_9, PA_10, 256, 4096);   
     serial->baud(9600);
 
     Transport::setTransport(Transport::WIFI);
@@ -88,10 +146,12 @@
     }
     printf("Connect: Success\r\n");
     printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False");
+
+
     
     printf("Ping Server: %s\n\r", wifi->ping("8.8.8.8") ? "Success" : "Failed");
     wait(1);
-    
+#endif
 
     // Initialize the M2X client
     Client client;