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:
Mon Sep 28 22:20:08 2015 +0000
Revision:
16:c074bfec598f
Parent:
15:b241b1fccd1f
mise a jours info carte ENC28J60 de MikroE

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