test ADC avec page Web reduite

Dependencies:   UIPEthernet mbed FCT_WEB hebergement

Fork of Nucleo_Web_ENC28J60 by FOURNET Olivier

P.S : 1ère mise en fonctionnement de la carte NUCLEO STM32F411RET6

Instruction pour la mise en fonctionnement : https://developer.mbed.org/users/Fo170/notebook/the-stm32-nucleo-64-board/

Revision:
18:7254aeaa41a8
Parent:
17:7539e7bdfee9
--- a/main.cpp	Thu Aug 06 13:55:44 2015 +0000
+++ b/main.cpp	Mon Sep 28 22:30:14 2015 +0000
@@ -11,8 +11,10 @@
 #include <UIPClient.h>
 #include <string>
 
-// PC_5 (connectique Morpho) : Entrée Analogique (0 à 3.3V)
+// PC_5 (connectique Morpho) : Entrée Analogique (0 a 3.3V)
 
+// Carte ENC28J60 : http://www.mikroe.com/add-on-boards/communication/serial-ethernet-proto/
+ 
 // Carte ENC28J60 <--> Nucleo F411RE
 // PB_5 (connectique Morpho) : MOSI
 // PB_4 (connectique Morpho) : MISO
@@ -58,19 +60,40 @@
 
 // IP address must be also unique and compatible with your network. Change as appropriate.
 const IPAddress  MY_IP(192,168,0,170);
-const string __IP_LOCAL__                             =  "192.168.0.170";
-const string __hebergement__                          =  "http://olivier.fournet.free.fr/electronique/e/WebServerNucleo/js/";
-const string __Time_between_page_refresh__            =  "1";
+#define  __IP_LOCAL__                     "192.168.0.170"
+
+// In this example we are turning on/off LED1.
+DigitalOut       sw(LED1);  // Change LED1 to a pin of your choice. However, make sure that it does not collide with any of the SPI pins already used in the UIPEthernet(...) constructor above!
+
+const string PASSWORD     = "secret";   // change as you like
 
-const string __image_Password_Folder__  = "<img alt='' src='http://olivier.fournet.free.fr/jpg/password_folder.jpg'>";
+#include <hebergement.h>
+#include <Fct_Web.h>
+
+/*
+#define  __hebergement__                  "http://olivier.fournet.free.fr/"
+#define  __Time_between_page_refresh__    "1"
+
+const string str_meta_refresh  = "<meta http-equiv=\"refresh\" content=\"" __Time_between_page_refresh__ ";url=http://" __IP_LOCAL__ "/\">";
 
-//const string __image_301_Moved_Permanently__  = "<img alt='' src='http://olivier.fournet.free.fr/jpg/301_moved_permanently.jpg'>";
-#define __image_301_Moved_Permanently__           "<img alt='' src='http://olivier.fournet.free.fr/jpg/301_moved_permanently.jpg'>"
-const string str_moved_perm   = "<h1>301 Moved Permanently " __image_301_Moved_Permanently__ "</h1>\r\n";
+const string str_JavaScript  = "<script language=\"javascript\" type=\"text/javascript\" src=\"" __hebergement__ "electronique/e/WebServerNucleo/js/WebServerNucleo_Interactivity_init.js\"></script>\r\n";
+
+const string str_Compilation_DATE_AND_TIME = "<p>Compilation avec mBED &agrave; " __TIME__ " le " __DATE__" \r\n"; 
+
+// Logo Test d'image en base64 :
+// http://webcodertools.com/imagetobase64converter/Create
+// const string str_Logo_image =  "<img alt='' src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwwAADsMBx2+oZAAAABp0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuMTAw9HKhAAAAUklEQVQ4T2NggIEGMIBzCTDgSh0cHAjrIcFgiGFoGoCWELYQrgLIgGsg4CtkaTibWNfu378fq2tpHx6EbcAMQ8J6iPU3cpIhbCqaisFpCTwVAwB5lit+0ltbrgAAAABJRU5ErkJggg=='>";
+const string str_favicon = "<LINK REL=\"SHORTCUT ICON\" type=\"image/x-icon\" href=\"" __hebergement__ "favicon.ico\">\r\n<link rel=\"icon\" href=\"" __hebergement__ "favicon.ico\" type=\"image/x-icon\">";
 
-//const string __image_401_Unauthorized__       = "<img alt='' src='http://olivier.fournet.free.fr/png/401_Unauthorized.png'>";
-#define __image_401_Unauthorized__                "<img alt='' src='http://olivier.fournet.free.fr/png/401_Unauthorized.png'>"
-const string str_Unauthorized = "<h1>401 Unauthorized " __image_401_Unauthorized__ "</h1>\r\n";
+#define __image_password_folder__                "password_folder.jpg"
+const string str_image_Password_Folder  = "<img alt='' src='" __hebergement__ "jpg/" __image_password_folder__ "'>";
+
+#define __image_301_Moved_Permanently__          "301_moved_permanently.jpg"
+const string str_moved_perm   = "<h1>301 Moved Permanently <img alt='' src='" __hebergement__ "jpg/" __image_301_Moved_Permanently__ "'></h1>\r\n";
+
+#define __image_401_Unauthorized__               "401_Unauthorized.png"
+const string str_Unauthorized = "<h1>401 Unauthorized <img alt='' src='" __hebergement__ "png/" __image_401_Unauthorized__ "'></h1>\r\n";
+*/
 
 #define FREQUENCE_SECTEUR             50
 #define NB_SAMPLES_PAR_OSCILLATION    100
@@ -128,17 +151,16 @@
     Seconds = Seconds + (float)__Time_between_refresh_in_Second__;
 }
 //------------
-const uint16_t   MY_PORT = 80;      // for HTTP connection
-EthernetServer   myServer = EthernetServer(MY_PORT);
-// In this example we are turning on/off LED1.
-DigitalOut       sw(LED1);  // Change LED1 to a pin of your choice. However, make sure that it does not collide with any of the SPI pins already used in the UIPEthernet(...) constructor above!
+//const uint16_t   MY_PORT = 80;      // for HTTP connection
+//EthernetServer   myServer = EthernetServer(MY_PORT);
 
-const string PASSWORD     = "secret";   // change as you like
+/*
 const string HTTP_OK      = "HTTP/1.0 200 OK";
 const string MOVED_PERM   = "HTTP/1.0 301 Moved Permanently\r\nLocation: ";
 const string UNAUTHORIZED = "HTTP/1.0 401 Unauthorized";
-string       httpHeader;     // HTTP header
-string       httpContent;    // HTTP content
+*/
+//string       httpHeader;     // HTTP header
+//string       httpContent;    // HTTP content
 
 
 // analyse the url given
@@ -153,7 +175,7 @@
 //                GET /password/ HTTP/1.....
 //                GET /password/?sw=1 HTTP/1.....
 //                GET /password/?sw=0 HTTP/1.....
-
+/*
 int8_t analyse_get_url(string& str)
 {
     if(str.substr(5, PASSWORD.size()) != PASSWORD)
@@ -175,44 +197,37 @@
 
     return(-3);
 }
-
+*/
+/*
 string& moved_perm(uint8_t flag)
 {
     if(flag == 1)
         httpContent = "/" +  PASSWORD + "/";
     else
         httpContent = "";
-    /*
-       httpContent += "<h1>301 Moved Permanently ";
-       httpContent += __image_301_Moved_Permanently__;
-       httpContent += "</h1>\r\n";
-       */
+   
     httpContent += str_moved_perm;
 
     return (httpContent);
 }
-
+*/
 string& page(uint8_t status)
 {
     char buffer[128];
     //char time_stamp[32];
 
     //-------------
-    httpContent = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\r\n";
-    httpContent += "<meta http-equiv=\"refresh\" content=\"";
-    httpContent += __Time_between_page_refresh__;
-    httpContent += ";url=http://";
-    httpContent += __IP_LOCAL__;
-    httpContent += "/\">\r\n";
-    httpContent += "<HTML><HEAD>\r\n";
+    httpContent = str_DOCTYPE;
+    httpContent += str_meta_refresh;
+    httpContent += "\r\n<HTML><HEAD>\r\n";
     httpContent += "<title>WEB Server Nucleo F411RE & ENC28J60 - ADC</title>\r\n";
-
-
-
+    httpContent += str_favicon;
+    httpContent += str_JavaScript;
     httpContent += "</HEAD><BODY>\r\n";
     httpContent += "<center><h2>WEB Server Nucleo F411RE (ADC)</h2>\r\n";
     httpContent += "<p>Designed for STM32F411RE & ENC28J60 (ADC)\r\n";
-    httpContent += "<p>Compilation avec mBED &agrave; " __TIME__ " le " __DATE__" \r\n";
+    httpContent += str_Compilation_DATE_AND_TIME;       
+    // httpContent += str_Logo_image ;
 
     httpContent += "<p></center>\r\n<hr><p>\r\n";
 
@@ -244,6 +259,7 @@
     return httpContent;
 }
 
+/*
 void http_send(EthernetClient& client, string& header, string& content)
 {
     char content_length[5] = {};
@@ -258,7 +274,7 @@
     string webpage = header + content;
     client.write((uint8_t*)webpage.c_str(),webpage.length());
 }
-
+*/
 int main()
 {
     meas_moy = 0.0;
@@ -282,7 +298,9 @@
 // interval: 200 micro seconds chaques samples
     time_measurement_ADC.attach_us(&measurement_ADC, TIME_SAMPLES_us);
 
-//-----------------
+ //-----------------
+ HTTP_LOOP();
+ /*
     UIPEthernet.begin(MY_MAC,MY_IP);
     myServer.begin();
     while(1) {
@@ -306,10 +324,7 @@
 
                 if(received.substr(0, 6) == "GET / ") {
                     httpHeader = HTTP_OK;
-                    /*
-                    httpContent = "<p>Usage: http://host_or_ip/password</p>\r\n";
-                    http_send(client, httpHeader, httpContent);
-                    */
+                    
                     http_send(client, httpHeader, page(sw));
                     continue;
                 }
@@ -325,11 +340,7 @@
 
                 if(cmd == -1) {
                     httpHeader = UNAUTHORIZED;
-                    /*
-                    httpContent = "<h1>401 Unauthorized ";
-                    httpContent += __image_401_Unauthorized__;
-                    httpContent += "</h1>\r\n";
-                    */
+                    
                     httpContent = str_Unauthorized;
                     http_send(client, httpHeader, httpContent);
                     continue;
@@ -337,6 +348,7 @@
             }
         }
     }
+    */
 }