ECE4180 lab2 part 5
Dependencies: EthernetInterface mbed-rtos mbed
Fork of TCPSocket_HelloWorld by
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 00004 Serial pc(USBTX, USBRX); // tx, rx 00005 00006 extern "C" void mbed_mac_address(char *mac); 00007 00008 int main() { 00009 00010 // to get the mac address of the mbed 00011 char mac[6]; 00012 mbed_mac_address(mac); 00013 for(int i=0; i<6;i++) { 00014 printf("%02X ", mac[i]); 00015 } 00016 printf("\n"); 00017 00018 EthernetInterface eth; 00019 eth.init(); //Use DHCP 00020 00021 pc.printf("Testing Init"); 00022 int err = eth.connect(15000); 00023 if (err != 0 ) { 00024 pc.printf("Error in connection error code is %d. \n", err); 00025 } else { 00026 // exit(1); 00027 } 00028 pc.printf("IP Address is %s\n", eth.getIPAddress()); 00029 TCPSocketConnection sock; 00030 sock.connect("mbed.org", 80); 00031 00032 char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n"; 00033 sock.send_all(http_cmd, sizeof(http_cmd)-1); 00034 00035 char buffer[300]; 00036 int ret; 00037 while (true) { 00038 ret = sock.receive(buffer, sizeof(buffer)-1); 00039 if (ret <= 0) 00040 break; 00041 buffer[ret] = '\0'; 00042 printf("Received %d chars from server:\n%s\n", ret, buffer); 00043 } 00044 00045 sock.close(); 00046 00047 eth.disconnect(); 00048 00049 while(1) {} 00050 }
Generated on Sat Jul 16 2022 09:38:42 by 1.7.2