Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetNetIf HTTPServer RPCInterface TextLCD mbed
Fork of RPC_HTTP by
HTTPServerExample.cpp
00001 #include "mbed.h" 00002 #include "EthernetNetIf.h" 00003 #include "HTTPServer.h" 00004 #include "RPCVariable.h" 00005 #include "RPCFunction.h" 00006 00007 BusOut dac(p21,p22,p23,p24,p25,p26,p27,p28); 00008 //Create the variables 00009 int i=10; 00010 RPCVariable<int> rpc_i(&i, "i"); 00011 //Define the LED´s 00012 DigitalOut led1(LED1, "led1"); 00013 DigitalOut led2(LED2, "led2"); 00014 DigitalOut led3(LED3, "led3"); 00015 LocalFileSystem fs("webfs"); 00016 00017 EthernetNetIf eth(IpAddr(192,168,1,20),IpAddr(255,255,255,0),IpAddr(192,168,1,1),IpAddr(192,168,1,1)); 00018 HTTPServer svr; 00019 00020 int main() 00021 { 00022 Base::add_rpc_class<AnalogIn>(); 00023 Base::add_rpc_class<AnalogOut>(); 00024 Base::add_rpc_class<DigitalIn>(); 00025 Base::add_rpc_class<DigitalOut>(); 00026 Base::add_rpc_class<DigitalInOut>(); 00027 Base::add_rpc_class<PwmOut>(); 00028 Base::add_rpc_class<Timer>(); 00029 Base::add_rpc_class<BusOut>(); 00030 Base::add_rpc_class<BusIn>(); 00031 Base::add_rpc_class<BusInOut>(); 00032 Base::add_rpc_class<Serial>(); 00033 00034 00035 printf("Setting up...\n\r"); 00036 EthernetErr ethErr = eth.setup(); 00037 if(ethErr) { 00038 printf("Error %d in setup.\n\r", ethErr); 00039 return -1; 00040 } 00041 printf("Setup OK\n\r"); 00042 00043 FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path 00044 FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path 00045 00046 svr.addHandler<SimpleHandler>("/hello"); 00047 svr.addHandler<RPCHandler>("/rpc"); 00048 svr.addHandler<FSHandler>("/files"); 00049 svr.addHandler<FSHandler>("/"); //Default handler 00050 //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm 00051 00052 svr.bind(80); 00053 00054 printf("Listening...\n\r"); 00055 00056 Timer tm; 00057 tm.start(); 00058 //Listen indefinitely 00059 while(true) { 00060 Net::poll(); 00061 if(tm.read()>.1) { 00062 led1=!led1; //Show that we are alive 00063 printf("Working...\n\r"); 00064 dac = i; 00065 00066 printf("i=%d",i); //c = 'a'; 00067 00068 tm.start(); 00069 } 00070 } 00071 }
Generated on Tue Jul 19 2022 03:50:08 by
