HTTP server example program for WIZwiki-W7500

Dependencies:   WIZnetInterface SDFileSystem httpServer mbed-src

Fork of TCPEchoServer-WIZwiki-W7500 by WIZnet

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "EthernetInterface.h"
00003 #include "FsHandler.h"
00004 #include "HTTPServer.h"
00005 #include "SDFileSystem.h"
00006 
00007 #ifdef TARGET_WIZWIKI_W7500
00008     //Choose one of file system.
00009     SDFileSystem local(SD_MOSI, SD_MISO, SD_CLK, SD_SEL, "local");//PB_3, PB_2, PB_1, PB_0
00010     //LocalFileSystem local("local");
00011 #endif
00012 
00013 #ifdef TARGET_WIZWIKI_W7500
00014     uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02};
00015 #endif
00016 
00017 EthernetInterface eth;
00018 HTTPServer  svr;
00019 char ip_addr[] = "192.168.1.111";
00020 char subnet_mask[] = "255.255.255.0";
00021 char gateway_addr[] = "192.168.1.1";
00022 
00023 //#define DHCP //If uncomment, W7500 runs DHCP
00024 
00025 int main()
00026 {
00027     HTTPFsRequestHandler::mount("/local/", "/");
00028     svr.addHandler<HTTPFsRequestHandler>("/");
00029 
00030 #ifdef TARGET_WIZWIKI_W7500
00031     
00032     #ifdef DHCP
00033         eth.init(mac_addr); //Use DHCP
00034     #else
00035         eth.init(mac_addr, ip_addr, subnet_mask, gateway_addr); //Not Use DHCP
00036     #endif
00037 
00038 #else
00039 
00040     #ifdef DHCP
00041         eth.init(); //Use DHCP
00042     #else
00043         eth.init(ip_addr, subnet_mask, gateway_addr); //Not Use DHCP
00044     #endif
00045 
00046 #endif
00047 
00048     printf("Check Ethernet Link\r\n");
00049     while(1) //Wait link up
00050     {
00051         if(eth.link() == true) 
00052             break;
00053     }
00054     printf("Link up\r\n");
00055 
00056     eth.connect();
00057     printf("Server IP Address is %s\r\n", eth.getIPAddress());
00058 
00059     if (!svr.start(80, &eth)) {
00060 
00061         error("Server not starting !");
00062         exit(0);
00063     }
00064 
00065     while(1) {
00066         svr.poll();
00067     }
00068     
00069 }
00070