
An example HTTP Server using new Ethernet Interface and localfilesystem.
Dependencies: EthernetInterface HttpServer mbed-rpc mbed-rtos mbed
Fork of giken9_HTMLServer_Sample by
main.cpp@5:d98cf6df5187, 2014-12-23 (annotated)
- Committer:
- mkilivan
- Date:
- Tue Dec 23 19:38:53 2014 +0000
- Revision:
- 5:d98cf6df5187
- Parent:
- 3:f0c16cc3a4ef
- Child:
- 6:116ca781e161
Removed lcd library and code tidy up
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yueee_yt | 0:7766f6712673 | 1 | //#define DNS_SERVER_ADDRESS(ipaddr) (ip4_addr_set_u32(ipaddr, ipaddr_addr("208.67.222.222"))) /* resolver1.opendns.com */ |
yueee_yt | 0:7766f6712673 | 2 | #include "mbed.h" |
yueee_yt | 0:7766f6712673 | 3 | #include "rtos.h" |
yueee_yt | 0:7766f6712673 | 4 | #include "EthernetInterface.h" |
yueee_yt | 0:7766f6712673 | 5 | #include "HTTPServer.h" |
yueee_yt | 0:7766f6712673 | 6 | #include "mbed_rpc.h" |
yueee_yt | 0:7766f6712673 | 7 | |
yueee_yt | 0:7766f6712673 | 8 | EthernetInterface eth; |
yueee_yt | 0:7766f6712673 | 9 | LocalFileSystem local("local"); |
yueee_yt | 0:7766f6712673 | 10 | DigitalOut led4(LED4); |
yueee_yt | 0:7766f6712673 | 11 | |
yueee_yt | 0:7766f6712673 | 12 | void LcdWrite(Arguments* arg, Reply* r);void LcdWrite(Arguments* arg, Reply* r); |
yueee_yt | 0:7766f6712673 | 13 | void aliveState(void const *args) |
yueee_yt | 0:7766f6712673 | 14 | { |
yueee_yt | 0:7766f6712673 | 15 | while (true) { |
yueee_yt | 0:7766f6712673 | 16 | led4 = !led4; |
yueee_yt | 0:7766f6712673 | 17 | Thread::wait(1000); |
yueee_yt | 0:7766f6712673 | 18 | } |
yueee_yt | 0:7766f6712673 | 19 | } |
yueee_yt | 0:7766f6712673 | 20 | int main() |
yueee_yt | 0:7766f6712673 | 21 | { |
yueee_yt | 0:7766f6712673 | 22 | printf("********* PROGRAM START ***********\r\n"); |
yueee_yt | 0:7766f6712673 | 23 | Thread thread(aliveState); |
yueee_yt | 0:7766f6712673 | 24 | |
yueee_yt | 0:7766f6712673 | 25 | printf("********* RPC Initialize ***********\r\n"); |
yueee_yt | 0:7766f6712673 | 26 | RPC::add_rpc_class<RpcDigitalOut>(); |
yueee_yt | 0:7766f6712673 | 27 | RPC::construct<RpcDigitalOut, PinName, const char*>(LED1, "led1"); |
yueee_yt | 0:7766f6712673 | 28 | RPC::construct<RpcDigitalOut, PinName, const char*>(LED2, "led2"); |
yueee_yt | 0:7766f6712673 | 29 | RPC::construct<RpcDigitalOut, PinName, const char*>(LED3, "led3"); |
yueee_yt | 0:7766f6712673 | 30 | RPCFunction rpcFunc(LcdWrite, "LcdWrite"); |
yueee_yt | 0:7766f6712673 | 31 | |
yueee_yt | 0:7766f6712673 | 32 | printf("EthernetInterface Setting up...\r\n"); |
yueee_yt | 0:7766f6712673 | 33 | if(eth.init()!=0) { //for DHCP Server |
yueee_yt | 0:7766f6712673 | 34 | printf("EthernetInterface Initialize Error \r\n"); |
yueee_yt | 0:7766f6712673 | 35 | return -1; |
yueee_yt | 0:7766f6712673 | 36 | } |
yueee_yt | 0:7766f6712673 | 37 | if(eth.connect()!=0) { |
yueee_yt | 0:7766f6712673 | 38 | printf("EthernetInterface Connect Error \r\n"); |
yueee_yt | 0:7766f6712673 | 39 | return -1; |
yueee_yt | 0:7766f6712673 | 40 | } |
yueee_yt | 0:7766f6712673 | 41 | printf("IP Address is %s\r\n", eth.getIPAddress()); |
yueee_yt | 0:7766f6712673 | 42 | printf("NetMask is %s\r\n", eth.getNetworkMask()); |
yueee_yt | 0:7766f6712673 | 43 | printf("Gateway Address is %s\r\n", eth.getGateway()); |
yueee_yt | 0:7766f6712673 | 44 | printf("Ethernet Setup OK\r\n"); |
yueee_yt | 0:7766f6712673 | 45 | |
yueee_yt | 0:7766f6712673 | 46 | FSHandler::mount("/local","/"); |
yueee_yt | 0:7766f6712673 | 47 | |
yueee_yt | 0:7766f6712673 | 48 | HTTPServerStart(80); |
yueee_yt | 0:7766f6712673 | 49 | } |