Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface mbed-rtos mbed
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 #include "TCPSocketConnection.h" 00004 00005 EthernetInterface eth; 00006 RawSerial pc(USBTX, USBRX); // tx, rx 00007 00008 int main() 00009 { 00010 pc.baud(9600); 00011 eth.init(); //Use DHCP 00012 eth.connect(); 00013 printf("IP Address is %s \n\r", eth.getIPAddress()); 00014 TCPSocketConnection socket; 00015 00016 socket.connect("httpbin.org", 80); 00017 00018 char http_cmd[] = "GET /get?helloworld HTTP/1.0\r\n\r\n"; 00019 socket.send_all(http_cmd, sizeof(http_cmd)-1); 00020 00021 char buffer[300]; 00022 int ret; 00023 while (true) { 00024 ret = socket.receive(buffer, sizeof(buffer)-1); 00025 if (ret <= 0) 00026 break; 00027 buffer[ret] = '\0'; 00028 printf("Received %d chars from server:\n%s\n", ret, buffer); 00029 } 00030 00031 printf("DONE!\n"); 00032 00033 socket.close(); 00034 00035 eth.disconnect(); 00036 00037 while(1) {} 00038 } 00039 extern "C" void mbed_mac_address(char *mac) 00040 { 00041 mac[0] = 0xD4; 00042 mac[1] = 0x3D; 00043 mac[2] = 0x7E; 00044 mac[3] = 0x3C; 00045 mac[4] = 0x7E; 00046 mac[5] = 0x1C; 00047 };
Generated on Mon Jul 18 2022 11:36:07 by
1.7.2