Example of using the ATT M2X back end. Connect over Wifi with the ESP8266 chip. This code sends random data to M2X. This code can be used for Any board, just change the RX/TX pins the wifi adapter is connected to.

Dependencies:   ESP8266Interface M2XStreamClient jsonlite mbed

Fork of M2X_K64F_Accel_ESP8266-wifi by AT&T Developer Summit Hackathon 2016

Revision:
3:694a1a67b156
Parent:
2:68b759c89fd9
Child:
4:3c1d712dcc48
--- a/main.cpp	Sat Aug 29 17:14:53 2015 +0000
+++ b/main.cpp	Fri Dec 11 00:19:45 2015 +0000
@@ -1,7 +1,8 @@
 #include "mbed.h"
 #include "FXOS8700Q.h"
 #include "M2XStreamClient.h"
-#include "EthernetInterface.h"
+#include "ESP8266Interface.h"
+#include "TCPSocketConnection.h"
 
 
 #ifndef MAX
@@ -16,21 +17,23 @@
 char streamName[] = "<stream name>"; // Stream you want to push to
 char m2xKey[] = "<m2x api key>"; // Your M2X API Key or Master API Key
 
+/*
+*  ESP8266 Wifi Config
+*/
+ESP8266Interface wifi(D8,D2,D3,"wifi-name","wifi-password",115200); // TX,RX,Reset,SSID,Password,Baud 
+
 int main()
 {
-    // Setup Ethernet
-    printf("Start\r\n");
-    EthernetInterface eth;
-    printf("Init...\r\n");
-    eth.init(); //Use DHCP
-    //eth.init(ip,mask,gateway); //Use Static IP Configuration
-    printf("Connect\r\n");
-    eth.connect();
-    printf("Device IP Address is %s\r\n", eth.getIPAddress());
+    printf("Starting...\r\n");
+
+    // connect to wifi
+    wifi.init(); //Reset
+    wifi.connect(); //Use DHCP
+    printf("IP Address is %s \n\r", wifi.getIPAddress());
 
     // Initialize the M2X client
     Client client;
-    M2XStreamClient m2xClient(&client, m2xKey);
+    M2XStreamClient m2xClient(&client, m2xKey,1,"52.22.150.98");
     int ret;
 
     // Create an accelerometer instance
@@ -57,10 +60,10 @@
 
         // If the maximum title is over 20 degrees, then send
         // data to stream
-        if (maxTilt > 20) {
+        
             ret = m2xClient.updateStreamValue(deviceId, streamName, maxTilt);
             printf("send() returned %d\r\n", ret);
             wait(1.0);
-        }
+        
     }
 }
\ No newline at end of file