Demo code for Seeed Ethernet Shield V2.0
Dependencies: WIZ820ioInterface mbed
Fork of Seeed_Ethernet_Shield_V2_HelloWorld by
main.cpp@0:84c1d086f776, 2014-02-18 (annotated)
- Committer:
- lawliet
- Date:
- Tue Feb 18 06:28:27 2014 +0000
- Revision:
- 0:84c1d086f776
Initial Version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lawliet | 0:84c1d086f776 | 1 | /* |
lawliet | 0:84c1d086f776 | 2 | main.cpp |
lawliet | 0:84c1d086f776 | 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. |
lawliet | 0:84c1d086f776 | 4 | |
lawliet | 0:84c1d086f776 | 5 | Author:lawliet zou(lawliet.zou@gmail.com) |
lawliet | 0:84c1d086f776 | 6 | 2014-02-18 |
lawliet | 0:84c1d086f776 | 7 | |
lawliet | 0:84c1d086f776 | 8 | This library is free software; you can redistribute it and/or |
lawliet | 0:84c1d086f776 | 9 | modify it under the terms of the GNU Lesser General Public |
lawliet | 0:84c1d086f776 | 10 | License as published by the Free Software Foundation; either |
lawliet | 0:84c1d086f776 | 11 | version 2.1 of the License, or (at your option) any later version. |
lawliet | 0:84c1d086f776 | 12 | |
lawliet | 0:84c1d086f776 | 13 | This library is distributed in the hope that it will be useful, |
lawliet | 0:84c1d086f776 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
lawliet | 0:84c1d086f776 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
lawliet | 0:84c1d086f776 | 16 | Lesser General Public License for more details. |
lawliet | 0:84c1d086f776 | 17 | |
lawliet | 0:84c1d086f776 | 18 | You should have received a copy of the GNU Lesser General Public |
lawliet | 0:84c1d086f776 | 19 | License along with this library; if not, write to the Free Software |
lawliet | 0:84c1d086f776 | 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
lawliet | 0:84c1d086f776 | 21 | */ |
lawliet | 0:84c1d086f776 | 22 | |
lawliet | 0:84c1d086f776 | 23 | #include "WIZ820ioInterface.h" |
lawliet | 0:84c1d086f776 | 24 | #include "mbed.h" |
lawliet | 0:84c1d086f776 | 25 | |
lawliet | 0:84c1d086f776 | 26 | #if defined(TARGET_LPC11U24) //SEEEDUINO_ARCH |
lawliet | 0:84c1d086f776 | 27 | #define PIN_MOSI P1_22 |
lawliet | 0:84c1d086f776 | 28 | #define PIN_MISO P1_21 |
lawliet | 0:84c1d086f776 | 29 | #define PIN_SCLK P1_20 |
lawliet | 0:84c1d086f776 | 30 | #define PIN_CS P0_2 |
lawliet | 0:84c1d086f776 | 31 | #elif defined(TARGET_LPC1768) //SEEEDUINO_ARCH_PRO |
lawliet | 0:84c1d086f776 | 32 | #define PIN_MOSI P0_18 |
lawliet | 0:84c1d086f776 | 33 | #define PIN_MISO P0_17 |
lawliet | 0:84c1d086f776 | 34 | #define PIN_SCLK P0_15 |
lawliet | 0:84c1d086f776 | 35 | #define PIN_CS P0_6 |
lawliet | 0:84c1d086f776 | 36 | #else //please redefine the following pins |
lawliet | 0:84c1d086f776 | 37 | #define PIN_MOSI |
lawliet | 0:84c1d086f776 | 38 | #define PIN_MISO |
lawliet | 0:84c1d086f776 | 39 | #define PIN_SCLK |
lawliet | 0:84c1d086f776 | 40 | #define PIN_CS |
lawliet | 0:84c1d086f776 | 41 | #endif |
lawliet | 0:84c1d086f776 | 42 | |
lawliet | 0:84c1d086f776 | 43 | WIZ820ioInterface eth(PIN_MOSI,PIN_MISO,PIN_SCLK,PIN_CS,NC);//mosi,miso,sclk,cs,reset; |
lawliet | 0:84c1d086f776 | 44 | |
lawliet | 0:84c1d086f776 | 45 | int main(void) |
lawliet | 0:84c1d086f776 | 46 | { |
lawliet | 0:84c1d086f776 | 47 | // use DHCP |
lawliet | 0:84c1d086f776 | 48 | eth.init(); |
lawliet | 0:84c1d086f776 | 49 | |
lawliet | 0:84c1d086f776 | 50 | // attempt DHCP |
lawliet | 0:84c1d086f776 | 51 | eth.connect(); |
lawliet | 0:84c1d086f776 | 52 | |
lawliet | 0:84c1d086f776 | 53 | // successful DHCP |
lawliet | 0:84c1d086f776 | 54 | printf("IP Address is %s\n", eth.getIPAddress()); |
lawliet | 0:84c1d086f776 | 55 | |
lawliet | 0:84c1d086f776 | 56 | TCPSocketConnection sock; |
lawliet | 0:84c1d086f776 | 57 | sock.connect("mbed.org", 80); |
lawliet | 0:84c1d086f776 | 58 | |
lawliet | 0:84c1d086f776 | 59 | char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n"; |
lawliet | 0:84c1d086f776 | 60 | sock.send_all(http_cmd, sizeof(http_cmd)-1); |
lawliet | 0:84c1d086f776 | 61 | |
lawliet | 0:84c1d086f776 | 62 | char buffer[300]; |
lawliet | 0:84c1d086f776 | 63 | int ret; |
lawliet | 0:84c1d086f776 | 64 | while (true) { |
lawliet | 0:84c1d086f776 | 65 | ret = sock.receive(buffer, sizeof(buffer)-1); |
lawliet | 0:84c1d086f776 | 66 | if (ret <= 0) |
lawliet | 0:84c1d086f776 | 67 | break; |
lawliet | 0:84c1d086f776 | 68 | buffer[ret] = '\0'; |
lawliet | 0:84c1d086f776 | 69 | printf("Received %d chars from server:\n%s\n", ret, buffer); |
lawliet | 0:84c1d086f776 | 70 | } |
lawliet | 0:84c1d086f776 | 71 | |
lawliet | 0:84c1d086f776 | 72 | sock.close(); |
lawliet | 0:84c1d086f776 | 73 | |
lawliet | 0:84c1d086f776 | 74 | eth.disconnect(); |
lawliet | 0:84c1d086f776 | 75 | |
lawliet | 0:84c1d086f776 | 76 | return 0; |
lawliet | 0:84c1d086f776 | 77 | } |