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:
7:acad90a34466
Parent:
6:2ce163810c2f
Child:
8:305b64d7dd23
--- a/main.cpp	Sat Jul 25 21:49:36 2015 +0000
+++ b/main.cpp	Sun Jul 26 22:14:02 2015 +0000
@@ -11,6 +11,14 @@
 #include <UIPClient.h>
 #include <string>
 
+// PC_0 (connectique Morpho) : Entrée Analogique (0 à 3.3V)
+
+// Carte ENC28J60 <--> Nucleo F411RE
+// PB_5 (connectique Morpho) : MOSI
+// PB_4 (connectique Morpho) : MISO
+// PB_3 (connectique Morpho) : SCK
+// PB_6 (connectique Morpho) : CS
+
 DigitalOut myled(LED1);
 AnalogIn    a_in(PC_0);
 
@@ -56,17 +64,24 @@
 #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 __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 __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;
+float Seconds = 0.0;
+
+Ticker second_ticker;
+
+void add_one_second()
+{
+ Seconds = Seconds + 0.1;
+}
 
 const uint16_t   MY_PORT = 80;      // for HTTP connection
 EthernetServer   myServer = EthernetServer(MY_PORT);
@@ -101,21 +116,17 @@
 
     uint8_t pos = 5 + PASSWORD.size();
 
-    if(str.substr(pos, 1) == " ")
-        return(-2);
+    if(str.substr(pos, 1) == " ") return(-2);
 
-    if(str.substr(pos, 1) != "/")
-        return(-1);
+    if(str.substr(pos, 1) != "/") return(-1);
 
     pos++;
 
     string cmd(str.substr(pos, 5));
 
-    if(cmd == "?sw=0")
-        return(0);
+    if(cmd == "?sw=0")  return(0);
 
-    if(cmd == "?sw=1")
-        return(1);
+    if(cmd == "?sw=1")  return(1);
 
     return(-3);
 }
@@ -136,6 +147,10 @@
 {
     char buffer[32];
     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; // Change the value to be in the 0 to 3300 range
+    
     //-------------
     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";
@@ -153,7 +168,7 @@
  // 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>Designed for STM32F411RE & ENC28J60 (RTC, ADC - <a href=\"http://www.flotcharts.org/flot/examples/interacting/index.html\">Flot Examples: Interactivity</a>),\r\n";
     httpContent += "<p>Compilation avec mBED &agrave; " __TIME__ " le " __DATE__" \r\n";   
            
     httpContent += __Logo_image__ "<p></center>\r\n";
@@ -170,24 +185,26 @@
 
     httpContent += "<hr>\r\n";
     //-------------
+    /*
+    httpContent += "Local Time: ";
     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)); 
+    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
+    */
+    sprintf(buffer, "%f ", Seconds);// diplays the human readable Seconds
     httpContent += buffer;
-    httpContent += "\r\n";    
-    httpContent += "<hr>\r\n";
+    httpContent += "Seconds\r\n<hr>\r\n";
     //----------------
     httpContent += "AnalogIn(PC_0) : ";
-    sprintf(buffer, "%4.3f", a_in * 3.3);
+    sprintf(buffer, "%.0f mV\r\n", meas);
     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);
+    //wait(1);
     return httpContent;
 }
 
@@ -237,23 +254,31 @@
 }
 
 int main()
-{   
+{
  // 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);
+ //-----------------      
     UIPEthernet.begin(MY_MAC,MY_IP);
     myServer.begin();
-    while(1) {
+    while(1)
+    {
         EthernetClient client = myServer.available();
-        if (client) {
+        if(client)
+        {
             size_t size = client.available();
-            if(size > 0) {
+            if(size > 0)
+            {
                 uint8_t* buf = (uint8_t*)malloc(size);
                 size = client.read(buf, size);
                 string received((char*)buf);
                 free(buf);
-                if(received.substr(0, 3) != "GET") {
+                if(received.substr(0, 3) != "GET")
+                {
                     // head, post or other method
                     // for possible status codes see:
                     // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
@@ -263,7 +288,8 @@
                     continue;
                 }
 
-                if(received.substr(0, 6) == "GET / ") {
+                if(received.substr(0, 6) == "GET / ")
+                {
                     httpHeader = HTTP_OK;
                     /*
                     httpContent = "<p>Usage: http://host_or_ip/password</p>\r\n";
@@ -275,14 +301,16 @@
 
                 int cmd = analyse_get_url(received);
 
-                if(cmd == -2) {
+                if(cmd == -2)
+                {
                     // redirect to the right base url
                     httpHeader = MOVED_PERM;
                     http_send(client, httpHeader, moved_perm(1));
                     continue;
                 }
 
-                if(cmd == -1) {
+                if(cmd == -1)
+                {
                     httpHeader = UNAUTHORIZED;
                     httpContent = "<h1>401 Unauthorized";
                     httpContent += __image_401_Unauthorized__ "</h1>\r\n";