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:
6:2ce163810c2f
Parent:
5:a46a2512e17e
Child:
7:acad90a34466
--- a/main.cpp	Sat Jul 25 17:43:36 2015 +0000
+++ b/main.cpp	Sat Jul 25 21:49:36 2015 +0000
@@ -50,7 +50,23 @@
 
 // IP address must be also unique and compatible with your network. Change as appropriate.
 const IPAddress  MY_IP(192,168,0,170);
-#define IPAdress_String "192.168.0.170"
+#define __IP_LOCAL__                               "192.168.0.170"
+#define __hebergement__                            "http://olivier.fournet.free.fr/electronique/Display_temperature_on_mini_web_server_v2/js/"
+#define __Temp_between_measurements__              "1"
+#define __Temp_between_measurements_in_Second__    1
+// Logo Test d'image en base64 :
+// http://webcodertools.com/imagetobase64converter/Create
+#define __Logo_image__ "<img alt='' src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwwAADsMBx2+oZAAAABp0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuMTAw9HKhAAAAUklEQVQ4T2NggIEGMIBzCTDgSh0cHAjrIcFgiGFoGoCWELYQrgLIgGsg4CtkaTibWNfu378fq2tpHx6EbcAMQ8J6iPU3cpIhbCqaisFpCTwVAwB5lit+0ltbrgAAAABJRU5ErkJggg=='>";
+#define __image_Password_Folder__ "<img alt='' src='http://olivier.fournet.free.fr/jpg/password_folder.jpg'>"
+#define __image_301_Moved_Permanently__ "<img alt='' src='http://olivier.fournet.free.fr/jpg/301_moved_permanently.jpg'>"
+#define __image_401_Unauthorized__ "<img alt='' src='http://olivier.fournet.free.fr/png/401_Unauthorized.png'>"
+
+#define NB_SAMPLES    10
+float adc_samples[NB_SAMPLES];// = { 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.01,1.02,1.03,1.04 };
+float time_samples[NB_SAMPLES];// = { -0.1,2,3,4,5,6,7,8,9,10,11,12,13,14 };
+float x_min = 0.0, x_max = 0.0;
+float y_min = 0.0, y_max = 0.0;
+float Seconds;
 
 const uint16_t   MY_PORT = 80;      // for HTTP connection
 EthernetServer   myServer = EthernetServer(MY_PORT);
@@ -111,50 +127,95 @@
     else
         httpContent = "";
 
-    httpContent += "<h1>301 Moved Permanently</h1>\r\n";
-
+    httpContent += "<h1>301 Moved Permanently ";
+    httpContent += __image_301_Moved_Permanently__ "</h1>\r\n";
     return (httpContent);
 }
 
 string& page(uint8_t status)
 {
     char buffer[32];
-    char time_stamp[32];//as our lcd is of 16 character it is so
+    char time_stamp[32];
     //-------------
-    httpContent = "<h2>Web Switch Nucleo-F411RE & ENC28J60 (RTC et ADC) ";
-    httpContent += IPAdress_String "\r\n";
+    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=\"" __Temp_between_measurements__ ";url=http://" __IP_LOCAL__ "/\">\r\n";
+    httpContent += "<HTML><HEAD>\r\n";
+    httpContent += "<title>WEB Server Nucleo F411RE - ENC28J60 - Flot Examples: Interactivity</title>\r\n";
+    httpContent += "<script language=\"javascript\" type=\"text/javascript\" src=\"" __hebergement__ "Interactivity_init.js\"></script>\r\n";
+    httpContent += "<script language=\"javascript\" type=\"text/javascript\">init_Interactivity();</script>\r\n";
+ // Variables JavaScript
+    httpContent += "<script language=\"javascript\" type=\"text/javascript\">\r\n";
+    httpContent += "var color_T = \"#FF0000\";\r\n";
+    httpContent += "var label_t = \"Adc(x)\";\r\n";
+    httpContent += "var x_min = -0.5, x_max =  14.5, y_min = -0.5, y_max =  1.5;\r\n";
+    httpContent += "var temperature = [[-0.1,0.1],[2,0.2],[3,0.3],[4,0.4],[5,0.5],[6,0.6],[7,0.7],[8,0.8],[9,0.9],[10,1],[11,1.01],[12,1.02],[13,1.03],[14,1.04]];\r\n";
+    httpContent += "</script>\r\n";
+ // Fin Variable JavaScript
+    httpContent += "</HEAD><BODY>\r\n";
+    httpContent += "<center><h2>WEB Server Nucleo F411RE</h2>\r\n";
+    httpContent += "<p>Designed for STM32F411RE & ENC28J60 (RTC, ADC - Flot Examples: Interactivity),\r\n";
+    httpContent += "<p>Compilation avec mBED &agrave; " __TIME__ " le " __DATE__" \r\n";   
+           
+    httpContent += __Logo_image__ "<p></center>\r\n";
+    httpContent += "<hr><p>\r\n";
     
-    // Test d'image en base64 :
-    // http://webcodertools.com/imagetobase64converter/Create
-    httpContent += "<img alt='' src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwwAADsMBx2+oZAAAABp0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuMTAw9HKhAAAAUklEQVQ4T2NggIEGMIBzCTDgSh0cHAjrIcFgiGFoGoCWELYQrgLIgGsg4CtkaTibWNfu378fq2tpHx6EbcAMQ8J6iPU3cpIhbCqaisFpCTwVAwB5lit+0ltbrgAAAABJRU5ErkJggg=='>";
-    httpContent += "</h2>\r\n";
+    if(status == 1)
+    {
+        httpContent += "<font color=#00FF00>Switch ON</font>\r\n";
+    } 
+    else 
+    {
+        httpContent += "<font color=#FF0000>Switch OFF</font>\r\n";
+    }
 
-    if(status == 1) {
-        httpContent += "<pre>\r\n  <font color=#00FF00>ON</font>";
+    httpContent += "<hr>\r\n";
+    //-------------
+    time_t seconds = time(NULL)+ 19800; // time(null) gives the GMT time .
+    // printf("Time as seconds since January 1, 1970 = %d\n", seconds);
+    strftime(time_stamp, 32, "Local Time: %y %m %d, %H:%M:%Ss", localtime(&seconds)); 
+    // this converts the value in seconds obtained above to human readable format and assigns it to the timestamp   
+    sprintf(buffer, "%s", time_stamp);// diplays the human readable time
+    httpContent += buffer;
+    httpContent += "\r\n";    
+    httpContent += "<hr>\r\n";
+    //----------------
+    httpContent += "AnalogIn(PC_0) : ";
+    sprintf(buffer, "%4.3f", a_in * 3.3);
+    httpContent += buffer;
+    httpContent += "V\r\n";
+    httpContent += "<hr>\r\n<p>Usage Password Page :<p>http://host_or_ip/password<p><hr>\r\n";
+    httpContent += "<script language=\"javascript\" type=\"text/javascript\">Interactivity();</script>\r\n";
+    httpContent += "</BODY></HTML>";
+    //-----------
+    wait(1);
+    return httpContent;
+}
+
+string& page_toggle_switch(uint8_t status)
+{
+    //-------------
+    httpContent = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\r\n";
+    httpContent += "<HTML><HEAD>\r\n";
+    httpContent += "<title>WEB Server Nucleo F411RE - ENC28J60 - Password Page</title>\r\n";
+    httpContent += "</HEAD><BODY>\r\n";
+    httpContent += "<center><h2>WEB Server Nucleo F411RE - ENC28J60 - Password Page</h2></center>\r\n";
+    httpContent += "<p>" __image_Password_Folder__ "<p>\r\n";
+    if(status == 1)
+    {
+        httpContent += "<hr><pre>\r\n  <font color=#00FF00>ON</font>";
         httpContent += " <a href=\"./?sw=0\">[switch off]</a>\r\n";
-    } else {
-        httpContent += "<pre>\r\n  <font color=#FF0000>OFF</font>";
+    }
+    else
+    {
+        httpContent += "<hr><pre>\r\n  <font color=#FF0000>OFF</font>";
         httpContent += " <a href=\"./?sw=1\">[switch on]</a>\r\n";
     }
 
     httpContent += "  <a href=\".\">[refresh status]</a>\r\n";
     httpContent += "</pre>\r\n";
     httpContent += "<hr>\r\n";
-    //-------------
-    time_t seconds = time(NULL)+ 19800; // time(null) gives the GMT time .
-    // printf("Time as seconds since January 1, 1970 = %d\n", seconds);
-    strftime(time_stamp, 32, "%y %m %d, %H:%M:%Ss", localtime(&seconds)); 
-    // this converts the value in seconds obtained above to human readable format and assigns it to the timestamp   
-    sprintf(buffer, "%s", time_stamp);// diplays the human readable time
-    httpContent += buffer;
-    httpContent += "\r\n";    
-    httpContent += "<hr>\r\n";
-    //----------------
-    httpContent += "Temperature: ";
-    sprintf(buffer, "%4.3f", a_in * 3.3);
-    httpContent += buffer;
-    httpContent += "&deg;C\r\n";
-    httpContent += "<hr>\r\n";
+    
+    httpContent += "</BODY></HTML>";
     //-----------
     wait(1);
     return httpContent;
@@ -180,8 +241,7 @@
  // RTC
  set_time(1387188323); // Set RTC time to 16 December 2013 10:05:23 UTC
  // Date and time are set.
-    
-    
+        
     UIPEthernet.begin(MY_MAC,MY_IP);
     myServer.begin();
     while(1) {
@@ -205,8 +265,11 @@
 
                 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;
                 }
 
@@ -221,21 +284,24 @@
 
                 if(cmd == -1) {
                     httpHeader = UNAUTHORIZED;
-                    httpContent = "<h1>401 Unauthorized</h1>";
+                    httpContent = "<h1>401 Unauthorized";
+                    httpContent += __image_401_Unauthorized__ "</h1>\r\n";
                     http_send(client, httpHeader, httpContent);
                     continue;
                 }
 
-                if(cmd == 1) {
-                    sw = 1;     // switch on
+                if(cmd == 1)
+                { 
+                 sw = 1;     // switch on
                 }
 
-                if(cmd == 0) {
-                    sw = 0;    // switch off
+                if(cmd == 0)
+                {
+                 sw = 0;    // switch off
                 }
 
                 httpHeader = HTTP_OK;
-                http_send(client, httpHeader, page(sw));
+                http_send(client, httpHeader, page_toggle_switch(sw));
             }
         }
     }