Example program for MTS WiFi Shield. Test that you can connect to a network.
Dependencies: SocketModem mbed
main.cpp
- Committer:
- jengbrecht
- Date:
- 2014-01-04
- Revision:
- 5:19044863e45c
- Parent:
- 4:6daf448c5b1c
- Child:
- 6:7c2bdcf9d302
File content as of revision 5:19044863e45c:
#include "mbed.h" #include "MTSSerial.h" #include "Wifi.h" using namespace mts; /* This example shows how to do a basic connectivity test using * the MTS Wifi shield board. You will need to change the network * SSID and security key, unless you are at the 2014 AT&T hackathon * where you can use the defaults below. */ int main() { //Set the network parameters std::string ssid = "belkin54g"; std::string securityKey = "hackathon"; Wifi::SecurityType securityType = Wifi::NONE; //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); }