Example of using the ATT M2X back end. Connect over Wifi with the ESP8266 chip. This code sends accelerometer 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 FXOS8700Q M2XStreamClient jsonlite mbed
Fork of M2X_K64F_Accel by
Revision 3:694a1a67b156, committed 2015-12-11
- Comitter:
- mbedAustin
- Date:
- Fri Dec 11 00:19:45 2015 +0000
- Parent:
- 2:68b759c89fd9
- Commit message:
- swapped out ethernet library with ESP8266 wifi library, pre-populated wifi with pin deffinitions for Nucleo 411 board
Changed in this revision
diff -r 68b759c89fd9 -r 694a1a67b156 ESP8266Interface.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ESP8266Interface.lib Fri Dec 11 00:19:45 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/ESP8266/code/ESP8266Interface/#03fd9333670d
diff -r 68b759c89fd9 -r 694a1a67b156 EthernetInterface.lib --- a/EthernetInterface.lib Sat Aug 29 17:14:53 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/EthernetInterface/#f69b81aa9eb1
diff -r 68b759c89fd9 -r 694a1a67b156 main.cpp --- 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
diff -r 68b759c89fd9 -r 694a1a67b156 mbed-rtos.lib --- a/mbed-rtos.lib Sat Aug 29 17:14:53 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#34e80e862021