HTTP_SDCard_File_Server_WIZwiki-W7500 avec gestion des extensions MIME
Dependencies: SDFileSystem WIZnetInterface mbed STATIC_COLORS
Fork of HTTP_SDCard_File_Server_WIZwiki-W7500 by
WIZnet WIZwiki-W7500
http://www.wiznet.co.kr/product-item/w7500/
Windows serial configuration https://developer.mbed.org/handbook/Windows-serial-configuration https://developer.mbed.org/media/downloads/drivers/mbedWinSerial_16466.exe
How to write the firmware into WIZwiki-W7500 https://developer.mbed.org/teams/WIZnet/wiki/How-to-write-the-firmware-into-WIZwiki-W
Data Output using Serial Port https://blog.wiznettechnology.com/2015/08/14/wiznet-wizwiki-w7500-tutorial-exercise-2-data-output-using-serial-port/ http://wizwiki.net/wiki/doku.php?id=products:w7500:peripherals:uart
SDFileSystem Instanciation
SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); WIZwiki-W7500
Ethernet Initialization
eth.init () uses the eth.init (MAC) If you use DHCP instead, and when using a Static IP uses eth.init ((uint8_t *) MAC, IP, MASK, GATEWAY). This section uses a static IP.
- define MAC "\x
\x\x\x\x\x" Should be Replacedwith your MAC - define IP "192.168.77.100" Should belong with your lan.
- define MASK "255.255.255.0"
- define GATEWAY "192.168.77.1"
eth.init((uint8_t*)MAC); Use DHCP for WIZnetInterface eth.init((uint8_t*)MAC,IP,MASK,GATEWAY); IP,mask,Gateway
Also watch its pages, the initial contributor to the project For Import the example https://developer.mbed.org/teams/WIZnet/code/HTTP_SDCard_File_Server_WIZwiki-W7500/
Wiki on ARMmbed https://developer.mbed.org/teams/WIZnet/code/HTTP_SDCard_File_Server_WIZwiki-W7500/wiki/HTTP_SDCard_File_Server_WIZwiki-W7500
WIZwiki_W7500 LED RGB :
LED1 = LED_RED = LEDR = PC_8
LED2 = LED_GREEN = LEDG = PC_9
LED3 = LED_BLUE = LEDB = PC_5
LED4 = LED_BLUE
Diff: main.cpp
- Revision:
- 10:e8dd198d1056
- Parent:
- 9:d0615c97295e
- Child:
- 11:ee62fd965f0a
--- a/main.cpp Thu Jul 30 02:21:13 2015 +0000 +++ b/main.cpp Sun May 08 00:51:53 2016 +0000 @@ -6,9 +6,9 @@ #define MAC "\x00\x08\xDC\x11\x34\x78" -#define IP "192.168.77.100" +#define IP "192.168.0.170" #define MASK "255.255.255.0" -#define GATEWAY "192.168.77.1" +#define GATEWAY "192.168.0.254" #define HTTPD_SERVER_PORT 80 #define HTTPD_MAX_REQ_LENGTH 1023 @@ -43,35 +43,50 @@ Ticker ledTick; +//char str[] = "This is a sample string"; +char *pch; +char ext[5]; +char ext_gif[] = "gif"; +char ext_jpg[] = "jpg"; +char ext_png[] = "png"; +int pos_ext; +int extLen; + void ledTickfunc() { led1 = !led1; } - - void get_file(char* uri) { + int i, ext_j; + uart.printf("get_file %s\n", uri); char *lstchr = strrchr(uri, NULL) -1; - if ('/' == *lstchr) { + if('/' == *lstchr) + { uart.printf("Open directory /sd%s\n", uri); *lstchr = 0; sprintf(fileName, "/sd%s", uri); DIR *d = opendir(fileName); - if (d != NULL) { + if(d != NULL) + { sprintf(httpHeader,"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Close\r\n\r\n"); client.send(httpHeader,strlen(httpHeader)); sprintf(httpHeader,"<html><head><title>Directory Listing</title></head><body><h1>%s Directory Listing</h1><ul>", uri); client.send(httpHeader,strlen(httpHeader)); struct dirent *p; - while((p = readdir(d)) != NULL) { + while((p = readdir(d)) != NULL) + { sprintf(dirName, "%s/%s", fileName, p->d_name); uart.printf("%s\n", dirName); DIR *subDir = opendir(dirName); - if (subDir != NULL) { + if(subDir != NULL) + { sprintf(httpHeader,"<li><a href=\"./%s/\">%s/</a></li>", p->d_name, p->d_name); - } else { + } + else + { sprintf(httpHeader,"<li><a href=\"./%s\">%s</a></li>", p->d_name, p->d_name); } client.send(httpHeader,strlen(httpHeader)); @@ -81,20 +96,73 @@ uart.printf("Directory closed\n"); sprintf(httpHeader,"</ul></body></html>"); client.send(httpHeader,strlen(httpHeader)); - } else { + } + else + { sprintf(fileName, "/sd%s", uri); fp = fopen(fileName, "r"); - if (fp == NULL) { + if(fp == NULL) + { uart.printf("File not found\n"); sprintf(httpHeader,"HTTP/1.1 404 Not Found \r\nContent-Type: text\r\nConnection: Close\r\n\r\n"); client.send(httpHeader,strlen(httpHeader)); client.send(uri,strlen(uri)); - } else { - uart.printf("Sending: header"); - sprintf(httpHeader,"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Close\r\n\r\n"); + } + else + { + pch = strrchr(fileName,'.'); + + if( pch != NULL) + { + pos_ext = pch - fileName + 1; + extLen = strlen(fileName) - pos_ext; + + uart.printf("Last occurence of '.' found at %d , extLen : %d\n", pos_ext, extLen ); + + for(i=0; i<extLen; i=i+1) + { + ext[i] = fileName[i+pos_ext]; + } + + ext[extLen] = '\0'; + + uart.printf("Sending: header # %s\n", fileName); + uart.printf("extension %s\n", ext); + + if( strcmp(ext, ext_gif) == 0 ) ext_j = 1; + + if( strcmp(ext, ext_jpg) == 0 ) ext_j = 2; + + if( strcmp(ext, ext_png) == 0 ) ext_j = 3; + } + else + { + uart.printf("Sending: header # %s\n", fileName); + ext_j = 0; + } + + switch(ext_j) + { + case 1: // HTTP reply with GIF image mime type + sprintf(httpHeader,"HTTP/1.1 200 OK\r\nContent-Type: image/gif\r\nConnection: Close\r\n\r\n"); + break; + + case 2: // HTTP reply with JPG image mime type + sprintf(httpHeader,"HTTP/1.1 200 OK\r\nContent-Type: image/jpg\r\nConnection: Close\r\n\r\n"); + break; + + case 3: // HTTP reply with PNG image mime type + sprintf(httpHeader,"HTTP/1.1 200 OK\r\nContent-Type: image/jpg\r\nConnection: Close\r\n\r\n"); + break; + + default: // HTTP reply with HTML mime type + sprintf(httpHeader,"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Close\r\n\r\n"); + } + client.send(httpHeader,strlen(httpHeader)); uart.printf(" file"); - while ((rdCnt = fread(buffer, sizeof( char ), 1024, fp)) == 1024) { + while((rdCnt = fread(buffer, sizeof( char ), 1024, fp)) == 1024) + { client.send(buffer, rdCnt); uart.printf("."); } @@ -109,7 +177,7 @@ { ledTick.attach(&ledTickfunc,0.5); // Serial Interface eth; - uart.baud(115200); + uart.baud(9600); uart.printf("Initializing\n"); // Check File System