Michael Walker / Mbed 2 deprecated RPC_HTTP

Dependencies:   EthernetNetIf mbed HTTPServer

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HTTPServerExample.cpp Source File

HTTPServerExample.cpp

00001 /*
00002 Copyright (c) 2010 ARM Ltd
00003  
00004 Permission is hereby granted, free of charge, to any person obtaining a copy
00005 of this software and associated documentation files (the "Software"), to deal
00006 in the Software without restriction, including without limitation the rights
00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008 copies of the Software, and to permit persons to whom the Software is
00009 furnished to do so, subject to the following conditions:
00010  
00011 The above copyright notice and this permission notice shall be included in
00012 all copies or substantial portions of the Software.
00013  
00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020 THE SOFTWARE.
00021 */
00022 #include "mbed.h"
00023 #include "EthernetNetIf.h"
00024 #include "HTTPServer.h"
00025 
00026 DigitalOut led1(LED1, "led1");
00027 DigitalOut led2(LED2, "led2");
00028 DigitalOut led3(LED3, "led3");
00029 DigitalOut led4(LED4, "led4");
00030 
00031 LocalFileSystem fs("webfs");
00032 
00033 EthernetNetIf eth;  
00034 HTTPServer svr;
00035 
00036 int main() {
00037     Base::add_rpc_class<AnalogIn>();
00038     Base::add_rpc_class<AnalogOut>();
00039     Base::add_rpc_class<DigitalIn>();
00040     Base::add_rpc_class<DigitalOut>();
00041     Base::add_rpc_class<DigitalInOut>();
00042     Base::add_rpc_class<PwmOut>();
00043     Base::add_rpc_class<Timer>();
00044     Base::add_rpc_class<BusOut>();
00045     Base::add_rpc_class<BusIn>();
00046     Base::add_rpc_class<BusInOut>();
00047     Base::add_rpc_class<Serial>();
00048 
00049   printf("Setting up...\n");
00050   EthernetErr ethErr = eth.setup();
00051   if(ethErr)
00052   {
00053     printf("Error %d in setup.\n", ethErr);
00054     return -1;
00055   }
00056   printf("Setup OK\n");
00057   
00058   FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path
00059   FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path
00060   
00061   svr.addHandler<SimpleHandler>("/hello");
00062   svr.addHandler<RPCHandler>("/rpc");
00063   svr.addHandler<FSHandler>("/files");
00064   svr.addHandler<FSHandler>("/"); //Default handler
00065   //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm
00066   
00067   svr.bind(80);
00068   
00069   printf("Listening...\n");
00070     
00071   Timer tm;
00072   tm.start();
00073   //Listen indefinitely
00074   while(true)
00075   {
00076     Net::poll();
00077     if(tm.read()>.5)
00078     {
00079       led1=!led1; //Show that we are alive
00080       tm.start();
00081     }
00082   }
00083   
00084   return 0;
00085 
00086 }