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

Committer:
Fo170
Date:
Wed Aug 19 11:05:49 2015 +0000
Revision:
14:671fa04504c2
Parent:
13:c8b148c37fc4
Child:
15:b241b1fccd1f
last days of the code to separate common web based and variable (text, images, etc ...)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:68a0003c4cb8 1 /* In this example LED1 is switched on/off using a web browser connected to this HTTP server.
hudakz 4:d34811deedab 2 * The example is based on the Tuxgraphics Web Switch <http://www.tuxgraphics.org/>.
hudakz 4:d34811deedab 3 * This HTTP server is built around the the ENC28J60 chip
hudakz 4:d34811deedab 4 * driven by the UIPEthernet library <https://github.com/ntruchsess/arduino_uip>
hudakz 0:68a0003c4cb8 5 * ported to mbed.
hudakz 0:68a0003c4cb8 6 */
hudakz 0:68a0003c4cb8 7
hudakz 0:68a0003c4cb8 8 #include <mbed.h>
hudakz 0:68a0003c4cb8 9 #include <UIPEthernet.h>
hudakz 0:68a0003c4cb8 10 #include <UIPServer.h>
hudakz 0:68a0003c4cb8 11 #include <UIPClient.h>
hudakz 0:68a0003c4cb8 12 #include <string>
hudakz 0:68a0003c4cb8 13
Fo170 12:61b10a733ede 14 // PC_5 (connectique Morpho) : Entrée Analogique (0 à 3.3V)
Fo170 7:acad90a34466 15
Fo170 7:acad90a34466 16 // Carte ENC28J60 <--> Nucleo F411RE
Fo170 7:acad90a34466 17 // PB_5 (connectique Morpho) : MOSI
Fo170 7:acad90a34466 18 // PB_4 (connectique Morpho) : MISO
Fo170 7:acad90a34466 19 // PB_3 (connectique Morpho) : SCK
Fo170 7:acad90a34466 20 // PB_6 (connectique Morpho) : CS
Fo170 7:acad90a34466 21
Fo170 14:671fa04504c2 22 DigitalOut myled(LED1);
Fo170 12:61b10a733ede 23 AnalogIn a_in(PC_5); // PC_5 au lieu de PC_0
Fo170 14:671fa04504c2 24 DigitalIn button_usr(USER_BUTTON);
Fo170 5:a46a2512e17e 25
hudakz 0:68a0003c4cb8 26 using namespace std;
hudakz 0:68a0003c4cb8 27
hudakz 0:68a0003c4cb8 28 // UIPEthernet is the name of a global instance of UIPEthernetClass.
hudakz 0:68a0003c4cb8 29 // Do not change the name! It is used within the UIPEthernet library.
hudakz 0:68a0003c4cb8 30 #if defined(TARGET_LPC1768)
hudakz 4:d34811deedab 31 UIPEthernetClass UIPEthernet(p11, p12, p13, p8); // mosi, miso, sck, cs
hudakz 0:68a0003c4cb8 32 #elif defined(TARGET_LPC1114)
hudakz 0:68a0003c4cb8 33 UIPEthernetClass UIPEthernet(dp2, dp1, dp6, dp25); // mosi, miso, sck, cs
hudakz 0:68a0003c4cb8 34 #elif defined(TARGET_LPC11U68)
hudakz 0:68a0003c4cb8 35 UIPEthernetClass UIPEthernet(P0_9, P0_8, P1_29, P0_2); // mosi, miso, sck, cs
hudakz 0:68a0003c4cb8 36 #elif defined (TARGET_NUCLEO_F103RB)
hudakz 0:68a0003c4cb8 37 UIPEthernetClass UIPEthernet(PB_5, PB_4, PB_3, PB_6); // mosi, miso, sck, cs
hudakz 4:d34811deedab 38 #elif defined (TARGET_NUCLEO_F401RE)
hudakz 4:d34811deedab 39 UIPEthernetClass UIPEthernet(PB_5, PB_4, PB_3, PB_6); // mosi, miso, sck, cs
hudakz 4:d34811deedab 40 #elif defined (TARGET_NUCLEO_F411RE)
hudakz 4:d34811deedab 41 UIPEthernetClass UIPEthernet(PB_5, PB_4, PB_3, PB_6); // mosi, miso, sck, cs
hudakz 4:d34811deedab 42
hudakz 4:d34811deedab 43 // If your board/plaform is not present yet then uncomment the following two lines and replace TARGET_YOUR_BOARD as appropriate.
hudakz 4:d34811deedab 44
hudakz 4:d34811deedab 45 //#elif defined (TARGET_YOUR_BOARD)
hudakz 4:d34811deedab 46 //UIPEthernetClass UIPEthernet(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS); // mosi, miso, sck, cs
hudakz 4:d34811deedab 47
hudakz 0:68a0003c4cb8 48 #endif
hudakz 0:68a0003c4cb8 49
hudakz 4:d34811deedab 50 // Note:
hudakz 4:d34811deedab 51 // If it happends that any of the SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS pins collide with LED1 pin
hudakz 4:d34811deedab 52 // then either use different SPI port (if available on the board) and change the pin names in the constructor UIPEthernet(...) accordingly
hudakz 4:d34811deedab 53 // or instead of using LED1 pin, select a free pin (not used by SPI port) and connect to it an external LED which is connected to a resitor that is connected to the groud.
hudakz 4:d34811deedab 54 // In the second case remember to replace LED1 in sw(LED1) constructor (see below).
hudakz 4:d34811deedab 55
hudakz 0:68a0003c4cb8 56 // MAC number must be unique within the connected network. Modify as appropriate.
hudakz 3:0133517ba02d 57 const uint8_t MY_MAC[6] = {0x00,0x01,0x02,0x03,0x04,0x06};
Fo170 5:a46a2512e17e 58
hudakz 0:68a0003c4cb8 59 // IP address must be also unique and compatible with your network. Change as appropriate.
Fo170 14:671fa04504c2 60 const IPAddress MY_IP(10,0,0,170);
Fo170 14:671fa04504c2 61 #define __IP_LOCAL__ "10.0.0.170"
Fo170 8:305b64d7dd23 62
Fo170 14:671fa04504c2 63 /* Maison
Fo170 14:671fa04504c2 64 const IPAddress MY_IP(192,168,0,170);
Fo170 14:671fa04504c2 65 #define __IP_LOCAL__ "192.168.0.170"
Fo170 14:671fa04504c2 66 */
Fo170 14:671fa04504c2 67 const string PASSWORD = "secret"; // change as you like
Fo170 13:c8b148c37fc4 68
Fo170 14:671fa04504c2 69 // In this example we are turning on/off LED1.
Fo170 14:671fa04504c2 70 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!
Fo170 13:c8b148c37fc4 71
Fo170 14:671fa04504c2 72 #include <hebergement.h>
Fo170 14:671fa04504c2 73 #include <Fct_Web.h>
Fo170 6:2ce163810c2f 74
Fo170 6:2ce163810c2f 75 #define NB_SAMPLES 10
Fo170 11:afb33350db83 76 unsigned long int Sample = 0;
Fo170 6:2ce163810c2f 77 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 };
Fo170 6:2ce163810c2f 78 float time_samples[NB_SAMPLES];// = { -0.1,2,3,4,5,6,7,8,9,10,11,12,13,14 };
Fo170 6:2ce163810c2f 79 float x_min = 0.0, x_max = 0.0;
Fo170 6:2ce163810c2f 80 float y_min = 0.0, y_max = 0.0;
Fo170 7:acad90a34466 81 float Seconds = 0.0;
Fo170 13:c8b148c37fc4 82 float meas = 0.0;
Fo170 13:c8b148c37fc4 83
Fo170 11:afb33350db83 84 //------------
Fo170 13:c8b148c37fc4 85 #define __Time_tic_in_Second__ 0.1
Fo170 13:c8b148c37fc4 86
Fo170 13:c8b148c37fc4 87 Ticker time_tic;
Fo170 7:acad90a34466 88
Fo170 13:c8b148c37fc4 89 void add_one_tic()
Fo170 11:afb33350db83 90 {
Fo170 13:c8b148c37fc4 91 int i;
Fo170 13:c8b148c37fc4 92
Fo170 13:c8b148c37fc4 93 Seconds = Seconds + (float)__Time_tic_in_Second__;
Fo170 13:c8b148c37fc4 94
Fo170 13:c8b148c37fc4 95 // mesures ADC
Fo170 13:c8b148c37fc4 96 meas = a_in.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
Fo170 13:c8b148c37fc4 97 meas = meas * 3300.0; // Change the value to be in the 0 to 3300 range
Fo170 13:c8b148c37fc4 98
Fo170 13:c8b148c37fc4 99 x_min = x_max = Seconds;
Fo170 13:c8b148c37fc4 100 y_min = y_max = meas;
Fo170 13:c8b148c37fc4 101
Fo170 13:c8b148c37fc4 102 for(i = 1 ; i < NB_SAMPLES ; i++)
Fo170 13:c8b148c37fc4 103 {
Fo170 13:c8b148c37fc4 104 time_samples[i-1] = time_samples[i];
Fo170 13:c8b148c37fc4 105 adc_samples[i-1] = adc_samples[i];
Fo170 13:c8b148c37fc4 106 if( time_samples[i] < x_min ) x_min = time_samples[i];
Fo170 13:c8b148c37fc4 107 if( time_samples[i] > x_max ) x_max = time_samples[i];
Fo170 13:c8b148c37fc4 108 if( adc_samples[i] < y_min ) y_min = adc_samples[i];
Fo170 13:c8b148c37fc4 109 if( adc_samples[i] > y_max ) y_max = adc_samples[i];
Fo170 13:c8b148c37fc4 110 }
Fo170 13:c8b148c37fc4 111
Fo170 13:c8b148c37fc4 112 adc_samples[NB_SAMPLES-1] = meas;
Fo170 13:c8b148c37fc4 113 time_samples[NB_SAMPLES-1] = Seconds;
Fo170 7:acad90a34466 114 }
Fo170 11:afb33350db83 115 //------------
hudakz 0:68a0003c4cb8 116
hudakz 0:68a0003c4cb8 117
hudakz 0:68a0003c4cb8 118 string& page(uint8_t status)
hudakz 0:68a0003c4cb8 119 {
Fo170 11:afb33350db83 120 char buffer[128];
Fo170 13:c8b148c37fc4 121 int i;
Fo170 8:305b64d7dd23 122 //char time_stamp[32];
Fo170 11:afb33350db83 123
Fo170 5:a46a2512e17e 124 //-------------
Fo170 14:671fa04504c2 125 httpContent = str_DOCTYPE;
Fo170 14:671fa04504c2 126 httpContent += str_meta_refresh;
Fo170 14:671fa04504c2 127 httpContent += "\r\n<HTML><HEAD>\r\n";
Fo170 6:2ce163810c2f 128 httpContent += "<title>WEB Server Nucleo F411RE - ENC28J60 - Flot Examples: Interactivity</title>\r\n";
Fo170 14:671fa04504c2 129 httpContent += str_favicon;
Fo170 14:671fa04504c2 130 httpContent += str_JavaScript;
Fo170 8:305b64d7dd23 131 httpContent += "<script language=\"javascript\" type=\"text/javascript\">init_WebServerNucleo_Interactivity();</script>\r\n";
Fo170 13:c8b148c37fc4 132 // Variables JavaScript
Fo170 6:2ce163810c2f 133 httpContent += "<script language=\"javascript\" type=\"text/javascript\">\r\n";
Fo170 8:305b64d7dd23 134 httpContent += "var color_Y = \"#FF0000\";\r\n";
Fo170 8:305b64d7dd23 135 httpContent += "var label_Y = \"Adc(x)\";\r\n";
Fo170 11:afb33350db83 136 //httpContent += "var x_min = -0.5, x_max = 14.5, y_min = -0.5, y_max = 1.5;\r\n";
Fo170 11:afb33350db83 137 sprintf(buffer, "var x_min = %f, x_max = %f, y_min = %f, y_max = %f;\r\n", x_min, x_max, y_min, y_max);
Fo170 11:afb33350db83 138 httpContent += buffer;
Fo170 11:afb33350db83 139 //httpContent += "var array_value = [[-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";
Fo170 11:afb33350db83 140 if(Sample > NB_SAMPLES)
Fo170 11:afb33350db83 141 {
Fo170 11:afb33350db83 142 httpContent += "var array_value = [";
Fo170 11:afb33350db83 143 for(i = 0 ; i < NB_SAMPLES ; i++)
Fo170 11:afb33350db83 144 {
Fo170 11:afb33350db83 145 sprintf(buffer, "[%f,%f],", time_samples[i], adc_samples[i]);
Fo170 11:afb33350db83 146 httpContent += buffer;
Fo170 11:afb33350db83 147 }
Fo170 11:afb33350db83 148 httpContent += "];\r\n";
Fo170 11:afb33350db83 149 }
Fo170 11:afb33350db83 150 Sample++;
Fo170 6:2ce163810c2f 151 httpContent += "</script>\r\n";
Fo170 14:671fa04504c2 152 // Fin Variable JavaScript
Fo170 6:2ce163810c2f 153 httpContent += "</HEAD><BODY>\r\n";
Fo170 6:2ce163810c2f 154 httpContent += "<center><h2>WEB Server Nucleo F411RE</h2>\r\n";
Fo170 7:acad90a34466 155 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";
Fo170 14:671fa04504c2 156
Fo170 14:671fa04504c2 157 httpContent += str_Compilation_DATE_AND_TIME;
Fo170 14:671fa04504c2 158 // httpContent += str_Logo_image;
Fo170 8:305b64d7dd23 159
Fo170 8:305b64d7dd23 160 httpContent += "<p></center>\r\n<hr><p>\r\n";
Fo170 5:a46a2512e17e 161
Fo170 6:2ce163810c2f 162 if(status == 1)
Fo170 6:2ce163810c2f 163 {
Fo170 6:2ce163810c2f 164 httpContent += "<font color=#00FF00>Switch ON</font>\r\n";
Fo170 6:2ce163810c2f 165 }
Fo170 6:2ce163810c2f 166 else
Fo170 6:2ce163810c2f 167 {
Fo170 6:2ce163810c2f 168 httpContent += "<font color=#FF0000>Switch OFF</font>\r\n";
Fo170 6:2ce163810c2f 169 }
hudakz 0:68a0003c4cb8 170
Fo170 6:2ce163810c2f 171 httpContent += "<hr>\r\n";
Fo170 6:2ce163810c2f 172 //-------------
Fo170 13:c8b148c37fc4 173 httpContent += "(Contact repos) \r\n";
Fo170 14:671fa04504c2 174 if(button_usr)
Fo170 13:c8b148c37fc4 175 {
Fo170 13:c8b148c37fc4 176 httpContent += "<font color=#00FF00>BUTTON ON</font>\r\n";
Fo170 13:c8b148c37fc4 177 }
Fo170 13:c8b148c37fc4 178 else
Fo170 13:c8b148c37fc4 179 {
Fo170 13:c8b148c37fc4 180 httpContent += "<font color=#FF0000>BUTTON OFF</font>\r\n";
Fo170 13:c8b148c37fc4 181 }
Fo170 13:c8b148c37fc4 182
Fo170 13:c8b148c37fc4 183 httpContent += "<hr>\r\n";
Fo170 13:c8b148c37fc4 184 //-------------
Fo170 7:acad90a34466 185 /*
Fo170 7:acad90a34466 186 httpContent += "Local Time: ";
Fo170 6:2ce163810c2f 187 time_t seconds = time(NULL)+ 19800; // time(null) gives the GMT time .
Fo170 6:2ce163810c2f 188 // printf("Time as seconds since January 1, 1970 = %d\n", seconds);
Fo170 7:acad90a34466 189 strftime(time_stamp, 32, "%y %m %d, %H:%M:%Ss", localtime(&seconds));
Fo170 6:2ce163810c2f 190 // this converts the value in seconds obtained above to human readable format and assigns it to the timestamp
Fo170 6:2ce163810c2f 191 sprintf(buffer, "%s", time_stamp);// diplays the human readable time
Fo170 7:acad90a34466 192 */
Fo170 8:305b64d7dd23 193 sprintf(buffer, "%.1f ", Seconds);// diplays the human readable Seconds
Fo170 6:2ce163810c2f 194 httpContent += buffer;
Fo170 7:acad90a34466 195 httpContent += "Seconds\r\n<hr>\r\n";
Fo170 6:2ce163810c2f 196 //----------------
Fo170 12:61b10a733ede 197 httpContent += "AnalogIn(PC_5) : ";
Fo170 7:acad90a34466 198 sprintf(buffer, "%.0f mV\r\n", meas);
Fo170 6:2ce163810c2f 199 httpContent += buffer;
Fo170 6:2ce163810c2f 200 httpContent += "<hr>\r\n<p>Usage Password Page :<p>http://host_or_ip/password<p><hr>\r\n";
Fo170 8:305b64d7dd23 201 httpContent += "<script language=\"javascript\" type=\"text/javascript\">WebServerNucleo_Interactivity();</script>\r\n";
Fo170 6:2ce163810c2f 202 httpContent += "</BODY></HTML>";
Fo170 6:2ce163810c2f 203 //-----------
Fo170 7:acad90a34466 204 //wait(1);
Fo170 6:2ce163810c2f 205 return httpContent;
Fo170 6:2ce163810c2f 206 }
Fo170 6:2ce163810c2f 207
hudakz 0:68a0003c4cb8 208 int main()
Fo170 7:acad90a34466 209 {
Fo170 5:a46a2512e17e 210 // RTC
Fo170 8:305b64d7dd23 211 //set_time(1387188323); // Set RTC time to 16 December 2013 10:05:23 UTC
Fo170 5:a46a2512e17e 212 // Date and time are set.
Fo170 7:acad90a34466 213
Fo170 13:c8b148c37fc4 214 // initialisation des variables
Fo170 13:c8b148c37fc4 215 int i;
Fo170 13:c8b148c37fc4 216
Fo170 13:c8b148c37fc4 217 for(i = 0 ; i < NB_SAMPLES ; i++)
Fo170 13:c8b148c37fc4 218 {
Fo170 13:c8b148c37fc4 219 time_samples[i] = 0;
Fo170 13:c8b148c37fc4 220 adc_samples[i] = 0.0;
Fo170 13:c8b148c37fc4 221 }
Fo170 13:c8b148c37fc4 222 // Init the ticker with the address of the function (add_one_second) to be attached and the interval (1000 ms)
Fo170 13:c8b148c37fc4 223 time_tic.attach(&add_one_tic, __Time_tic_in_Second__);
Fo170 13:c8b148c37fc4 224
Fo170 13:c8b148c37fc4 225 // interval: 200 micro seconds chaques samples
Fo170 13:c8b148c37fc4 226 //time_measurement_ADC.attach_us(&measurement_ADC, TIME_SAMPLES_us);
Fo170 13:c8b148c37fc4 227
Fo170 14:671fa04504c2 228 HTTP_LOOP();
hudakz 0:68a0003c4cb8 229 }
hudakz 0:68a0003c4cb8 230
hudakz 3:0133517ba02d 231