エレキジャックweb mbed入門用です。 index.htmなどのファイルアクセス可能なHPPTServerプログラムです。cookbook HTTPServerのものと同等です。

Dependencies:   EthernetNetIf mbed HTTPServer

Committer:
takeuchi
Date:
Sun Oct 24 10:57:16 2010 +0000
Revision:
0:600610f4821a

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
takeuchi 0:600610f4821a 1 // Ethernet Test
takeuchi 0:600610f4821a 2 // HTTPServer index.htm
takeuchi 0:600610f4821a 3 #include "mbed.h"
takeuchi 0:600610f4821a 4 #include "EthernetNetIf.h"
takeuchi 0:600610f4821a 5 #include "HTTPServer.h"
takeuchi 0:600610f4821a 6
takeuchi 0:600610f4821a 7 EthernetNetIf eth;
takeuchi 0:600610f4821a 8 HTTPServer svr;
takeuchi 0:600610f4821a 9
takeuchi 0:600610f4821a 10 DigitalOut led1(LED1, "led1");
takeuchi 0:600610f4821a 11 DigitalOut led2(LED2, "led2");
takeuchi 0:600610f4821a 12 DigitalOut led3(LED3, "led3");
takeuchi 0:600610f4821a 13 DigitalOut led4(LED4, "led4");
takeuchi 0:600610f4821a 14
takeuchi 0:600610f4821a 15 LocalFileSystem fs("webfs");
takeuchi 0:600610f4821a 16
takeuchi 0:600610f4821a 17 int main() {
takeuchi 0:600610f4821a 18 Base::add_rpc_class<DigitalOut>();
takeuchi 0:600610f4821a 19 Base::add_rpc_class<AnalogIn>();
takeuchi 0:600610f4821a 20 Base::add_rpc_class<PwmOut>();
takeuchi 0:600610f4821a 21
takeuchi 0:600610f4821a 22 printf("Setting up...\n");
takeuchi 0:600610f4821a 23 EthernetErr ethErr = eth.setup();
takeuchi 0:600610f4821a 24 if(ethErr)
takeuchi 0:600610f4821a 25 {
takeuchi 0:600610f4821a 26 printf("Error %d in setup.\n", ethErr);
takeuchi 0:600610f4821a 27 return -1;
takeuchi 0:600610f4821a 28 }
takeuchi 0:600610f4821a 29 printf("Setup OK\n");
takeuchi 0:600610f4821a 30
takeuchi 0:600610f4821a 31 FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path
takeuchi 0:600610f4821a 32 FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path
takeuchi 0:600610f4821a 33 svr.addHandler<SimpleHandler>("/hello");
takeuchi 0:600610f4821a 34 svr.addHandler<RPCHandler>("/rpc");
takeuchi 0:600610f4821a 35 svr.addHandler<FSHandler>("/files");
takeuchi 0:600610f4821a 36 svr.addHandler<FSHandler>("/"); //Default handler
takeuchi 0:600610f4821a 37 //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm
takeuchi 0:600610f4821a 38
takeuchi 0:600610f4821a 39 svr.bind(80);
takeuchi 0:600610f4821a 40
takeuchi 0:600610f4821a 41 printf("Listening...\n");
takeuchi 0:600610f4821a 42
takeuchi 0:600610f4821a 43 Timer tm;
takeuchi 0:600610f4821a 44 tm.start();
takeuchi 0:600610f4821a 45 //Listen indefinitely
takeuchi 0:600610f4821a 46 while(true)
takeuchi 0:600610f4821a 47 {
takeuchi 0:600610f4821a 48 Net::poll();
takeuchi 0:600610f4821a 49 if(tm.read()>.5)
takeuchi 0:600610f4821a 50 {
takeuchi 0:600610f4821a 51 led1=!led1; //Show that we are alive
takeuchi 0:600610f4821a 52 tm.start();
takeuchi 0:600610f4821a 53 }
takeuchi 0:600610f4821a 54 }
takeuchi 0:600610f4821a 55
takeuchi 0:600610f4821a 56 return 0;
takeuchi 0:600610f4821a 57 }