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

Committer:
mfiore
Date:
Sat Jan 04 21:02:31 2014 +0000
Revision:
6:7c2bdcf9d302
Parent:
5:19044863e45c
Child:
8:fa93a2d07116
put wifi->ping() in a while loop for robustness; change default Wifi::SecurityMode to Wifi::WPA since we're giving out access to our router

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 0:23c1654d70e4 1 #include "mbed.h"
sam_grove 0:23c1654d70e4 2 #include "MTSSerial.h"
sam_grove 0:23c1654d70e4 3 #include "Wifi.h"
sam_grove 0:23c1654d70e4 4 using namespace mts;
sam_grove 0:23c1654d70e4 5
jengbrecht 5:19044863e45c 6 /* This example shows how to do a basic connectivity test using
jengbrecht 5:19044863e45c 7 * the MTS Wifi shield board. You will need to change the network
jengbrecht 5:19044863e45c 8 * SSID and security key, unless you are at the 2014 AT&T hackathon
jengbrecht 5:19044863e45c 9 * where you can use the defaults below.
jengbrecht 5:19044863e45c 10 */
jengbrecht 5:19044863e45c 11
sam_grove 0:23c1654d70e4 12 int main()
sam_grove 0:23c1654d70e4 13 {
jengbrecht 5:19044863e45c 14 //Set the network parameters
sam_grove 4:6daf448c5b1c 15 std::string ssid = "belkin54g";
jengbrecht 5:19044863e45c 16 std::string securityKey = "hackathon";
mfiore 6:7c2bdcf9d302 17 Wifi::SecurityType securityType = Wifi::WPA;
sam_grove 0:23c1654d70e4 18
sam_grove 0:23c1654d70e4 19 //Wait for wifi module to boot up
sam_grove 0:23c1654d70e4 20 for (int i = 10; i >= 0; i = i - 2) {
sam_grove 0:23c1654d70e4 21 wait(2);
sam_grove 0:23c1654d70e4 22 printf("Waiting %d seconds...\n\r", i);
sam_grove 0:23c1654d70e4 23 }
sam_grove 0:23c1654d70e4 24
sam_grove 0:23c1654d70e4 25 //Setup serial interface to WiFi module
sam_grove 0:23c1654d70e4 26 MTSSerial* serial = new MTSSerial(PTD3, PTD2, 256, 256);
sam_grove 0:23c1654d70e4 27 serial->baud(9600);
sam_grove 0:23c1654d70e4 28
sam_grove 0:23c1654d70e4 29 //Setup Wifi class
sam_grove 0:23c1654d70e4 30 Wifi* wifi = Wifi::getInstance();
sam_grove 0:23c1654d70e4 31 printf("Init: %s\n\r", wifi->init(serial) ? "SUCCESS" : "FAILURE");
sam_grove 0:23c1654d70e4 32
sam_grove 0:23c1654d70e4 33 //Setup and check connection
sam_grove 0:23c1654d70e4 34 printf("Set Network: %s\n\r", getCodeNames(wifi->setNetwork(ssid, securityType, securityKey)).c_str());
sam_grove 0:23c1654d70e4 35 printf("Set DHCP: %s\n\r", getCodeNames(wifi->setDeviceIP("DHCP")).c_str());
sam_grove 0:23c1654d70e4 36 printf("Connect: %s\n\r", wifi->connect() ? "Success" : "Failure");
sam_grove 0:23c1654d70e4 37 printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False");
mfiore 6:7c2bdcf9d302 38
mfiore 6:7c2bdcf9d302 39 //Ping
mfiore 6:7c2bdcf9d302 40 while (true) {
mfiore 6:7c2bdcf9d302 41 printf("Ping Server: %s\n\r", wifi->ping("8.8.8.8") ? "Success" : "Failed");
mfiore 6:7c2bdcf9d302 42 wait(3);
mfiore 6:7c2bdcf9d302 43 }
sam_grove 0:23c1654d70e4 44 }