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

WIZnet WIZwiki-W7500

/media/uploads/Fo170/wizwiki-w7500_usb_connected.jpg

/media/uploads/Fo170/wiznet_logo_110x37.png 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

/media/uploads/Fo170/wizwiki_w7500_spi_sch.png

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.

  1. define MAC "\x\x\x\x\x\x" Should be Replaced with your MAC
  2. define IP "192.168.77.100" Should belong with your lan.
  3. define MASK "255.255.255.0"
  4. 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

/media/uploads/Fo170/wp_20160508_008.jpg

WIZwiki_W7500 LED RGB :

/media/uploads/Fo170/wizwiki_w7500_led_rgb.png

LED1 = LED_RED = LEDR = PC_8

LED2 = LED_GREEN = LEDG = PC_9

LED3 = LED_BLUE = LEDB = PC_5

LED4 = LED_BLUE

Revision:
3:4f71a37a1ed2
Parent:
1:64f023138627
Child:
5:27b09a0f3fb6
--- a/main.cpp	Fri Dec 06 03:59:01 2013 +0000
+++ b/main.cpp	Sat Apr 19 05:26:40 2014 +0000
@@ -1,7 +1,6 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
 #include "SDFileSystem.h"
-#include "muri.h"
 #include <stdio.h>
 #include <string.h>
 
@@ -9,20 +8,21 @@
 #define HTTPD_MAX_REQ_LENGTH   1023
 #define HTTPD_MAX_HDR_LENGTH   255
 #define HTTPD_MAX_FNAME_LENGTH   127
-#define MURI_MAX_RESP_LENGTH  127
-#define I2C_BUFFER_SIZE 31
+#define HTTPD_MAX_DNAME_LENGTH   127
+
+Serial uart(USBTX, USBRX);
 
-SDFileSystem sd(p5, p6, p7, p8, "sd"); //
-// I2C i2c(p28, p27);
+//SDFileSystem sd(p5, p6, p7, p8, "sd"); // LPC1768 MBD2PMD
+SDFileSystem sd(P0_18, P0_17, P0_15, P0_16, "sd"); // Seeeduino Arch Pro SPI2SD
+
 EthernetInterface eth;
 TCPSocketServer server;
 TCPSocketConnection client;
 
 char buffer[HTTPD_MAX_REQ_LENGTH+1];
 char httpHeader[HTTPD_MAX_HDR_LENGTH+1];
-char filename[HTTPD_MAX_FNAME_LENGTH+1];
-char obuf[MURI_MAX_RESP_LENGTH+1];
-char data[I2C_BUFFER_SIZE];
+char fileName[HTTPD_MAX_FNAME_LENGTH+1];
+char dirName[HTTPD_MAX_DNAME_LENGTH+1];
 char *uristr;
 char *eou;
 char *qrystr;
@@ -32,32 +32,38 @@
 
 void get_file(char* uri)
 {
-    printf("get_file %s\n", uri);
+    uart.printf("get_file %s\n", uri);
     char *lstchr = strrchr(uri, NULL) -1;
     if ('/' == *lstchr) {
-        printf("Open directory /sd%s\n", uri);
+        uart.printf("Open directory /sd%s\n", uri);
         *lstchr = 0;
-        sprintf(filename, "/sd%s", uri);
-        DIR *d = opendir(filename);
+        sprintf(fileName, "/sd%s", uri);
+        DIR *d = opendir(fileName);
         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</h1><ul>", uri);
+            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) {
-                printf("%s\n", p->d_name);
-                sprintf(httpHeader,"<li>%s</li>", p->d_name);
+                sprintf(dirName, "%s/%s", fileName, p->d_name);
+                uart.printf("%s\n", dirName);
+                DIR *subDir = opendir(dirName);
+                if (subDir != NULL) {
+                    sprintf(httpHeader,"<li><a href=\"./%s/\">%s/</a></li>", p->d_name, p->d_name);
+                } else {
+                    sprintf(httpHeader,"<li><a href=\"./%s\">%s</a></li>", p->d_name, p->d_name);
+                }
                 client.send(httpHeader,strlen(httpHeader));
             }
         }
         closedir(d);
-        printf("Directory closed\n");
+        uart.printf("Directory closed\n");
         sprintf(httpHeader,"</ul></body></html>");
         client.send(httpHeader,strlen(httpHeader));
     } else {
-        sprintf(filename, "/sd%s", uri);
-        fp = fopen(filename, "r");
+        sprintf(fileName, "/sd%s", uri);
+        fp = fopen(fileName, "r");
         if (fp == NULL) {
             sprintf(httpHeader,"HTTP/1.1 404 Not Found \r\nContent-Type: text\r\nConnection: Close\r\n\r\n");
             client.send(httpHeader,strlen(httpHeader));
@@ -74,50 +80,40 @@
     }
 }
 
-void get_cgi(char* uri)
-{
-    char *result;
-    muri(uri, data, obuf);
-    if (!strncmp(obuf, "200 ", 4)) {
-        result = obuf +4;
-        sprintf(httpHeader,"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Close\r\n\r\n");
-        client.send(httpHeader,strlen(httpHeader));
-        client.send(result,strlen(result));
-        printf("result:  %s", result);
-    } else {
-        sprintf(httpHeader,"HTTP/1.1 ");
-        client.send(httpHeader,strlen(httpHeader));
-        client.send(obuf,strlen(obuf));
-        sprintf(httpHeader,"\r\n");
-        client.send(httpHeader,strlen(httpHeader)); 
-    }
-    
-}
-
-
 int main (void)
 {
+//    Serial Interface eth;
+    uart.baud(115200);
+    uart.printf("RAPM Serial Started\n");
+
+//    Check File System
+    DIR *d = opendir("/sd/");
+    if (d != NULL) {
+        uart.printf("SD Card Present\n");
+    } else {
+        uart.printf("SD Card Root Directory Not Found\n");
+    }
+
 //    EthernetInterface eth;
     eth.init(); //Use DHCP
     eth.connect();
-    printf("IP Address is %s\n", eth.getIPAddress());
+    uart.printf("IP Address is %s\n", eth.getIPAddress());
 
 //    TCPSocketServer server;
     server.bind(HTTPD_SERVER_PORT);
     server.listen();
-    
-    init_dio(); //initialize pmd digital IO
+    uart.printf("RAPM Server Listening\n");
 
     while (true) {
-        printf("\nWait for new connection...\r\n");
+        uart.printf("\nWait for new connection...\r\n");
         server.accept(client);
         client.set_blocking(false, 1500); // Timeout after (1.5)s
 
-        printf("Connection from: %s\r\n", client.get_address());
+        uart.printf("Connection from: %s\r\n", client.get_address());
         while (true) {
             int n = client.receive(buffer, sizeof(buffer));
             if (n <= 0) break;
-            printf("Recieved Data: %d\r\n\r\n%.*s\r\n",n,n,buffer);
+            uart.printf("Recieved Data: %d\r\n\r\n%.*s\r\n",n,n,buffer);
             if (n >= 1024) {
                 sprintf(httpHeader,"HTTP/1.1 413 Request Entity Too Large \r\nContent-Type: text\r\nConnection: Close\r\n\r\n");
                 client.send(httpHeader,strlen(httpHeader));
@@ -135,11 +131,7 @@
                     client.send(buffer,n);
                 } else {
                     *eou = 0;
-                    if (!strncmp(uristr, "/muri/", 6)) {
-                        get_cgi(uristr+6);
-                    } else {
-                        get_file(uristr);
-                    }
+                    get_file(uristr);
                 }
             }
         }