Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: M2XStreamClient WIZnet_Library jsonlite mbed
Fork of M2X_Nucleo411_ESP8266-wifi by
main.cpp
- Committer:
- mbedAustin
- Date:
- 2015-12-11
- Revision:
- 5:b3bcb048a5a5
- Parent:
- 4:3c1d712dcc48
- Child:
- 6:694279899cf2
File content as of revision 5:b3bcb048a5a5:
#include "mbed.h"
#include "M2XStreamClient.h"
#include "ESP8266Interface.h"
#include "TCPSocketConnection.h"
//
// Fill these field in from you ATT M2X Account
//
char deviceId[] = "<device id>"; // Device you want to push to
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 for nucleo 411
*/
ESP8266Interface wifi(D8,D2,D3,"wifi-name","wifi-password",115200); // TX,RX,Reset,SSID,Password,Baud 
int main()
{
    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,1,"52.22.150.98"); // api-m2x.att.com
    
    int ret;
    volatile int randomNumber = 0;
    while (true) {
        // send a random number to M2X every 5 seconds
        randomNumber = rand();
        ret = m2xClient.updateStreamValue(deviceId, streamName, randomNumber);
        printf("send() returned %d\r\n", ret);
        wait(5.0);
    }
}
            
    