HTTP DHCP

Dependencies:   EthernetNetIf HTTPServer RPCInterface TextLCD mbed

Fork of HTTP_server_DHCP by toshio masuda

Committer:
MasudaToshio
Date:
Thu Apr 18 10:01:49 2013 +0000
Revision:
0:af120baf5a2e
Child:
1:89479d6c8b09
HTTP tester

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MasudaToshio 0:af120baf5a2e 1 #include "mbed.h"
MasudaToshio 0:af120baf5a2e 2 #include "TextLCD.h"
MasudaToshio 0:af120baf5a2e 3 #include "EthernetNetIf.h"
MasudaToshio 0:af120baf5a2e 4 #include "HTTPServer.h"
MasudaToshio 0:af120baf5a2e 5 #include "RPCFunction.h" //ADD Here!!
MasudaToshio 0:af120baf5a2e 6 DigitalOut led1(LED1,"led1");
MasudaToshio 0:af120baf5a2e 7 DigitalOut led2(LED2,"led2");
MasudaToshio 0:af120baf5a2e 8 DigitalOut led3(LED3,"led3");
MasudaToshio 0:af120baf5a2e 9 DigitalOut led4(LED4,"led4");
MasudaToshio 0:af120baf5a2e 10
MasudaToshio 0:af120baf5a2e 11 TextLCD lcd(p24, p26, p27, p28, p29, p30);
MasudaToshio 0:af120baf5a2e 12
MasudaToshio 0:af120baf5a2e 13 #if 1
MasudaToshio 0:af120baf5a2e 14 /*
MasudaToshio 0:af120baf5a2e 15 * Use DHCP
MasudaToshio 0:af120baf5a2e 16 */
MasudaToshio 0:af120baf5a2e 17 EthernetNetIf ethif;
MasudaToshio 0:af120baf5a2e 18 #else
MasudaToshio 0:af120baf5a2e 19 /*
MasudaToshio 0:af120baf5a2e 20 * Use "static IP address" (Parameters:IP, Subnet mask, Gateway, DNS)
MasudaToshio 0:af120baf5a2e 21 */
MasudaToshio 0:af120baf5a2e 22 EthernetNetIf ethif(IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx));
MasudaToshio 0:af120baf5a2e 23 #endif
MasudaToshio 0:af120baf5a2e 24
MasudaToshio 0:af120baf5a2e 25 HTTPServer server;
MasudaToshio 0:af120baf5a2e 26 LocalFileSystem local("local");
MasudaToshio 0:af120baf5a2e 27 void LcdWrite(char *input,char *output); //ADD Here!!
MasudaToshio 0:af120baf5a2e 28 RPCFunction rpcFunc(&LcdWrite, "LcdWrite"); //ADD Here!!
MasudaToshio 0:af120baf5a2e 29
MasudaToshio 0:af120baf5a2e 30 int main(void) {
MasudaToshio 0:af120baf5a2e 31
MasudaToshio 0:af120baf5a2e 32 Base::add_rpc_class<DigitalOut>();
MasudaToshio 0:af120baf5a2e 33
MasudaToshio 0:af120baf5a2e 34 lcd.cls();
MasudaToshio 0:af120baf5a2e 35 lcd.locate(0,0);
MasudaToshio 0:af120baf5a2e 36 lcd.printf("Program init.. ");
MasudaToshio 0:af120baf5a2e 37
MasudaToshio 0:af120baf5a2e 38 if (ethif.setup()) {
MasudaToshio 0:af120baf5a2e 39 error("Ethernet setup failed.");
MasudaToshio 0:af120baf5a2e 40 return 1;
MasudaToshio 0:af120baf5a2e 41 }
MasudaToshio 0:af120baf5a2e 42 IpAddr ethIp=ethif.getIp();
MasudaToshio 0:af120baf5a2e 43
MasudaToshio 0:af120baf5a2e 44 lcd.locate(0,1);
MasudaToshio 0:af120baf5a2e 45 lcd.printf("%d.%d.%d.%d", ethIp[0], ethIp[1], ethIp[2], ethIp[3]);
MasudaToshio 0:af120baf5a2e 46 led1=1;
MasudaToshio 0:af120baf5a2e 47 wait(1);
MasudaToshio 0:af120baf5a2e 48 server.addHandler<SimpleHandler>("/hello");
MasudaToshio 0:af120baf5a2e 49 server.addHandler<RPCHandler>("/rpc");
MasudaToshio 0:af120baf5a2e 50 FSHandler::mount("/local", "/");
MasudaToshio 0:af120baf5a2e 51 server.addHandler<FSHandler>("/");
MasudaToshio 0:af120baf5a2e 52 server.bind(80);
MasudaToshio 0:af120baf5a2e 53 while (1) {
MasudaToshio 0:af120baf5a2e 54 Net::poll();
MasudaToshio 0:af120baf5a2e 55 }
MasudaToshio 0:af120baf5a2e 56 return 0;
MasudaToshio 0:af120baf5a2e 57 }
MasudaToshio 0:af120baf5a2e 58
MasudaToshio 0:af120baf5a2e 59
MasudaToshio 0:af120baf5a2e 60
MasudaToshio 0:af120baf5a2e 61
MasudaToshio 0:af120baf5a2e 62
MasudaToshio 0:af120baf5a2e 63 void LcdWrite(char *input , char *output) //ADD Here!!
MasudaToshio 0:af120baf5a2e 64 {
MasudaToshio 0:af120baf5a2e 65
MasudaToshio 0:af120baf5a2e 66 if( input[0] == 0x31 ){
MasudaToshio 0:af120baf5a2e 67 led1 = ! led1 ;
MasudaToshio 0:af120baf5a2e 68 }else{
MasudaToshio 0:af120baf5a2e 69
MasudaToshio 0:af120baf5a2e 70 lcd.locate(0,0);
MasudaToshio 0:af120baf5a2e 71 lcd.printf( " " );
MasudaToshio 0:af120baf5a2e 72 lcd.printf("%s",input);
MasudaToshio 0:af120baf5a2e 73 lcd.printf( " " );
MasudaToshio 0:af120baf5a2e 74
MasudaToshio 0:af120baf5a2e 75 }
MasudaToshio 0:af120baf5a2e 76 }
MasudaToshio 0:af120baf5a2e 77