
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@3:f0c16cc3a4ef, 2014-12-23 (annotated)
- Committer:
- mkilivan
- Date:
- Tue Dec 23 18:40:55 2014 +0000
- Revision:
- 3:f0c16cc3a4ef
- Parent:
- 0:7766f6712673
- Child:
- 5:d98cf6df5187
Used library links instead of cloned files
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" |
mkilivan | 3:f0c16cc3a4ef | 7 | #include "C12832.h" |
mkilivan | 3:f0c16cc3a4ef | 8 | |
mkilivan | 3:f0c16cc3a4ef | 9 | |
mkilivan | 3:f0c16cc3a4ef | 10 | C12832 lcd(p5, p7, p6, p8, p11); |
yueee_yt | 0:7766f6712673 | 11 | |
yueee_yt | 0:7766f6712673 | 12 | EthernetInterface eth; |
yueee_yt | 0:7766f6712673 | 13 | LocalFileSystem local("local"); |
yueee_yt | 0:7766f6712673 | 14 | DigitalOut led4(LED4); |
yueee_yt | 0:7766f6712673 | 15 | //DigitalOut led1(LED1); |
yueee_yt | 0:7766f6712673 | 16 | |
yueee_yt | 0:7766f6712673 | 17 | void LcdWrite(Arguments* arg, Reply* r);void LcdWrite(Arguments* arg, Reply* r); |
yueee_yt | 0:7766f6712673 | 18 | void aliveState(void const *args) |
yueee_yt | 0:7766f6712673 | 19 | { |
yueee_yt | 0:7766f6712673 | 20 | while (true) { |
yueee_yt | 0:7766f6712673 | 21 | led4 = !led4; |
yueee_yt | 0:7766f6712673 | 22 | Thread::wait(1000); |
yueee_yt | 0:7766f6712673 | 23 | } |
yueee_yt | 0:7766f6712673 | 24 | } |
yueee_yt | 0:7766f6712673 | 25 | int main() |
yueee_yt | 0:7766f6712673 | 26 | { |
yueee_yt | 0:7766f6712673 | 27 | printf("********* PROGRAM START ***********\r\n"); |
yueee_yt | 0:7766f6712673 | 28 | Thread thread(aliveState); |
yueee_yt | 0:7766f6712673 | 29 | lcd.cls(); |
yueee_yt | 0:7766f6712673 | 30 | lcd.locate(0,0); |
yueee_yt | 0:7766f6712673 | 31 | |
yueee_yt | 0:7766f6712673 | 32 | printf("********* RPC Initialize ***********\r\n"); |
yueee_yt | 0:7766f6712673 | 33 | RPC::add_rpc_class<RpcDigitalOut>(); |
yueee_yt | 0:7766f6712673 | 34 | RPC::construct<RpcDigitalOut, PinName, const char*>(LED1, "led1"); |
yueee_yt | 0:7766f6712673 | 35 | RPC::construct<RpcDigitalOut, PinName, const char*>(LED2, "led2"); |
yueee_yt | 0:7766f6712673 | 36 | RPC::construct<RpcDigitalOut, PinName, const char*>(LED3, "led3"); |
yueee_yt | 0:7766f6712673 | 37 | RPCFunction rpcFunc(LcdWrite, "LcdWrite"); |
yueee_yt | 0:7766f6712673 | 38 | |
yueee_yt | 0:7766f6712673 | 39 | printf("EthernetInterface Setting up...\r\n"); |
yueee_yt | 0:7766f6712673 | 40 | if(eth.init()!=0) { //for DHCP Server |
yueee_yt | 0:7766f6712673 | 41 | // if(eth.init("133.11.168.23","255.255.255.0","133.11.168.1")!=0) { //for Static IP Address |
yueee_yt | 0:7766f6712673 | 42 | printf("EthernetInterface Initialize Error \r\n"); |
yueee_yt | 0:7766f6712673 | 43 | return -1; |
yueee_yt | 0:7766f6712673 | 44 | } |
yueee_yt | 0:7766f6712673 | 45 | if(eth.connect()!=0) { |
yueee_yt | 0:7766f6712673 | 46 | printf("EthernetInterface Connect Error \r\n"); |
yueee_yt | 0:7766f6712673 | 47 | return -1; |
yueee_yt | 0:7766f6712673 | 48 | } |
yueee_yt | 0:7766f6712673 | 49 | printf("IP Address is %s\r\n", eth.getIPAddress()); |
yueee_yt | 0:7766f6712673 | 50 | printf("NetMask is %s\r\n", eth.getNetworkMask()); |
yueee_yt | 0:7766f6712673 | 51 | printf("Gateway Address is %s\r\n", eth.getGateway()); |
yueee_yt | 0:7766f6712673 | 52 | printf("Ethernet Setup OK\r\n"); |
yueee_yt | 0:7766f6712673 | 53 | |
yueee_yt | 0:7766f6712673 | 54 | FSHandler::mount("/local","/"); |
mkilivan | 3:f0c16cc3a4ef | 55 | //FSHandler::mount("/local/css","css/"); |
yueee_yt | 0:7766f6712673 | 56 | |
yueee_yt | 0:7766f6712673 | 57 | lcd.locate(0,0); |
yueee_yt | 0:7766f6712673 | 58 | lcd.printf("%s",eth.getIPAddress()); |
yueee_yt | 0:7766f6712673 | 59 | HTTPServerStart(80); |
yueee_yt | 0:7766f6712673 | 60 | } |
yueee_yt | 0:7766f6712673 | 61 | |
yueee_yt | 0:7766f6712673 | 62 | void LcdWrite(Arguments* arg, Reply* r) //RPC Call |
yueee_yt | 0:7766f6712673 | 63 | { |
yueee_yt | 0:7766f6712673 | 64 | lcd.locate(0,1); |
yueee_yt | 0:7766f6712673 | 65 | lcd.printf("%s",arg->argv[0]); |
yueee_yt | 0:7766f6712673 | 66 | } |
yueee_yt | 0:7766f6712673 | 67 |