Working sample program from the [[http://mbed.org/cookbook/Cool-Components-Workshop-Board|cool components workshop board]] page.

Dependencies:   NetServices mbed

Committer:
hlipka
Date:
Wed Jan 19 20:39:50 2011 +0000
Revision:
0:f0d3d3f90a84
initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 0:f0d3d3f90a84 1 #include "mbed.h"
hlipka 0:f0d3d3f90a84 2 #include "HTTPClient.h"
hlipka 0:f0d3d3f90a84 3 #include "EthernetNetIf.h"
hlipka 0:f0d3d3f90a84 4
hlipka 0:f0d3d3f90a84 5 DigitalOut led(LED1);
hlipka 0:f0d3d3f90a84 6
hlipka 0:f0d3d3f90a84 7 EthernetNetIf eth;
hlipka 0:f0d3d3f90a84 8
hlipka 0:f0d3d3f90a84 9
hlipka 0:f0d3d3f90a84 10 LocalFileSystem local("local");
hlipka 0:f0d3d3f90a84 11 /**
hlipka 0:f0d3d3f90a84 12 * Request a google search for HelloWorld and display the first 2000 characters
hlipka 0:f0d3d3f90a84 13 * of the page source on the serial terminal.
hlipka 0:f0d3d3f90a84 14 */
hlipka 0:f0d3d3f90a84 15 int main(void) {
hlipka 0:f0d3d3f90a84 16 EthernetNetIf eth( // Brings up the device with static IP address and domain name.
hlipka 0:f0d3d3f90a84 17 IpAddr(192,168,0,123), // IPv4 address
hlipka 0:f0d3d3f90a84 18 IpAddr(255,255,255,0), // netmask
hlipka 0:f0d3d3f90a84 19 IpAddr(192,168,0,1), // default gateway
hlipka 0:f0d3d3f90a84 20 IpAddr(192,168,0,1)); // dns server
hlipka 0:f0d3d3f90a84 21 int ethErr = eth.setup(); // Brings up the device with static IP address and domain name.
hlipka 0:f0d3d3f90a84 22 if(ethErr)
hlipka 0:f0d3d3f90a84 23 {
hlipka 0:f0d3d3f90a84 24 printf("Error %d in setup.\n", ethErr);
hlipka 0:f0d3d3f90a84 25 return -1;
hlipka 0:f0d3d3f90a84 26 }
hlipka 0:f0d3d3f90a84 27
hlipka 0:f0d3d3f90a84 28 HTTPClient http;
hlipka 0:f0d3d3f90a84 29 HTTPText txt;
hlipka 0:f0d3d3f90a84 30
hlipka 0:f0d3d3f90a84 31 HTTPResult r = http.get("http://mbed.org/media/uploads/donatien/hello.txt", &txt);
hlipka 0:f0d3d3f90a84 32 if(r==HTTP_OK)
hlipka 0:f0d3d3f90a84 33 {
hlipka 0:f0d3d3f90a84 34 printf("Result :\"%s\"\n", txt.gets());
hlipka 0:f0d3d3f90a84 35 }
hlipka 0:f0d3d3f90a84 36 else
hlipka 0:f0d3d3f90a84 37 {
hlipka 0:f0d3d3f90a84 38 printf("Error %d\n", r);
hlipka 0:f0d3d3f90a84 39 }
hlipka 0:f0d3d3f90a84 40
hlipka 0:f0d3d3f90a84 41 // Work is done!
hlipka 0:f0d3d3f90a84 42 while(1) {
hlipka 0:f0d3d3f90a84 43 led = !led;
hlipka 0:f0d3d3f90a84 44 wait(0.2);
hlipka 0:f0d3d3f90a84 45 }
hlipka 0:f0d3d3f90a84 46 }