Example program for the SeeedStudio WiFi Shield V2.0, based on UART serial port connectivity (D0/D1 pins). This program connects to WiFi hotspot, obtains an IP using DHCP and downloads http://mbed.org/media/uploads/mbed_official/hello.txt

Dependencies:   WiflyInterface mbed

main.cpp

Committer:
screamer
Date:
2014-04-08
Revision:
0:f2524261196f
Child:
1:ced62d2a69f9

File content as of revision 0:f2524261196f:

#include "mbed.h"
#include "WiflyInterface.h"

/**
 * D1 - TX pin (RX on the WiFi side)
 * D0 - RX pin (TX on the WiFi side)
 * NC - Reset pin
 * LED1 - TCP status pin
 * "ssid" - hostspot name
 * "password" - hotspot passowrd
 * security method - NONE, WEP_128, WPA, WPA2
 */
WiflyInterface wifi(D1, D0, NC, LED1, "hotspot", "", NONE);
Serial pc(USBTX, USBRX);

int main()
{
    int s = wifi.init(); // Use DHCP
    if( s != NULL ) {
        printf("Could not initialise. Halting!\n");
        exit(0);
    }

    while (1) {
        s = wifi.connect(); // Set up the chip and join the network

        if( s == false ) {
            printf("Could not connect. Retrying!\n");
            wait(3);
            continue;
        } else {
            // Print the IP address every second
            while(1) {
                printf("Got IP: %s\n", wifi.getIPAddress());
                wait(1);
            }
        }
    }
}