Seeed / Mbed 2 deprecated Seeed_Ethernet_Shield_V2_HelloWorld

Dependencies:   WIZ820ioInterface mbed

Fork of Seeed_Ethernet_Shield_V2_HelloWorld by wei zou

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002   main.cpp
00003   2013 Copyright (c) Seeed Technology Inc.  All right reserved.
00004 
00005   Author:lawliet zou(lawliet.zou@gmail.com)
00006   2014-02-18
00007 
00008   This library is free software; you can redistribute it and/or
00009   modify it under the terms of the GNU Lesser General Public
00010   License as published by the Free Software Foundation; either
00011   version 2.1 of the License, or (at your option) any later version.
00012 
00013   This library is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016   Lesser General Public License for more details.
00017 
00018   You should have received a copy of the GNU Lesser General Public
00019   License along with this library; if not, write to the Free Software
00020   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00021 */
00022 
00023 #include "WIZ820ioInterface.h"
00024 #include "mbed.h"
00025 
00026 #if defined(TARGET_LPC11U24)    //SEEEDUINO_ARCH
00027     #define PIN_MOSI        P1_22
00028     #define PIN_MISO        P1_21
00029     #define PIN_SCLK        P1_20
00030     #define PIN_CS          P0_2
00031 #elif defined(TARGET_LPC1768)   //SEEEDUINO_ARCH_PRO
00032     #define PIN_MOSI        P0_18
00033     #define PIN_MISO        P0_17
00034     #define PIN_SCLK        P0_15
00035     #define PIN_CS          P0_6
00036 #else //please redefine the following pins
00037     #define PIN_MOSI
00038     #define PIN_MISO
00039     #define PIN_SCLK
00040     #define PIN_CS
00041 #endif
00042 
00043 WIZ820ioInterface eth(PIN_MOSI,PIN_MISO,PIN_SCLK,PIN_CS,NC);//mosi,miso,sclk,cs,reset;
00044 
00045 int main(void)
00046 {
00047     // use DHCP
00048     eth.init();
00049 
00050     // attempt DHCP
00051     eth.connect();
00052 
00053     // successful DHCP
00054     printf("IP Address is %s\n", eth.getIPAddress());
00055 
00056     TCPSocketConnection sock;
00057     sock.connect("mbed.org", 80);
00058 
00059     char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
00060     sock.send_all(http_cmd, sizeof(http_cmd)-1);
00061 
00062     char buffer[300];
00063     int ret;
00064     while (true) {
00065         ret = sock.receive(buffer, sizeof(buffer)-1);
00066         if (ret <= 0)
00067             break;
00068         buffer[ret] = '\0';
00069         printf("Received %d chars from server:\n%s\n", ret, buffer);
00070     }
00071 
00072     sock.close();
00073 
00074     eth.disconnect();
00075 
00076     return 0;
00077 }