FOURNET Olivier / Mbed 2 deprecated HTTP_SDCard_File_Server_WIZwiki-W7500

Dependencies:   SDFileSystem WIZnetInterface mbed STATIC_COLORS

Fork of HTTP_SDCard_File_Server_WIZwiki-W7500 by WIZnet

Files at this revision

API Documentation at this revision

Comitter:
Fo170
Date:
Sun May 15 14:11:45 2016 +0000
Parent:
11:ee62fd965f0a
Commit message:
mise en place de la lib. STATIC_COLORS

Changed in this revision

STATIC_COLORS.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r ee62fd965f0a -r 8cb8eeb1dc94 STATIC_COLORS.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/STATIC_COLORS.lib	Sun May 15 14:11:45 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/Fo170/code/STATIC_COLORS/#a638217762a2
diff -r ee62fd965f0a -r 8cb8eeb1dc94 main.cpp
--- a/main.cpp	Sun May 08 17:04:06 2016 +0000
+++ b/main.cpp	Sun May 15 14:11:45 2016 +0000
@@ -4,7 +4,7 @@
 #include <stdio.h>
 #include <string.h>
 
-#define USE_DHCP    0
+#define USE_DHCP    1
 
 #define MAC     "\x00\x08\xDC\x11\x34\x78"
 #define IP      "192.168.0.170"
@@ -17,9 +17,14 @@
 #define HTTPD_MAX_FNAME_LENGTH   127
 #define HTTPD_MAX_DNAME_LENGTH   127
 
+#if defined(TARGET_WIZwiki_W7500)
 Serial uart(USBTX, USBRX);
-
-SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // WIZwiki-W7500 
+SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // WIZwiki-W7500
+#include "static_colors.h"
+// LED R     : server listning status
+// LED GREEN : socket connecting status Ok
+// LED BLUE  : socket connecting status Busy
+#endif
 
 EthernetInterface eth;
 TCPSocketServer server;
@@ -36,16 +41,8 @@
 FILE *fp;
 int rdCnt;
 
-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
-*/
+// Initialize a pins to perform analog input and digital output fucntions
+AnalogIn   ain(A0);
 
 Ticker ledTick;
 
@@ -73,6 +70,7 @@
     if('/' == *lstchr) 
     {
         uart.printf("Open directory /sd%s\n", uri);
+        if( 0 == strcmp("/Images/", uri) ) uart.printf("(Directory OK)\n");
         *lstchr = 0;
         sprintf(fileName, "/sd%s", uri);
         DIR *d = opendir(fileName);
@@ -80,7 +78,7 @@
         {
             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);
+            sprintf(httpHeader,"<html><head><title>Directory Listing</title></head><body><h2>%s Directory Listing</h2><br><hr><br><ul>", uri);
             client.send(httpHeader,strlen(httpHeader));
             struct dirent *p;
             while((p = readdir(d)) != NULL)
@@ -111,9 +109,21 @@
         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));
+            if( 0 == strcmp("/AIN0.js", uri) )
+            {
+                uart.printf("(File OK)\n");
+                sprintf(httpHeader,"HTTP/1.1 200 OK\r\nContent-Type: application/javascript\r\nConnection: Close\r\n\r\n");
+                client.send(httpHeader,strlen(httpHeader));
+                
+                sprintf(httpHeader,"var AIN0 = %3.3f;\n", ain.read()*3.3f);
+                client.send(httpHeader,strlen(httpHeader));
+            }
+            else
+            {
+             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 
         {
@@ -189,8 +199,10 @@
 int main(void)
 {
     ledTick.attach(&ledTickfunc,0.5);
-//    Serial Interface eth;
+    // Serial Interface eth;
+    // Serial port configuration (valeurs par defaut) : 9600 baud, 8-bit data, no parity, stop bit
     uart.baud(9600);
+    uart.format(8, SerialBase::None, 1);
     uart.printf("Initializing\n");
   wait(1.0);
 //    Check File System
@@ -221,13 +233,15 @@
     
     if(eth.link() == true) 
     { 
-     uart.printf("- Ethernet PHY Link-Done \r\n");
-     led_r = true;
+     uart.printf("- Ethernet PHY Link - Done\r\n");
+     //led_r = LED_ON;
+     COLOR(_RED_);
     }
     else 
     {
-     uart.printf("- Ethernet PHY Link- Fail\r\n");
-     led_r = false;
+     uart.printf("- Ethernet PHY Link - Fail\r\n");
+     //led_r = LED_OFF;
+     COLOR(_BLACK_);
     }
     wait(1.0);
     if(!ret) 
@@ -239,20 +253,22 @@
      {
             uart.printf("IP: %s, MASK: %s, GW: %s\r\n",
                       eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway());
-      led_b = true;
-      led_g = true;
+      // led_b = LED_ON, led_g = LED_ON;
+      COLOR(_CYAN_);
      } 
      else 
      {
             uart.printf("Error ethernet.connect() - ret = %d\r\n", ret);
-      led_b = false;
+      //led_b = LED_OFF;
+      COLOR(_BLUE_);
       exit(0);
      }
     } 
     else 
     {
         uart.printf("Error ethernet.init() - ret = %d\r\n", ret);
-     led_b = false;
+     //led_b = LED_OFF;
+     COLOR(_BLACK_);
      exit(0);
     }    
     wait(1.0);
@@ -270,32 +286,41 @@
         uart.printf("Connection from: %s\r\n", client.get_address());
         while(true) 
         {
-            led_g = true;
+            //led_g = LED_ON;
+            COLOR(_GREEN_);
             int n = client.receive(buffer, sizeof(buffer));
-            if (n <= 0) break;
+            if(n <= 0) break;
             uart.printf("Recieved Data: %d\r\n\r\n%.*s\r\n",n,n,buffer);
-            if (n >= 1024) {
+            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));
                 client.send(buffer,n);
                 break;
-            } else {
+            } 
+            else 
+            {
                 buffer[n]=0;
             }
-            if (!strncmp(buffer, "GET ", 4)) {
+            if(!strncmp(buffer, "GET ", 4)) 
+            {
                 uristr = buffer + 4;
                 eou = strstr(uristr, " ");
-                if (eou == NULL) {
+                if(eou == NULL) 
+                {
                     sprintf(httpHeader,"HTTP/1.1 400 Bad Request \r\nContent-Type: text\r\nConnection: Close\r\n\r\n");
                     client.send(httpHeader,strlen(httpHeader));
                     client.send(buffer,n);
-                } else {
+                } 
+                else 
+                {
                     *eou = 0;
                     get_file(uristr);
                 }
             }
         }
-        led_g = false;
+        //led_g = LED_OFF;
+        COLOR(_BLACK_);
         client.close();
     }
 }
diff -r ee62fd965f0a -r 8cb8eeb1dc94 mbed.bld
--- a/mbed.bld	Sun May 08 17:04:06 2016 +0000
+++ b/mbed.bld	Sun May 15 14:11:45 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/165afa46840b
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/7c328cabac7e
\ No newline at end of file