HTTP server is created by connecting an ENC28J60 module to the mbed board. It is serving a webpage which enables remotely turn on/off LED1 (or other device). Compile, download, run and type 192.168.0.170/secret/ into your web browser and Flot Interactivity Graphique

Dependencies:   UIPEthernet mbed FCT_WEB hebergement

Fork of WebSwitch_ENC28J60 by Zoltan Hudak

Page généré : /media/uploads/Fo170/webservernucleo.png

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/

Vue d'ensemble : /media/uploads/Fo170/vue_d_ensemble_1.jpg

/media/uploads/Fo170/vue_d_ensemble_2.jpg

Vue de la carte ENC28J60 : /media/uploads/Fo170/carte_enc28j60_a.jpg

/media/uploads/Fo170/carte_enc28j60_b.jpg

Carte Nucléo : /media/uploads/Fo170/nucleo_stm32f411re.jpg

Revision:
13:c8b148c37fc4
Parent:
12:61b10a733ede
Child:
14:671fa04504c2
--- a/main.cpp	Wed Jul 29 18:02:03 2015 +0000
+++ b/main.cpp	Wed Aug 05 12:45:44 2015 +0000
@@ -21,6 +21,7 @@
 
 DigitalOut myled(LED1);
 AnalogIn    a_in(PC_5); // PC_5 au lieu de PC_0
+DigitalIn boton(USER_BUTTON);
 
 using namespace std;
 
@@ -60,16 +61,23 @@
 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 __Temp_between_measurements__            =  "1";
-#define      __Temp_between_measurements_in_Second__     1
+const string __Time_between_page_refresh__            =  "1";
+
 
 // Logo Test d'image en base64 :
 // http://webcodertools.com/imagetobase64converter/Create
 const string __Logo_image__ =  "<img alt='' src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwwAADsMBx2+oZAAAABp0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuMTAw9HKhAAAAUklEQVQ4T2NggIEGMIBzCTDgSh0cHAjrIcFgiGFoGoCWELYQrgLIgGsg4CtkaTibWNfu378fq2tpHx6EbcAMQ8J6iPU3cpIhbCqaisFpCTwVAwB5lit+0ltbrgAAAABJRU5ErkJggg=='>";
 
-const string __image_Password_Folder__        = "<img alt='' src='http://olivier.fournet.free.fr/jpg/password_folder.jpg'>";
-const string __image_301_Moved_Permanently__  = "<img alt='' src='http://olivier.fournet.free.fr/jpg/301_moved_permanently.jpg'>";
-const string __image_401_Unauthorized__       = "<img alt='' src='http://olivier.fournet.free.fr/png/401_Unauthorized.png'>";
+const string __image_Password_Folder__  = "<img alt='' src='http://olivier.fournet.free.fr/jpg/password_folder.jpg'>";
+
+//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 __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 NB_SAMPLES    10
 unsigned long int Sample = 0;
@@ -78,13 +86,38 @@
 float x_min = 0.0, x_max = 0.0;
 float y_min = 0.0, y_max = 0.0;
 float Seconds = 0.0;
-float k = 0.0;
+float meas = 0.0;
+
 //------------
-Ticker second_ticker;
+#define      __Time_tic_in_Second__      0.1
+
+Ticker time_tic;
 
-void add_one_second()
+void add_one_tic()
 {       
- Seconds = Seconds + k;//0.1;
+ int i;
+ 
+ Seconds = Seconds + (float)__Time_tic_in_Second__;
+ 
+ // mesures ADC
+    meas = a_in.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
+    meas = meas * 3300.0; // Change the value to be in the 0 to 3300 range
+    
+    x_min = x_max = Seconds;
+    y_min = y_max = meas;
+                    
+    for(i = 1 ; i < NB_SAMPLES ; i++)
+    {
+     time_samples[i-1] = time_samples[i];
+     adc_samples[i-1] = adc_samples[i];
+     if( time_samples[i] < x_min ) x_min = time_samples[i];
+     if( time_samples[i] > x_max ) x_max = time_samples[i];
+     if( adc_samples[i] < y_min ) y_min = adc_samples[i];
+     if( adc_samples[i] > y_max ) y_max = adc_samples[i];
+    }
+
+    adc_samples[NB_SAMPLES-1] = meas;
+    time_samples[NB_SAMPLES-1] = Seconds;
 }
 //------------
 const uint16_t   MY_PORT = 80;      // for HTTP connection
@@ -135,47 +168,34 @@
     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];
+    int i;
     //char time_stamp[32];
-    float meas;
-    meas = a_in.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
-    meas = meas * 3300.0; // Change the value to be in the 0 to 3300 range
-    //Seconds = Seconds + 1;
-    x_min = x_max = Seconds;
-    y_min = y_max = meas;
-    int i;
-                    
-    for(i = 1 ; i < NB_SAMPLES ; i++)
-    {
-     time_samples[i-1] = time_samples[i];
-     adc_samples[i-1] = adc_samples[i];
-     if( time_samples[i] < x_min ) x_min = time_samples[i];
-     if( time_samples[i] > x_max ) x_max = time_samples[i];
-     if( adc_samples[i] < y_min ) y_min = adc_samples[i];
-     if( adc_samples[i] > y_max ) y_max = adc_samples[i];
-    }
 
-    adc_samples[NB_SAMPLES-1] = meas;
-    time_samples[NB_SAMPLES-1] = Seconds;
     //-------------
     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 += __Temp_between_measurements__;
+    httpContent += __Time_between_page_refresh__;
     httpContent += ";url=http://";
     httpContent += __IP_LOCAL__;
     httpContent += "/\">\r\n";
@@ -185,7 +205,7 @@
     httpContent += __hebergement__;
     httpContent += "WebServerNucleo_Interactivity_init.js\"></script>\r\n";
     httpContent += "<script language=\"javascript\" type=\"text/javascript\">init_WebServerNucleo_Interactivity();</script>\r\n";
- // Variables JavaScript
+    // Variables JavaScript
     httpContent += "<script language=\"javascript\" type=\"text/javascript\">\r\n";
     httpContent += "var color_Y = \"#FF0000\";\r\n";
     httpContent += "var label_Y = \"Adc(x)\";\r\n";
@@ -226,6 +246,18 @@
 
     httpContent += "<hr>\r\n";
     //-------------
+    httpContent += "(Contact repos) \r\n";
+    if(boton)
+    {
+        httpContent += "<font color=#00FF00>BUTTON ON</font>\r\n";
+    } 
+    else 
+    {
+        httpContent += "<font color=#FF0000>BUTTON OFF</font>\r\n";
+    }
+    
+    httpContent += "<hr>\r\n";
+    //-------------
     /*
     httpContent += "Local Time: ";
     time_t seconds = time(NULL)+ 19800; // time(null) gives the GMT time .
@@ -276,7 +308,7 @@
     
     httpContent += "</BODY></HTML>";
     //-----------
-    wait(1);
+    //wait(1);
     return httpContent;
 }
 
@@ -299,12 +331,22 @@
 {
  // RTC
  //set_time(1387188323); // Set RTC time to 16 December 2013 10:05:23 UTC
- 
  // Date and time are set.
  
- // Init the ticker with the address of the function (add_one_second) to be attached and the interval (100 ms)
- second_ticker.attach(&add_one_second, 0.1);
- k = (float)__Temp_between_measurements_in_Second__ / (float)NB_SAMPLES;
+ // initialisation des variables
+ int i;
+ 
+ for(i = 0 ; i < NB_SAMPLES ; i++)
+ {
+      time_samples[i] = 0;
+      adc_samples[i] = 0.0;
+ }
+ // Init the ticker with the address of the function (add_one_second) to be attached and the interval (1000 ms)
+ time_tic.attach(&add_one_tic, __Time_tic_in_Second__);
+ 
+ // interval: 200 micro seconds chaques samples
+ //time_measurement_ADC.attach_us(&measurement_ADC, TIME_SAMPLES_us);
+ 
  //-----------------      
     UIPEthernet.begin(MY_MAC,MY_IP);
     myServer.begin();
@@ -355,9 +397,12 @@
                 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;
                 }