Sample project to connect to AT&T M2X from the STM32 Nucleo + MTSAS Cellular SocketModem shield

Dependencies:   M2XStreamClient jsonlite mbed

Fork of MTSAS_Cellular_Connect_M2X_Example_F411 by Joe Tijerina

Revision:
15:a7512648f111
Parent:
14:025cccfe4215
Child:
16:3458e36115a9
--- a/main.cpp	Thu Sep 18 21:37:20 2014 +0000
+++ b/main.cpp	Fri Sep 19 21:31:28 2014 +0000
@@ -1,7 +1,32 @@
 #include "mbed.h"
 #include "mtsas.h"
+#include "M2XStreamClient.h"
 
-int main(){
+const char key[] = "08b2d950b81eec9545bf076714f2cf06";    // Replace with your M2X API key
+const char feed[] = "e3a9c12feecbd7cec32bfecdca22ccd2";   // Replace with your blueprint Feed ID
+const char stream[] = "temperature"; // Replace with your stream name  
+char name[] = "austin"; // Name of current location of datasource
+
+
+DigitalOut myled(D7);   
+AnalogIn tempSensor(A0);    
+
+int main()
+{ 
+    int ping_status = 0;
+    char amb_temp[6]; 
+    char water_sense[6];     
+    int response;
+    int a;
+    int adc_scale = 65535; 
+    int B = 3975;
+    int water;
+    float resistance; 
+    float temperature;
+    float temperature_f;   
+               
+                        
+                
     //Modify to match your apn if you are using an HSPA radio with a SIM card
     const char APN[] = "epc.tmobile.com";
     printf("Starting...\n");
@@ -77,12 +102,48 @@
         }
         if (radio->ping("www.google.com") == true) {
             logInfo("Successfully pinged www.google.com");
+            ping_status = 1;
             break;
         } else {
             wait(1);
         }
     }
+        
+    // Initialize the M2X client
+    Client client;    
+    M2XStreamClient m2xClient(&client, key);    
+
+    if (ping_status)
+    {    
+        while(1)    
+        {      
+            myled = 1; // LED is ON    
+            //a = tempSensor.read_u16();
+                   
+            //resistance = (float)(adc_scale-a)*10000/a; //get the resistance of the sensor;              
+            //temperature = 1/(log(resistance/10000)/B+1/298.15)-273.15;  //convert to temperature via datasheet        
+            //temperature_f = (1.8 * temperature) + 32.0;
+            //sprintf(amb_temp, "%0.2f", temperature_f);  
+            
+            //printf("Temp Sensor Analog Reading is 0x%X = %d   ", a, a);         
+            //printf("Current Temperature: %f C  %f F \n\r", temperature, temperature_f); 
+            
+            temperature++;
+            printf("temperature: %f \n", temperature);
+            response = m2xClient.put(feed, stream, temperature);
+            printf("Post response code: %d\r\n", response);
+            if (response == -1) 
+            {
+                break; 
+            }                   
+            
+            myled = 0; // LED is OFF        
     
+            delay(5000);      
+                    
+        }
+    }
+            
     //Disconnect ppp link
     radio->disconnect();