Example program for MTS WiFi Shield. Test that you can connect to a network.
Dependencies: SocketModem mbed
main.cpp@5:19044863e45c, 2014-01-04 (annotated)
- Committer:
- jengbrecht
- Date:
- Sat Jan 04 20:29:00 2014 +0000
- Revision:
- 5:19044863e45c
- Parent:
- 4:6daf448c5b1c
- Child:
- 6:7c2bdcf9d302
Updated the documentation in main
Who changed what in which revision?
User | Revision | Line number | New 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"; |
sam_grove | 4:6daf448c5b1c | 17 | Wifi::SecurityType securityType = Wifi::NONE; |
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"); |
sam_grove | 0:23c1654d70e4 | 38 | printf("Ping Server: %s\n\r", wifi->ping("8.8.8.8") ? "Success" : "Failed"); |
sam_grove | 0:23c1654d70e4 | 39 | |
sam_grove | 0:23c1654d70e4 | 40 | //Disconnect from network |
sam_grove | 0:23c1654d70e4 | 41 | printf("Disconnecting...\n\r"); |
sam_grove | 0:23c1654d70e4 | 42 | wifi->disconnect(); |
sam_grove | 0:23c1654d70e4 | 43 | printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False"); |
sam_grove | 0:23c1654d70e4 | 44 | |
sam_grove | 0:23c1654d70e4 | 45 | printf("End Program\n\r"); |
sam_grove | 0:23c1654d70e4 | 46 | while(1); |
sam_grove | 0:23c1654d70e4 | 47 | } |