~
Dependencies: 4DGL-uLCD-SE SDFileSystem
Diff: main.cpp
- Revision:
- 3:99acbebbed6c
- Parent:
- 2:20b2a7eb4bd8
- Child:
- 4:f5bc5d9a790b
diff -r 20b2a7eb4bd8 -r 99acbebbed6c main.cpp --- a/main.cpp Fri Sep 16 03:30:17 2016 +0000 +++ b/main.cpp Fri Sep 23 19:34:38 2016 +0000 @@ -33,4 +33,37 @@ led4 = (ain > 0.8f) ? 1 : 0; wait(.01); } + + /* part 5 + // demo from https://docs.mbed.com/docs/mbed-os-api-reference/en/5.1/APIs/communication/network_sockets/ + + printf("Example network-socket HTTP client\n"); + + // Brings up the network interface + eth.connect(); + const char *ip = eth.get_ip_address(); + const char *mac = eth.get_mac_address(); + printf("IP address is: %s\n", ip ? ip : "No IP"); + printf("MAC address is: %s\n", mac ? mac : "No MAC"); + + // Open a socket on the network interface, and create a TCP connection to mbed.org + socket.open(ð); + 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]\r\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]\r\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer); + + // Close the socket to return its memory and bring down the network interface + socket.close(); + eth.disconnect(); + + printf("Done\n"); + */ } \ No newline at end of file