TCP Socket Hello World with Ethernet
Dependencies: EthernetInterface IAP mbed-rtos mbed
Fork of TCPSocket_HelloWorld by
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 #include "IAP.h" 00004 00005 00006 int main() { 00007 printf("-------- Arch Pro Ethernet -----------\n"); 00008 EthernetInterface eth; 00009 eth.init(); //Use DHCP 00010 eth.connect(); 00011 printf("MAC Address is %s\n", eth.getMACAddress()); 00012 printf("IP Address is %s\n", eth.getIPAddress()); 00013 00014 TCPSocketConnection sock; 00015 sock.connect("httpbin.org", 80); 00016 00017 char http_cmd[] = "GET /get?helloworld HTTP/1.0\r\n\r\n"; 00018 sock.send_all(http_cmd, sizeof(http_cmd)-1); 00019 00020 char buffer[300]; 00021 int ret; 00022 while (true) { 00023 ret = sock.receive(buffer, sizeof(buffer)-1); 00024 if (ret <= 0) 00025 break; 00026 buffer[ret] = '\0'; 00027 printf("Received %d chars from server:\n%s\n", ret, buffer); 00028 } 00029 00030 sock.close(); 00031 00032 eth.disconnect(); 00033 00034 while(1) {} 00035 } 00036 00037 extern "C" void mbed_mac_address(char *mac) { 00038 IAP iap; 00039 00040 int *serial_number_array = iap.read_serial(); // 4 int 00041 char *ptr = (char *)serial_number_array; 00042 00043 mac[0] = ptr[0]; 00044 mac[1] = ptr[1]; 00045 mac[2] = ptr[2]; 00046 mac[3] = ptr[3]; 00047 mac[4] = ptr[4]; 00048 mac[5] = ptr[5]; 00049 }; 00050 00051
Generated on Wed Jul 13 2022 18:56:51 by
1.7.2
