davide carboni / Mbed 2 deprecated HTTPClientExample

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HTTPClientExample.cpp Source File

HTTPClientExample.cpp

00001 #include "mbed.h"
00002 #include "EthernetNetIf.h"
00003 #include "HTTPClient.h"
00004 
00005 //EthernetNetIf eth; 
00006 HTTPClient http;
00007 DigitalOut led1(LED1);
00008 DigitalOut led2(LED4);
00009   
00010 int main() {
00011 
00012   printf("Setting up...\n");
00013 
00014   EthernetNetIf eth(
00015   IpAddr(10,0,0,20), //IP Address
00016   IpAddr(255,0,0,0), //Network Mask
00017   IpAddr(10,0,0,1), //Gateway
00018   IpAddr(10,0,0,1)  //DNS
00019    );
00020 
00021 
00022   EthernetErr ethErr = eth.setup();
00023   if(ethErr)
00024   {
00025     printf("Error %d in setup.\n", ethErr);
00026     return -1;
00027   }
00028   printf("Setup OK\n");
00029   
00030   HTTPText txt;
00031   
00032   HTTPResult r = http.get("http://10.0.0.1/", &txt);
00033   if(r==HTTP_OK)
00034   {
00035     printf("GET Result :\"%s\"\n", txt.gets()); 
00036     led1=1;
00037     led2=1;
00038   }
00039   else
00040   {
00041     printf("Error %d\n", r);
00042     led1=0;
00043     led2=1;
00044   }
00045   
00046   while(1)
00047   {
00048     //printf("ciao");
00049   }
00050   
00051   return 0;
00052   
00053 }