TCPSocket with STM32F407VET6 board. For more details see https://os.mbed.com/users/hudakz/code/STM32F407VET6_Hello/

Dependencies:   EthernetInterface mbed-rtos mbed

Committer:
hudakz
Date:
Mon Apr 02 19:31:31 2018 +0000
Revision:
0:93bc6de01cd8
Initial issue.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:93bc6de01cd8 1 // Blinky demo for the STM32F407VET6 boards.
hudakz 0:93bc6de01cd8 2 // See http://wiki.stm32duino.com/index.php?title=STM32F407.
hudakz 0:93bc6de01cd8 3 //
hudakz 0:93bc6de01cd8 4 // Use "Seed Arch Max" as target platform for the online compiler.
hudakz 0:93bc6de01cd8 5
hudakz 0:93bc6de01cd8 6 #include "mbed.h"
hudakz 0:93bc6de01cd8 7 #include "EthernetInterface.h"
hudakz 0:93bc6de01cd8 8
hudakz 0:93bc6de01cd8 9 int main() {
hudakz 0:93bc6de01cd8 10 EthernetInterface eth;
hudakz 0:93bc6de01cd8 11 eth.init(); //Use DHCP
hudakz 0:93bc6de01cd8 12 eth.connect();
hudakz 0:93bc6de01cd8 13 printf("IP Address is %s\n", eth.getIPAddress());
hudakz 0:93bc6de01cd8 14
hudakz 0:93bc6de01cd8 15 TCPSocketConnection sock;
hudakz 0:93bc6de01cd8 16 sock.connect("httpbin.org", 80);
hudakz 0:93bc6de01cd8 17
hudakz 0:93bc6de01cd8 18 char http_cmd[] = "GET /get?helloworld HTTP/1.0\r\n\r\n";
hudakz 0:93bc6de01cd8 19 sock.send_all(http_cmd, sizeof(http_cmd)-1);
hudakz 0:93bc6de01cd8 20
hudakz 0:93bc6de01cd8 21 char buffer[300];
hudakz 0:93bc6de01cd8 22 int ret;
hudakz 0:93bc6de01cd8 23 while (true) {
hudakz 0:93bc6de01cd8 24 ret = sock.receive(buffer, sizeof(buffer)-1);
hudakz 0:93bc6de01cd8 25 if (ret <= 0)
hudakz 0:93bc6de01cd8 26 break;
hudakz 0:93bc6de01cd8 27 buffer[ret] = '\0';
hudakz 0:93bc6de01cd8 28 printf("Received %d chars from server:\n%s\n", ret, buffer);
hudakz 0:93bc6de01cd8 29 }
hudakz 0:93bc6de01cd8 30
hudakz 0:93bc6de01cd8 31 sock.close();
hudakz 0:93bc6de01cd8 32
hudakz 0:93bc6de01cd8 33 eth.disconnect();
hudakz 0:93bc6de01cd8 34
hudakz 0:93bc6de01cd8 35 while(1) {}
hudakz 0:93bc6de01cd8 36 }