Example program for MTS WiFi Shield. Test that you can connect to a network.
Dependencies: SocketModem mbed
main.cpp@1:b2a530079150, 2014-01-03 (annotated)
- Committer:
- sam_grove
- Date:
- Fri Jan 03 05:03:38 2014 +0000
- Revision:
- 1:b2a530079150
- Parent:
- 0:23c1654d70e4
- Child:
- 2:5f1645f60a3b
updates to socketmodem
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 | |
sam_grove | 0:23c1654d70e4 | 6 | int main() |
sam_grove | 0:23c1654d70e4 | 7 | { |
sam_grove | 1:b2a530079150 | 8 | // std::string ssid = "your network name"; |
sam_grove | 1:b2a530079150 | 9 | // std::string securityKey = "your pass phrase"; |
sam_grove | 1:b2a530079150 | 10 | std::string ssid = "McGroves"; |
sam_grove | 1:b2a530079150 | 11 | std::string securityKey = "purnell44"; |
sam_grove | 0:23c1654d70e4 | 12 | Wifi::SecurityType securityType = Wifi::WPA2; |
sam_grove | 0:23c1654d70e4 | 13 | |
sam_grove | 0:23c1654d70e4 | 14 | //Wait for wifi module to boot up |
sam_grove | 0:23c1654d70e4 | 15 | for (int i = 10; i >= 0; i = i - 2) { |
sam_grove | 0:23c1654d70e4 | 16 | wait(2); |
sam_grove | 0:23c1654d70e4 | 17 | printf("Waiting %d seconds...\n\r", i); |
sam_grove | 0:23c1654d70e4 | 18 | } |
sam_grove | 0:23c1654d70e4 | 19 | |
sam_grove | 0:23c1654d70e4 | 20 | //Setup serial interface to WiFi module |
sam_grove | 0:23c1654d70e4 | 21 | MTSSerial* serial = new MTSSerial(PTD3, PTD2, 256, 256); |
sam_grove | 0:23c1654d70e4 | 22 | serial->baud(9600); |
sam_grove | 0:23c1654d70e4 | 23 | |
sam_grove | 0:23c1654d70e4 | 24 | //Setup Wifi class |
sam_grove | 0:23c1654d70e4 | 25 | Wifi* wifi = Wifi::getInstance(); |
sam_grove | 0:23c1654d70e4 | 26 | printf("Init: %s\n\r", wifi->init(serial) ? "SUCCESS" : "FAILURE"); |
sam_grove | 0:23c1654d70e4 | 27 | |
sam_grove | 0:23c1654d70e4 | 28 | //Setup and check connection |
sam_grove | 0:23c1654d70e4 | 29 | printf("Set Network: %s\n\r", getCodeNames(wifi->setNetwork(ssid, securityType, securityKey)).c_str()); |
sam_grove | 0:23c1654d70e4 | 30 | printf("Set DHCP: %s\n\r", getCodeNames(wifi->setDeviceIP("DHCP")).c_str()); |
sam_grove | 0:23c1654d70e4 | 31 | printf("Connect: %s\n\r", wifi->connect() ? "Success" : "Failure"); |
sam_grove | 0:23c1654d70e4 | 32 | printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False"); |
sam_grove | 0:23c1654d70e4 | 33 | printf("Ping Server: %s\n\r", wifi->ping("8.8.8.8") ? "Success" : "Failed"); |
sam_grove | 0:23c1654d70e4 | 34 | |
sam_grove | 0:23c1654d70e4 | 35 | //Disconnect from network |
sam_grove | 0:23c1654d70e4 | 36 | printf("Disconnecting...\n\r"); |
sam_grove | 0:23c1654d70e4 | 37 | wifi->disconnect(); |
sam_grove | 0:23c1654d70e4 | 38 | printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False"); |
sam_grove | 0:23c1654d70e4 | 39 | |
sam_grove | 0:23c1654d70e4 | 40 | printf("End Program\n\r"); |
sam_grove | 0:23c1654d70e4 | 41 | while(1); |
sam_grove | 0:23c1654d70e4 | 42 | } |