port ethernet libray for stm32f407 (seeed arch max). it works.

Dependencies:   EthernetInterface-arch-max-dev mbed-rtos mbed-src

Fork of TCPSocket_HelloWorld by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "EthernetInterface.h"
00003 
00004 int main() {
00005     EthernetInterface eth;
00006 //    eth.init("192.168.1.3", "255.255.255.0", "192.168.1.1"); 
00007     eth.init(); // use DHCP
00008     eth.connect();
00009     printf("IP Address is %s\n", eth.getIPAddress());
00010 
00011 
00012     TCPSocketConnection sock;
00013     sock.connect("mbed.org", 80);
00014     
00015     char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
00016     sock.send_all(http_cmd, sizeof(http_cmd)-1);
00017     
00018     char buffer[300];
00019     int ret;
00020     while (true) {
00021         ret = sock.receive(buffer, sizeof(buffer)-1);
00022         if (ret <= 0)
00023             break;
00024         buffer[ret] = '\0';
00025         printf("Received %d chars from server:\n%s\n", ret, buffer);
00026     }
00027       
00028     sock.close();
00029     
00030     eth.disconnect();
00031     
00032     while(1) {} 
00033 }