ert
Dependencies: SDFileSystem WIZnetInterface httpServer_with_Ethernt mbed
main.cpp@0:0d1b91810d28, 2018-04-30 (annotated)
- Committer:
- wiznetw7500
- Date:
- Mon Apr 30 04:47:02 2018 +0000
- Revision:
- 0:0d1b91810d28
teteatat
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| wiznetw7500 | 0:0d1b91810d28 | 1 | #include "mbed.h" |
| wiznetw7500 | 0:0d1b91810d28 | 2 | #include "EthernetInterface.h" |
| wiznetw7500 | 0:0d1b91810d28 | 3 | #include "FsHandler.h" |
| wiznetw7500 | 0:0d1b91810d28 | 4 | #include "HTTPServer.h" |
| wiznetw7500 | 0:0d1b91810d28 | 5 | #include "SDFileSystem.h" |
| wiznetw7500 | 0:0d1b91810d28 | 6 | |
| wiznetw7500 | 0:0d1b91810d28 | 7 | #if defined(TARGET_WIZWIKI_W7500)||defined(TARGET_WIZWIKI_W7500P) |
| wiznetw7500 | 0:0d1b91810d28 | 8 | //Choose one of file system. |
| wiznetw7500 | 0:0d1b91810d28 | 9 | SDFileSystem local(SD_MOSI, SD_MISO, SD_CLK, SD_SEL, "local");//PB_3, PB_2, PB_1, PB_0 |
| wiznetw7500 | 0:0d1b91810d28 | 10 | //LocalFileSystem local("local"); |
| wiznetw7500 | 0:0d1b91810d28 | 11 | #endif |
| wiznetw7500 | 0:0d1b91810d28 | 12 | |
| wiznetw7500 | 0:0d1b91810d28 | 13 | #if defined(TARGET_WIZWIKI_W7500)||defined(TARGET_WIZWIKI_W7500P) |
| wiznetw7500 | 0:0d1b91810d28 | 14 | uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x53, 0xAE, 0x90}; |
| wiznetw7500 | 0:0d1b91810d28 | 15 | #endif |
| wiznetw7500 | 0:0d1b91810d28 | 16 | |
| wiznetw7500 | 0:0d1b91810d28 | 17 | EthernetInterface eth; |
| wiznetw7500 | 0:0d1b91810d28 | 18 | |
| wiznetw7500 | 0:0d1b91810d28 | 19 | // Declare HTTP Server Class |
| wiznetw7500 | 0:0d1b91810d28 | 20 | HTTPServer svr; |
| wiznetw7500 | 0:0d1b91810d28 | 21 | |
| wiznetw7500 | 0:0d1b91810d28 | 22 | DigitalOut myled(D1); |
| wiznetw7500 | 0:0d1b91810d28 | 23 | |
| wiznetw7500 | 0:0d1b91810d28 | 24 | // Set Server Network |
| wiznetw7500 | 0:0d1b91810d28 | 25 | char ip_addr[] = "172.16.73.112"; |
| wiznetw7500 | 0:0d1b91810d28 | 26 | char subnet_mask[] = "255.255.255.0"; |
| wiznetw7500 | 0:0d1b91810d28 | 27 | char gateway_addr[] = "172.16.73.254"; |
| wiznetw7500 | 0:0d1b91810d28 | 28 | |
| wiznetw7500 | 0:0d1b91810d28 | 29 | int main() { |
| wiznetw7500 | 0:0d1b91810d28 | 30 | |
| wiznetw7500 | 0:0d1b91810d28 | 31 | // HTTPFsRequestHandler::mount_eth(ð); |
| wiznetw7500 | 0:0d1b91810d28 | 32 | HTTPFsRequestHandler::mount("/local/", "/"); |
| wiznetw7500 | 0:0d1b91810d28 | 33 | svr.addHandler<HTTPFsRequestHandler>("/"); |
| wiznetw7500 | 0:0d1b91810d28 | 34 | |
| wiznetw7500 | 0:0d1b91810d28 | 35 | #if defined(TARGET_WIZWIKI_W7500)||defined(TARGET_WIZWIKI_W7500P) |
| wiznetw7500 | 0:0d1b91810d28 | 36 | |
| wiznetw7500 | 0:0d1b91810d28 | 37 | #ifdef DHCP |
| wiznetw7500 | 0:0d1b91810d28 | 38 | eth.init(mac_addr); //Use DHCP |
| wiznetw7500 | 0:0d1b91810d28 | 39 | #else |
| wiznetw7500 | 0:0d1b91810d28 | 40 | eth.init(mac_addr, ip_addr, subnet_mask, gateway_addr); //Not Use DHCP |
| wiznetw7500 | 0:0d1b91810d28 | 41 | #endif |
| wiznetw7500 | 0:0d1b91810d28 | 42 | |
| wiznetw7500 | 0:0d1b91810d28 | 43 | #else |
| wiznetw7500 | 0:0d1b91810d28 | 44 | |
| wiznetw7500 | 0:0d1b91810d28 | 45 | #ifdef DHCP |
| wiznetw7500 | 0:0d1b91810d28 | 46 | eth.init(); //Use DHCP |
| wiznetw7500 | 0:0d1b91810d28 | 47 | #else |
| wiznetw7500 | 0:0d1b91810d28 | 48 | eth.init(ip_addr, subnet_mask, gateway_addr); //Not Use DHCP |
| wiznetw7500 | 0:0d1b91810d28 | 49 | #endif |
| wiznetw7500 | 0:0d1b91810d28 | 50 | |
| wiznetw7500 | 0:0d1b91810d28 | 51 | #endif |
| wiznetw7500 | 0:0d1b91810d28 | 52 | |
| wiznetw7500 | 0:0d1b91810d28 | 53 | printf("Check Ethernet Link\r\n"); |
| wiznetw7500 | 0:0d1b91810d28 | 54 | /*while(1) //Wait link up |
| wiznetw7500 | 0:0d1b91810d28 | 55 | { |
| wiznetw7500 | 0:0d1b91810d28 | 56 | if(eth.link() == true) |
| wiznetw7500 | 0:0d1b91810d28 | 57 | break; |
| wiznetw7500 | 0:0d1b91810d28 | 58 | }*/ |
| wiznetw7500 | 0:0d1b91810d28 | 59 | printf("Link up\r\n"); |
| wiznetw7500 | 0:0d1b91810d28 | 60 | |
| wiznetw7500 | 0:0d1b91810d28 | 61 | eth.connect(); |
| wiznetw7500 | 0:0d1b91810d28 | 62 | printf("Server IP Address is %s\r\n", eth.getIPAddress()); |
| wiznetw7500 | 0:0d1b91810d28 | 63 | if (!svr.start(80, ð)) { |
| wiznetw7500 | 0:0d1b91810d28 | 64 | |
| wiznetw7500 | 0:0d1b91810d28 | 65 | error("Server not starting !"); |
| wiznetw7500 | 0:0d1b91810d28 | 66 | exit(0); |
| wiznetw7500 | 0:0d1b91810d28 | 67 | } |
| wiznetw7500 | 0:0d1b91810d28 | 68 | |
| wiznetw7500 | 0:0d1b91810d28 | 69 | while(1) { |
| wiznetw7500 | 0:0d1b91810d28 | 70 | svr.poll(); |
| wiznetw7500 | 0:0d1b91810d28 | 71 | } |
| wiznetw7500 | 0:0d1b91810d28 | 72 | } |