HttpServerExample.cpp

Committer:
TP
Date:
2011-06-13
Revision:
0:a4a5adb694e5
Child:
1:fae5b4e9987e

File content as of revision 0:a4a5adb694e5:

#include "mbed.h"
#include "EthernetNetIf.h"
#include "HttpServer.h"
#include "TextLCD.h"

DigitalOut led1(LED1, "led1");
DigitalOut led2(LED2, "led2");
DigitalOut led3(LED3, "led3");
DigitalOut led4(LED4, "led4");

LocalFileSystem fs("webfs");

DigitalOut rw(p25);
TextLCD lcd(p26,p24,p23,p22,p20,p19, TextLCD::LCD20x4);


EthernetNetIf eth;  
HttpServer svr;

int main() {
  rw = 0;

  Base::add_rpc_class<DigitalOut>();
  lcd.cls();
  lcd.printf("Setting up..");
  EthernetErr ethErr = eth.setup();
  if(ethErr)
  {
    lcd.printf("Error %d\n", ethErr);
    return -1;
  }
  lcd.printf("OK\n");
  
  svr.addHandler<SimpleHandler>("/hello");
  svr.addHandler<RpcHandler>("/rpc");
  svr.addHandler<FSHandler>(""); //Default handler
  //Example : Access to mbed.htm : http://a.b.c.d/webfs/demo.htm
  //Zet demo.htm in de root van de mbed.
  svr.bind(80);
  
  lcd.printf("Listening..see:\nhttp://a.b.c.d/webfs/demo.htm");
    
  Timer tm;
  tm.start();
  //Listen indefinitely
  while(true)
  {
    Net::poll();
    if(tm.read()>.5)
    {
      led1=!led1; //Show that we are alive
      tm.start();
    }
  }
  
  return 0;

}