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

Dependencies:   NetServices mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "HTTPClient.h"
00003 #include "EthernetNetIf.h"
00004 
00005 DigitalOut led(LED1);
00006 
00007 EthernetNetIf eth;
00008 
00009                
00010 LocalFileSystem local("local");
00011 /**
00012  * Request a google search for HelloWorld and display the first 2000 characters 
00013  * of the page source on the serial terminal.
00014  */
00015 int main(void) {
00016 EthernetNetIf eth(        // Brings up the device with static IP address and domain name.
00017                 IpAddr(192,168,0,123),   // IPv4 address
00018                 IpAddr(255,255,255,0),   // netmask
00019                 IpAddr(192,168,0,1),     // default gateway
00020                 IpAddr(192,168,0,1));    // dns server
00021   int ethErr = eth.setup();        // Brings up the device with static IP address and domain name.
00022   if(ethErr)
00023   {
00024     printf("Error %d in setup.\n", ethErr);
00025     return -1;
00026   }
00027 
00028   HTTPClient http;
00029   HTTPText txt;
00030   
00031   HTTPResult r = http.get("http://mbed.org/media/uploads/donatien/hello.txt", &txt);
00032   if(r==HTTP_OK)
00033   {
00034     printf("Result :\"%s\"\n", txt.gets()); 
00035   }
00036   else
00037   {
00038     printf("Error %d\n", r);
00039   }
00040   
00041   // Work is done!
00042   while(1) {
00043     led = !led;
00044     wait(0.2);
00045   }
00046 }