HTTPServer mit RPC, SimpleHandler und Zugriff auf SD Karte
Dependencies: EthernetInterface HttpServer SDFileSystem mbed-rpc mbed-rtos mbed
Fork of HttpServerSample by
Revision 7:8a319a112fba, committed 2015-01-18
- Comitter:
- marcel1691
- Date:
- Sun Jan 18 14:39:15 2015 +0000
- Parent:
- 6:c9c7ffa0594e
- Commit message:
- AnalogInput eingebaut
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r c9c7ffa0594e -r 8a319a112fba main.cpp --- a/main.cpp Wed Jan 14 18:52:15 2015 +0000 +++ b/main.cpp Sun Jan 18 14:39:15 2015 +0000 @@ -14,6 +14,29 @@ //LocalFileSystem local("local"); SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "local"); +static float value = 20; + +class AnalogInHandler : public SimpleHandler +{ +public: + AnalogInHandler(const char* rootPath, const char* path, TCPSocketConnection* pTCPSocketConnection) : SimpleHandler(rootPath, path, pTCPSocketConnection) { } + virtual ~AnalogInHandler() {} + +//protected: + static inline HTTPRequestHandler* inst(const char* rootPath, const char* path, TCPSocketConnection* pTCPSocketConnection) { return new AnalogInHandler(rootPath, path, pTCPSocketConnection); } //if we ever could do static virtual functions, this would be one + + virtual void doGet() + { + char buf[20]; + sprintf( buf, "%f", value ); + value += 0.01; + setContentLen( strlen(buf) ); + respHeaders()["Connection"] = "close"; + writeData(buf, strlen(buf)); + } + +}; + void aliveState(void const *args) { while (true) @@ -41,11 +64,18 @@ { printf("********* PROGRAM START ***********\r\n"); Thread thread(aliveState); + + // LED's RPC::add_rpc_class<RpcDigitalOut>(); RPC::construct<RpcDigitalOut, PinName, const char*>(PTC3, "led1"); RPC::construct<RpcDigitalOut, PinName, const char*>(PTC2, "led2"); RPC::construct<RpcDigitalOut, PinName, const char*>(PTA2, "led3"); + + // Sensoren bringt Linkfehler + //RPC::add_rpc_class<RpcAnalogIn>(); + //RPC::construct<RpcAnalogIn, PinName, const char*>(PTB3, "s1"); //RPCFunction rpcFunc(LcdWrite, "LcdWrite"); //ADD Here!! + printf("EthernetInterface Setting up...\r\n"); if(eth.init()!=0) @@ -67,9 +97,10 @@ printf("\nList all directories/files /local.\n"); do_list("/local"); - HTTPServerAddHandler<SimpleHandler>("/hello"); //Default handler - FSHandler::mount("/local", "/"); - HTTPServerAddHandler<FSHandler>("/"); + //HTTPServerAddHandler<SimpleHandler>("/hello"); //Default handler + HTTPServerAddHandler<AnalogInHandler>("/analogIn"); //Default handler + //FSHandler::mount("/local", "/"); + //HTTPServerAddHandler<FSHandler>("/"); HTTPServerAddHandler<RPCHandler>("/rpc"); HTTPServerStart(80); }