![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
test ethernet
Dependencies: EthernetInterface HTTPClient MbedJSONValue mbed-rtos mbed
main.cpp
- Committer:
- Sytten
- Date:
- 2017-10-20
- Revision:
- 0:1de2607f659c
File content as of revision 0:1de2607f659c:
#include "mbed.h" #include "EthernetInterface.h" #include "HTTPClient.h" int main() { // Ethernet setup EthernetInterface eth; eth.init(); //Use DHCP eth.connect(); printf("IP Address is %s\n", eth.getIPAddress()); // Http client HTTPClient http; int i = 0; while(i < 100) { 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) { ret = sock.receive(buffer, sizeof(buffer)-1); if (ret <= 0) break; buffer[ret] = '\0'; printf("Received %d chars from server:\n%s\n", ret, buffer); } sock.close(); i++; wait(1); } eth.disconnect(); while(1) {} }