questo a me andava già da subito

Dependencies:   WIZ820ioInterface mbed

Fork of Seeed_Ethernet_Shield by Shields

main.cpp

Committer:
screamer
Date:
2014-04-11
Revision:
0:1e952439b254
Child:
1:bb040724d21b

File content as of revision 0:1e952439b254:

#include "mbed.h"
#include "WIZ820ioInterface.h"

Serial pc(USBTX, USBRX);
WIZ820ioInterface eth(D11, D12, D13, D10, NC);

int main()
{
    wait(3);
    pc.printf(">>> Get IP via DHCP...\n");
    int s = eth.init(); // Use DHCP

    if (s != NULL) {
        pc.printf(">>> Could not initialise. Halting!\n");
        exit(0);
    }

    while (1) {
        s = eth.connect();

        if (s == false || s < 0) {
            pc.printf(">>> Could not connect to network. Retrying!\n");
            wait(3);
        } else {
            break;
        }
    }

    // successful DHCP
    pc.printf(">>> Got IP Address: %s\n", eth.getIPAddress());

    char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
    TCPSocketConnection sock;
    sock.connect("mbed.org", 80);    
    sock.send_all(http_cmd, sizeof(http_cmd)-1);
    pc.printf(">>> Sent request to mbed.org\n");

    char buffer[300];
    int ret;
    while (true) {
        ret = sock.receive(buffer, sizeof(buffer)-1);
        if (ret <= 0)
            break;
        buffer[ret] = '\0';
        pc.printf(">>> Received %d chars from mbed.org:\n%s\n", ret, buffer);
    }
    sock.close();
    
    eth.disconnect();
    return 0;
}