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

Files at this revision

API Documentation at this revision

Comitter:
Fo170
Date:
Sun May 08 17:04:06 2016 +0000
Parent:
10:e8dd198d1056
Child:
12:8cb8eeb1dc94
Commit message:
ajout des affichages LED RVB

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun May 08 00:51:53 2016 +0000
+++ b/main.cpp	Sun May 08 17:04:06 2016 +0000
@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include <string.h>
 
+#define USE_DHCP    0
 
 #define MAC     "\x00\x08\xDC\x11\x34\x78"
 #define IP      "192.168.0.170"
@@ -18,9 +19,6 @@
 
 Serial uart(USBTX, USBRX);
 
-//SDFileSystem sd(p5, p6, p7, p8, "sd"); // LPC1768 MBD2PMD
-//SDFileSystem sd(P0_18, P0_17, P0_15, P0_16, "sd"); // Seeeduino Arch Pro SPI2SD
-//SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // K64F
 SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // WIZwiki-W7500 
 
 EthernetInterface eth;
@@ -38,8 +36,16 @@
 FILE *fp;
 int rdCnt;
 
-DigitalOut led1(LED1); //server listning status
-DigitalOut led2(LED2); //socket connecting status
+DigitalOut led_r(LED_RED);   //server listning status
+DigitalOut led_g(LED_GREEN); //socket connecting status Ok
+DigitalOut led_b(LED_BLUE);  //socket connecting status Busy
+
+/* W7500
+LED1 = LED_RED   = LEDR = PC_8
+LED2 = LED_GREEN = LEDG = PC_9
+LED3 = LED_BLUE  = LEDB = PC_5
+LED4 = LED_BLUE
+*/
 
 Ticker ledTick;
 
@@ -49,12 +55,13 @@
 char ext_gif[] = "gif";
 char ext_jpg[] = "jpg";
 char ext_png[] = "png";
+char ext_tiff[] = "tiff";
 int pos_ext;
 int extLen;
 
 void ledTickfunc()
 {
-    led1 = !led1;
+    led_r = !led_r;
 }
 
 void get_file(char* uri)
@@ -126,18 +133,20 @@
          
           ext[extLen] = '\0';
          
-            uart.printf("Sending: header # %s\n", fileName);
-            uart.printf("extension %s\n", ext);
+            uart.printf("Sending header of the : %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;         
+            
+            if( strcmp(ext, ext_tiff) == 0 ) ext_j = 4;
           }
           else
           {
-             uart.printf("Sending: header # %s\n", fileName);
+             uart.printf("Sending header of the : %s\n", fileName);
              ext_j = 0;
           }
             
@@ -155,12 +164,16 @@
              sprintf(httpHeader,"HTTP/1.1 200 OK\r\nContent-Type: image/jpg\r\nConnection: Close\r\n\r\n");
              break;
              
+             case 4: // HTTP reply with TIFF image mime type
+             sprintf(httpHeader,"HTTP/1.1 200 OK\r\nContent-Type: image/tiff\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");
+            uart.printf(" file ");
             while((rdCnt = fread(buffer, sizeof( char ), 1024, fp)) == 1024)
             {
                 client.send(buffer, rdCnt);
@@ -173,44 +186,91 @@
     }
 }
 
-int main (void)
+int main(void)
 {
     ledTick.attach(&ledTickfunc,0.5);
 //    Serial Interface eth;
     uart.baud(9600);
     uart.printf("Initializing\n");
-
+  wait(1.0);
 //    Check File System
     uart.printf("Checking File System\n");
     DIR *d = opendir("/sd/");
-    if (d != NULL) {
+    if(d != NULL) 
+    {
         uart.printf("SD Card Present\n");
-    } else {
+    } 
+    else 
+    {
         uart.printf("SD Card Root Directory Not Found\n");
     }
-
+   wait(1.0);
 //    EthernetInterface eth;
     uart.printf("Initializing Ethernet\n");
-    //eth.init(); //Use DHCP
-    //eth.init((uint8_t*)MAC);    // Use DHCP for WIZnetInterface
-    eth.init((uint8_t*)MAC,IP,MASK,GATEWAY);  //IP,mask,Gateway
-    uart.printf("Connecting\n");
-    eth.connect();
-    uart.printf("IP Address is %s\n", eth.getIPAddress());
-
+    #if USE_DHCP
+    //eth.init Use DHCP
+    int ret = eth.init((uint8_t*)MAC);    // Use DHCP for WIZnetInterface
+    uart.printf("Connecting DHCP\n");
+    #else
+    int ret = eth.init((uint8_t*)MAC,IP,MASK,GATEWAY);  //IP,mask,Gateway
+    uart.printf("Connecting (IP,mask,Gateway)\n");
+    #endif
+    wait(1.0);
+    // Check Ethernet Link-Done
+    uart.printf("Check Ethernet Link\r\n");
+    
+    if(eth.link() == true) 
+    { 
+     uart.printf("- Ethernet PHY Link-Done \r\n");
+     led_r = true;
+    }
+    else 
+    {
+     uart.printf("- Ethernet PHY Link- Fail\r\n");
+     led_r = false;
+    }
+    wait(1.0);
+    if(!ret) 
+    {
+     uart.printf("Initialized, MAC: %s\r\n", eth.getMACAddress());
+     ret = eth.connect();
+     
+     if(!ret) 
+     {
+            uart.printf("IP: %s, MASK: %s, GW: %s\r\n",
+                      eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway());
+      led_b = true;
+      led_g = true;
+     } 
+     else 
+     {
+            uart.printf("Error ethernet.connect() - ret = %d\r\n", ret);
+      led_b = false;
+      exit(0);
+     }
+    } 
+    else 
+    {
+        uart.printf("Error ethernet.init() - ret = %d\r\n", ret);
+     led_b = false;
+     exit(0);
+    }    
+    wait(1.0);
 //    TCPSocketServer server;
     server.bind(HTTPD_SERVER_PORT);
     server.listen();
     uart.printf("Server Listening\n");
 
-    while (true) {
+    while(true) 
+    {
         uart.printf("\nWait for new connection...\r\n");
         server.accept(client);
         client.set_blocking(false, 1500); // Timeout after (1.5)s
 
         uart.printf("Connection from: %s\r\n", client.get_address());
-        while (true) {
-            led2 = true;
+        while(true) 
+        {
+            led_g = true;
             int n = client.receive(buffer, sizeof(buffer));
             if (n <= 0) break;
             uart.printf("Recieved Data: %d\r\n\r\n%.*s\r\n",n,n,buffer);
@@ -235,7 +295,7 @@
                 }
             }
         }
-        led2 = false;
+        led_g = false;
         client.close();
     }
 }