Dewant Katare
/
My_ethernet
Prints out ip address of pc in serial terminal like Tera term or Putty
Revision 0:bbe70c857378, committed 2018-03-25
- Comitter:
- dewantkatare
- Date:
- Sun Mar 25 18:57:07 2018 +0000
- Commit message:
- prints out IP address of PC in serial terminal
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed-os.lib | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r bbe70c857378 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Mar 25 18:57:07 2018 +0000 @@ -0,0 +1,38 @@ +#include "mbed.h" +#include "EthernetInterface.h" + +// Network interface +EthernetInterface net; + +// Socket demo +int main() { + // Bring up the ethernet interface + printf("Ethernet socket example\n"); + net.connect(); + + // Show the network address + const char *ip = net.get_ip_address(); + printf("IP address is: %s\n", ip ? ip : "No IP"); + + // Open a socket on the network interface, and create a TCP connection to mbed.org + TCPSocket socket; + socket.open(&net); + socket.connect("developer.mbed.org", 80); + + // Send a simple http request + char sbuffer[] = "GET / HTTP/1.1\r\nHost: developer.mbed.org\r\n\r\n"; + int scount = socket.send(sbuffer, sizeof sbuffer); + printf("sent %d [%.*s]\n", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer); + + // Recieve a simple http response and print out the response line + char rbuffer[64]; + int rcount = socket.recv(rbuffer, sizeof rbuffer); + printf("recv %d [%.*s]\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer); + + // Close the socket to return its memory and bring down the network interface + socket.close(); + + // Bring down the ethernet interface + net.disconnect(); + printf("Done\n"); +}
diff -r 000000000000 -r bbe70c857378 mbed-os.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Sun Mar 25 18:57:07 2018 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#16bac101a6b7b4724023dcf86ece1548e3a23cbf