Example of using the ATT M2X back end. Connect over Ethernet with the WIZnet 5500 chip. This code sends random data to M2X.

Dependencies:   M2XStreamClient WIZnet_Library jsonlite mbed

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

Committer:
mbedAustin
Date:
Fri Dec 11 00:37:37 2015 +0000
Revision:
5:b3bcb048a5a5
Parent:
4:3c1d712dcc48
Child:
6:694279899cf2
changed settings for Nucleo 411 board

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jb8414 0:ece599ab76bb 1 #include "mbed.h"
jb8414 0:ece599ab76bb 2 #include "M2XStreamClient.h"
mbedAustin 3:694a1a67b156 3 #include "ESP8266Interface.h"
mbedAustin 3:694a1a67b156 4 #include "TCPSocketConnection.h"
jb8414 0:ece599ab76bb 5
mbedAustin 5:b3bcb048a5a5 6 //
mbedAustin 5:b3bcb048a5a5 7 // Fill these field in from you ATT M2X Account
mbedAustin 5:b3bcb048a5a5 8 //
jb8414 1:c7b9e522cc8e 9 char deviceId[] = "<device id>"; // Device you want to push to
jb8414 1:c7b9e522cc8e 10 char streamName[] = "<stream name>"; // Stream you want to push to
jb8414 1:c7b9e522cc8e 11 char m2xKey[] = "<m2x api key>"; // Your M2X API Key or Master API Key
jb8414 0:ece599ab76bb 12
mbedAustin 3:694a1a67b156 13 /*
mbedAustin 5:b3bcb048a5a5 14 * ESP8266 Wifi Config for nucleo 411
mbedAustin 3:694a1a67b156 15 */
mbedAustin 5:b3bcb048a5a5 16 ESP8266Interface wifi(D8,D2,D3,"wifi-name","wifi-password",115200); // TX,RX,Reset,SSID,Password,Baud
mbedAustin 3:694a1a67b156 17
jb8414 0:ece599ab76bb 18 int main()
jb8414 0:ece599ab76bb 19 {
mbedAustin 3:694a1a67b156 20 printf("Starting...\r\n");
mbedAustin 3:694a1a67b156 21
mbedAustin 3:694a1a67b156 22 // connect to wifi
mbedAustin 3:694a1a67b156 23 wifi.init(); //Reset
mbedAustin 3:694a1a67b156 24 wifi.connect(); //Use DHCP
mbedAustin 3:694a1a67b156 25 printf("IP Address is %s \n\r", wifi.getIPAddress());
jb8414 0:ece599ab76bb 26
jb8414 0:ece599ab76bb 27 // Initialize the M2X client
jb8414 0:ece599ab76bb 28 Client client;
mbedAustin 5:b3bcb048a5a5 29 M2XStreamClient m2xClient(&client, m2xKey,1,"52.22.150.98"); // api-m2x.att.com
mbedAustin 5:b3bcb048a5a5 30
jb8414 0:ece599ab76bb 31 int ret;
mbedAustin 5:b3bcb048a5a5 32 volatile int randomNumber = 0;
jb8414 0:ece599ab76bb 33
jb8414 0:ece599ab76bb 34 while (true) {
mbedAustin 5:b3bcb048a5a5 35 // send a random number to M2X every 5 seconds
mbedAustin 5:b3bcb048a5a5 36 randomNumber = rand();
mbedAustin 5:b3bcb048a5a5 37 ret = m2xClient.updateStreamValue(deviceId, streamName, randomNumber);
mbedAustin 5:b3bcb048a5a5 38 printf("send() returned %d\r\n", ret);
mbedAustin 5:b3bcb048a5a5 39 wait(5.0);
jb8414 0:ece599ab76bb 40 }
jb8414 0:ece599ab76bb 41 }