Sample project to connect to AT&T M2X from the STM32 Nucleo + MTS WiFi shield

Dependencies:   M2XStreamClient SocketModem jsonlite mbed

Fork of STM32_MTS_Wifi_Connect_M2X by AT&T Developer Summit Hackathon 2016

main.cpp

Committer:
sam_grove
Date:
2014-01-02
Revision:
0:23c1654d70e4
Child:
1:b2a530079150

File content as of revision 0:23c1654d70e4:

#include "mbed.h"
#include "MTSSerial.h"
#include "Wifi.h"
using namespace mts;

int main()
{
    std::string ssid = "your network name";
    std::string securityKey = "your pass phrase";
    Wifi::SecurityType securityType = Wifi::WPA2;

    //Wait for wifi module to boot up
    for (int i = 10; i >= 0; i = i - 2) {
        wait(2);
        printf("Waiting %d seconds...\n\r", i);
    }

    //Setup serial interface to WiFi module
    MTSSerial* serial = new MTSSerial(PTD3, PTD2, 256, 256);
    serial->baud(9600);

    //Setup Wifi class
    Wifi* wifi = Wifi::getInstance();
    printf("Init: %s\n\r", wifi->init(serial) ? "SUCCESS" : "FAILURE");

    //Setup and check connection
    printf("Set Network: %s\n\r", getCodeNames(wifi->setNetwork(ssid, securityType, securityKey)).c_str());
    printf("Set DHCP: %s\n\r", getCodeNames(wifi->setDeviceIP("DHCP")).c_str());
    printf("Connect: %s\n\r", wifi->connect() ? "Success" : "Failure");
    printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False");
    printf("Ping Server: %s\n\r", wifi->ping("8.8.8.8") ? "Success" : "Failed");

    //Disconnect from network
    printf("Disconnecting...\n\r");
    wifi->disconnect();
    printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False");

    printf("End Program\n\r");
    while(1);
}