Wiflash demo program

Dependencies:   EthernetInterface mbed-rtos mbed wiflash

Fork of TCPSocket_HelloWorld by mbed official

Committer:
donatien
Date:
Tue Jun 26 14:39:21 2012 +0000
Revision:
0:bb128f0e952f
Child:
1:e2652bd064c6
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:bb128f0e952f 1 #include "mbed.h"
donatien 0:bb128f0e952f 2 #include "EthernetInterface.h"
donatien 0:bb128f0e952f 3
donatien 0:bb128f0e952f 4 int main()
donatien 0:bb128f0e952f 5 {
donatien 0:bb128f0e952f 6 EthernetInterface eth;
donatien 0:bb128f0e952f 7 eth.init(); //Use DHCP
donatien 0:bb128f0e952f 8
donatien 0:bb128f0e952f 9 eth.connect();
donatien 0:bb128f0e952f 10
donatien 0:bb128f0e952f 11 TCPSocket sock;
donatien 0:bb128f0e952f 12 sock.connect("mbed.org", 80);
donatien 0:bb128f0e952f 13
donatien 0:bb128f0e952f 14 const char http_cmd[] = "GET /media/uploads/donatien/hello.txt HTTP/1.1\r\nHost: %s\r\n\r\n";
donatien 0:bb128f0e952f 15 sock.send((std::uint8_t*)http_cmd, sizeof(http_cmd) - 1, 3000);
donatien 0:bb128f0e952f 16
donatien 0:bb128f0e952f 17 char in_buf[256];
donatien 0:bb128f0e952f 18 bool firstIteration = true;
donatien 0:bb128f0e952f 19 int ret;
donatien 0:bb128f0e952f 20 do
donatien 0:bb128f0e952f 21 {
donatien 0:bb128f0e952f 22 ret = sock.receive((std::uint8_t*)in_buf, 255, firstIteration?3000:0);
donatien 0:bb128f0e952f 23 in_buf[ret] = '\0';
donatien 0:bb128f0e952f 24
donatien 0:bb128f0e952f 25 printf("Received %d chars from server: %s\n", ret, in_buf);
donatien 0:bb128f0e952f 26 firstIteration = false;
donatien 0:bb128f0e952f 27 } while( ret > 0 );
donatien 0:bb128f0e952f 28
donatien 0:bb128f0e952f 29 sock.close();
donatien 0:bb128f0e952f 30
donatien 0:bb128f0e952f 31 eth.disconnect();
donatien 0:bb128f0e952f 32
donatien 0:bb128f0e952f 33 while(1) {
donatien 0:bb128f0e952f 34 }
donatien 0:bb128f0e952f 35 }