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 16:12:10 2015 +0000
Revision:
15:b241b1fccd1f
Parent:
14:671fa04504c2
Child:
16:c074bfec598f
code change the images on resources (the program works well up to 13,600 seconds, the analog measures are still too uncertain -> follow the proposals to reduce noise ...)

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 15:b241b1fccd1f 137 sprintf(buffer, "var x_min = %.1f, x_max = %.1f, y_min = %.1f, y_max = %.1f;\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 15:b241b1fccd1f 145 sprintf(buffer, "[%.1f,%.1f],", 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 15:b241b1fccd1f 164 httpContent += "<font color=#00FF00>Switch ON</font> ";
Fo170 15:b241b1fccd1f 165 httpContent += str_ampoule_ON;
Fo170 15:b241b1fccd1f 166 httpContent += "\r\n";
Fo170 6:2ce163810c2f 167 }
Fo170 6:2ce163810c2f 168 else
Fo170 6:2ce163810c2f 169 {
Fo170 15:b241b1fccd1f 170 httpContent += "<font color=#FF0000>Switch OFF</font> ";
Fo170 15:b241b1fccd1f 171 httpContent += str_ampoule_OFF;
Fo170 15:b241b1fccd1f 172 httpContent += "\r\n";
Fo170 6:2ce163810c2f 173 }
hudakz 0:68a0003c4cb8 174
Fo170 6:2ce163810c2f 175 httpContent += "<hr>\r\n";
Fo170 6:2ce163810c2f 176 //-------------
Fo170 13:c8b148c37fc4 177 httpContent += "(Contact repos) \r\n";
Fo170 14:671fa04504c2 178 if(button_usr)
Fo170 13:c8b148c37fc4 179 {
Fo170 15:b241b1fccd1f 180 httpContent += "<font color=#00FF00>BUTTON ON</font> ";
Fo170 15:b241b1fccd1f 181 httpContent += str_ampoule_ON;
Fo170 15:b241b1fccd1f 182 httpContent += "\r\n";
Fo170 13:c8b148c37fc4 183 }
Fo170 13:c8b148c37fc4 184 else
Fo170 13:c8b148c37fc4 185 {
Fo170 15:b241b1fccd1f 186 httpContent += "<font color=#FF0000>BUTTON OFF</font> ";
Fo170 15:b241b1fccd1f 187 httpContent += str_ampoule_OFF;
Fo170 15:b241b1fccd1f 188 httpContent += "\r\n";
Fo170 13:c8b148c37fc4 189 }
Fo170 13:c8b148c37fc4 190
Fo170 13:c8b148c37fc4 191 httpContent += "<hr>\r\n";
Fo170 13:c8b148c37fc4 192 //-------------
Fo170 7:acad90a34466 193 /*
Fo170 7:acad90a34466 194 httpContent += "Local Time: ";
Fo170 6:2ce163810c2f 195 time_t seconds = time(NULL)+ 19800; // time(null) gives the GMT time .
Fo170 6:2ce163810c2f 196 // printf("Time as seconds since January 1, 1970 = %d\n", seconds);
Fo170 7:acad90a34466 197 strftime(time_stamp, 32, "%y %m %d, %H:%M:%Ss", localtime(&seconds));
Fo170 6:2ce163810c2f 198 // this converts the value in seconds obtained above to human readable format and assigns it to the timestamp
Fo170 6:2ce163810c2f 199 sprintf(buffer, "%s", time_stamp);// diplays the human readable time
Fo170 7:acad90a34466 200 */
Fo170 15:b241b1fccd1f 201 sprintf(buffer, "%.1f Seconds ", Seconds);// diplays the human readable Seconds
Fo170 6:2ce163810c2f 202 httpContent += buffer;
Fo170 15:b241b1fccd1f 203 httpContent += str_chrono;
Fo170 15:b241b1fccd1f 204 httpContent += "\r\n<hr>\r\n";
Fo170 6:2ce163810c2f 205 //----------------
Fo170 12:61b10a733ede 206 httpContent += "AnalogIn(PC_5) : ";
Fo170 15:b241b1fccd1f 207 sprintf(buffer, "%.0f mV ", meas);
Fo170 6:2ce163810c2f 208 httpContent += buffer;
Fo170 15:b241b1fccd1f 209 httpContent += str_thermometre;
Fo170 6:2ce163810c2f 210 httpContent += "<hr>\r\n<p>Usage Password Page :<p>http://host_or_ip/password<p><hr>\r\n";
Fo170 8:305b64d7dd23 211 httpContent += "<script language=\"javascript\" type=\"text/javascript\">WebServerNucleo_Interactivity();</script>\r\n";
Fo170 6:2ce163810c2f 212 httpContent += "</BODY></HTML>";
Fo170 6:2ce163810c2f 213 //-----------
Fo170 7:acad90a34466 214 //wait(1);
Fo170 6:2ce163810c2f 215 return httpContent;
Fo170 6:2ce163810c2f 216 }
Fo170 6:2ce163810c2f 217
hudakz 0:68a0003c4cb8 218 int main()
Fo170 7:acad90a34466 219 {
Fo170 5:a46a2512e17e 220 // RTC
Fo170 8:305b64d7dd23 221 //set_time(1387188323); // Set RTC time to 16 December 2013 10:05:23 UTC
Fo170 5:a46a2512e17e 222 // Date and time are set.
Fo170 7:acad90a34466 223
Fo170 13:c8b148c37fc4 224 // initialisation des variables
Fo170 13:c8b148c37fc4 225 int i;
Fo170 13:c8b148c37fc4 226
Fo170 13:c8b148c37fc4 227 for(i = 0 ; i < NB_SAMPLES ; i++)
Fo170 13:c8b148c37fc4 228 {
Fo170 13:c8b148c37fc4 229 time_samples[i] = 0;
Fo170 13:c8b148c37fc4 230 adc_samples[i] = 0.0;
Fo170 13:c8b148c37fc4 231 }
Fo170 13:c8b148c37fc4 232 // Init the ticker with the address of the function (add_one_second) to be attached and the interval (1000 ms)
Fo170 13:c8b148c37fc4 233 time_tic.attach(&add_one_tic, __Time_tic_in_Second__);
Fo170 13:c8b148c37fc4 234
Fo170 13:c8b148c37fc4 235 // interval: 200 micro seconds chaques samples
Fo170 13:c8b148c37fc4 236 //time_measurement_ADC.attach_us(&measurement_ADC, TIME_SAMPLES_us);
Fo170 13:c8b148c37fc4 237
Fo170 14:671fa04504c2 238 HTTP_LOOP();
hudakz 0:68a0003c4cb8 239 }
hudakz 0:68a0003c4cb8 240
hudakz 3:0133517ba02d 241