ECE 4180 Lab 2 Part 4
Dependencies: EthernetInterface mbed-rtos mbed
Fork of TCPSocket_HelloWorld by
Diff: main.cpp
- Revision:
- 15:bf59021c6f53
- Parent:
- 11:59dcefdda506
diff -r 72be2b8b7f24 -r bf59021c6f53 main.cpp --- a/main.cpp Wed May 14 15:07:26 2014 +0000 +++ b/main.cpp Tue Oct 09 00:48:43 2018 +0000 @@ -1,18 +1,30 @@ #include "mbed.h" #include "EthernetInterface.h" -int main() { +Serial pc(USBTX, USBRX); + +int main() +{ + pc.printf("Hi! "); + + char mac[6]; + mbed_mac_address(mac); + pc.printf("mbed MAC address is %02x:%02x:%02x:%02x:%02x:%02x\n\r", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + + pc.printf("1"); EthernetInterface eth; + pc.printf("2"); eth.init(); //Use DHCP + pc.printf("3"); eth.connect(); - printf("IP Address is %s\n", eth.getIPAddress()); - + pc.printf("IP Address is %s\n", eth.getIPAddress()); + TCPSocketConnection sock; sock.connect("mbed.org", 80); - + char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n"; sock.send_all(http_cmd, sizeof(http_cmd)-1); - + char buffer[300]; int ret; while (true) { @@ -20,12 +32,12 @@ if (ret <= 0) break; buffer[ret] = '\0'; - printf("Received %d chars from server:\n%s\n", ret, buffer); + pc.printf("Received %d chars from server:\n%s\n", ret, buffer); } - + sock.close(); - + eth.disconnect(); - + while(1) {} }