test ADC avec page Web reduite

Dependencies:   UIPEthernet mbed FCT_WEB hebergement

Fork of Nucleo_Web_ENC28J60 by FOURNET Olivier

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/

Committer:
Fo170
Date:
Mon Sep 28 22:30:14 2015 +0000
Revision:
18:7254aeaa41a8
Parent:
17:7539e7bdfee9
mise a jours info carte ENC28J60 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/>.
Fo170 17:7539e7bdfee9 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 18:7254aeaa41a8 14 // PC_5 (connectique Morpho) : Entrée Analogique (0 a 3.3V)
Fo170 7:acad90a34466 15
Fo170 18:7254aeaa41a8 16 // Carte ENC28J60 : http://www.mikroe.com/add-on-boards/communication/serial-ethernet-proto/
Fo170 18:7254aeaa41a8 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 5:a46a2512e17e 24 DigitalOut myled(LED1);
Fo170 12:61b10a733ede 25 AnalogIn a_in(PC_5); // PC_5 au lieu de PC_0
Fo170 5:a46a2512e17e 26
hudakz 0:68a0003c4cb8 27 using namespace std;
hudakz 0:68a0003c4cb8 28
hudakz 0:68a0003c4cb8 29 // UIPEthernet is the name of a global instance of UIPEthernetClass.
hudakz 0:68a0003c4cb8 30 // Do not change the name! It is used within the UIPEthernet library.
hudakz 0:68a0003c4cb8 31 #if defined(TARGET_LPC1768)
hudakz 4:d34811deedab 32 UIPEthernetClass UIPEthernet(p11, p12, p13, p8); // mosi, miso, sck, cs
hudakz 0:68a0003c4cb8 33 #elif defined(TARGET_LPC1114)
hudakz 0:68a0003c4cb8 34 UIPEthernetClass UIPEthernet(dp2, dp1, dp6, dp25); // mosi, miso, sck, cs
hudakz 0:68a0003c4cb8 35 #elif defined(TARGET_LPC11U68)
hudakz 0:68a0003c4cb8 36 UIPEthernetClass UIPEthernet(P0_9, P0_8, P1_29, P0_2); // mosi, miso, sck, cs
hudakz 0:68a0003c4cb8 37 #elif defined (TARGET_NUCLEO_F103RB)
hudakz 0:68a0003c4cb8 38 UIPEthernetClass UIPEthernet(PB_5, PB_4, PB_3, PB_6); // mosi, miso, sck, cs
hudakz 4:d34811deedab 39 #elif defined (TARGET_NUCLEO_F401RE)
hudakz 4:d34811deedab 40 UIPEthernetClass UIPEthernet(PB_5, PB_4, PB_3, PB_6); // mosi, miso, sck, cs
hudakz 4:d34811deedab 41 #elif defined (TARGET_NUCLEO_F411RE)
hudakz 4:d34811deedab 42 UIPEthernetClass UIPEthernet(PB_5, PB_4, PB_3, PB_6); // mosi, miso, sck, cs
hudakz 4:d34811deedab 43
hudakz 4:d34811deedab 44 // If your board/plaform is not present yet then uncomment the following two lines and replace TARGET_YOUR_BOARD as appropriate.
hudakz 4:d34811deedab 45
hudakz 4:d34811deedab 46 //#elif defined (TARGET_YOUR_BOARD)
hudakz 4:d34811deedab 47 //UIPEthernetClass UIPEthernet(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS); // mosi, miso, sck, cs
hudakz 4:d34811deedab 48
hudakz 0:68a0003c4cb8 49 #endif
hudakz 0:68a0003c4cb8 50
hudakz 4:d34811deedab 51 // Note:
hudakz 4:d34811deedab 52 // If it happends that any of the SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS pins collide with LED1 pin
hudakz 4:d34811deedab 53 // then either use different SPI port (if available on the board) and change the pin names in the constructor UIPEthernet(...) accordingly
hudakz 4:d34811deedab 54 // 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 55 // In the second case remember to replace LED1 in sw(LED1) constructor (see below).
hudakz 4:d34811deedab 56
hudakz 0:68a0003c4cb8 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 5:a46a2512e17e 62 const IPAddress MY_IP(192,168,0,170);
Fo170 18:7254aeaa41a8 63 #define __IP_LOCAL__ "192.168.0.170"
Fo170 18:7254aeaa41a8 64
Fo170 18:7254aeaa41a8 65 // In this example we are turning on/off LED1.
Fo170 18:7254aeaa41a8 66 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 18:7254aeaa41a8 67
Fo170 18:7254aeaa41a8 68 const string PASSWORD = "secret"; // change as you like
Fo170 13:939e0fa0cd39 69
Fo170 18:7254aeaa41a8 70 #include <hebergement.h>
Fo170 18:7254aeaa41a8 71 #include <Fct_Web.h>
Fo170 18:7254aeaa41a8 72
Fo170 18:7254aeaa41a8 73 /*
Fo170 18:7254aeaa41a8 74 #define __hebergement__ "http://olivier.fournet.free.fr/"
Fo170 18:7254aeaa41a8 75 #define __Time_between_page_refresh__ "1"
Fo170 18:7254aeaa41a8 76
Fo170 18:7254aeaa41a8 77 const string str_meta_refresh = "<meta http-equiv=\"refresh\" content=\"" __Time_between_page_refresh__ ";url=http://" __IP_LOCAL__ "/\">";
Fo170 13:939e0fa0cd39 78
Fo170 18:7254aeaa41a8 79 const string str_JavaScript = "<script language=\"javascript\" type=\"text/javascript\" src=\"" __hebergement__ "electronique/e/WebServerNucleo/js/WebServerNucleo_Interactivity_init.js\"></script>\r\n";
Fo170 18:7254aeaa41a8 80
Fo170 18:7254aeaa41a8 81 const string str_Compilation_DATE_AND_TIME = "<p>Compilation avec mBED &agrave; " __TIME__ " le " __DATE__" \r\n";
Fo170 18:7254aeaa41a8 82
Fo170 18:7254aeaa41a8 83 // Logo Test d'image en base64 :
Fo170 18:7254aeaa41a8 84 // http://webcodertools.com/imagetobase64converter/Create
Fo170 18:7254aeaa41a8 85 // const string str_Logo_image = "<img alt='' src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwwAADsMBx2+oZAAAABp0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuMTAw9HKhAAAAUklEQVQ4T2NggIEGMIBzCTDgSh0cHAjrIcFgiGFoGoCWELYQrgLIgGsg4CtkaTibWNfu378fq2tpHx6EbcAMQ8J6iPU3cpIhbCqaisFpCTwVAwB5lit+0ltbrgAAAABJRU5ErkJggg=='>";
Fo170 18:7254aeaa41a8 86 const string str_favicon = "<LINK REL=\"SHORTCUT ICON\" type=\"image/x-icon\" href=\"" __hebergement__ "favicon.ico\">\r\n<link rel=\"icon\" href=\"" __hebergement__ "favicon.ico\" type=\"image/x-icon\">";
Fo170 8:305b64d7dd23 87
Fo170 18:7254aeaa41a8 88 #define __image_password_folder__ "password_folder.jpg"
Fo170 18:7254aeaa41a8 89 const string str_image_Password_Folder = "<img alt='' src='" __hebergement__ "jpg/" __image_password_folder__ "'>";
Fo170 18:7254aeaa41a8 90
Fo170 18:7254aeaa41a8 91 #define __image_301_Moved_Permanently__ "301_moved_permanently.jpg"
Fo170 18:7254aeaa41a8 92 const string str_moved_perm = "<h1>301 Moved Permanently <img alt='' src='" __hebergement__ "jpg/" __image_301_Moved_Permanently__ "'></h1>\r\n";
Fo170 18:7254aeaa41a8 93
Fo170 18:7254aeaa41a8 94 #define __image_401_Unauthorized__ "401_Unauthorized.png"
Fo170 18:7254aeaa41a8 95 const string str_Unauthorized = "<h1>401 Unauthorized <img alt='' src='" __hebergement__ "png/" __image_401_Unauthorized__ "'></h1>\r\n";
Fo170 18:7254aeaa41a8 96 */
Fo170 13:939e0fa0cd39 97
Fo170 13:939e0fa0cd39 98 #define FREQUENCE_SECTEUR 50
Fo170 13:939e0fa0cd39 99 #define NB_SAMPLES_PAR_OSCILLATION 100
Fo170 13:939e0fa0cd39 100 #define NB_SAMPLES 5000 // FREQUENCE_SECTEUR * NB_SAMPLES_PAR_OSCILLATION
Fo170 13:939e0fa0cd39 101 #define TIME_SAMPLES_us 200 // 1000000 / NB_SAMPLES
Fo170 13:939e0fa0cd39 102 unsigned long int Samples = 0;
Fo170 13:939e0fa0cd39 103
Fo170 13:939e0fa0cd39 104 float Seconds = 0.0;
Fo170 13:939e0fa0cd39 105 float time_between_two_measurement_ADC = 0.0;
Fo170 17:7539e7bdfee9 106 float meas, meas_sum, meas_moy, meas_min, meas_max;
Fo170 17:7539e7bdfee9 107 float vdc, vdc_min, vdc_max;
Fo170 17:7539e7bdfee9 108 float vac, pow2_vac, sum_pow2_vac, veff;
Fo170 8:305b64d7dd23 109
Fo170 13:939e0fa0cd39 110 Ticker time_measurement_ADC;
Fo170 17:7539e7bdfee9 111
Fo170 13:939e0fa0cd39 112 void measurement_ADC()
Fo170 13:939e0fa0cd39 113 {
Fo170 6:2ce163810c2f 114
Fo170 17:7539e7bdfee9 115 meas = 3300.0 * a_in.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
Fo170 13:939e0fa0cd39 116 //wait_us(10);
Fo170 13:939e0fa0cd39 117 meas_sum += meas;
Fo170 13:939e0fa0cd39 118 if(meas_min > meas) meas_min = meas;
Fo170 13:939e0fa0cd39 119 if(meas_max < meas) meas_max = meas;
Fo170 17:7539e7bdfee9 120
Fo170 17:7539e7bdfee9 121 vac = meas - 1650.0; // 0V AC = 3,3V/2
Fo170 17:7539e7bdfee9 122 pow2_vac = vac * vac; // valeur VAC au carré
Fo170 17:7539e7bdfee9 123 sum_pow2_vac += pow2_vac; // somme des valeurs AC au carré
Fo170 17:7539e7bdfee9 124
Fo170 13:939e0fa0cd39 125 Samples++;
Fo170 17:7539e7bdfee9 126
Fo170 17:7539e7bdfee9 127 if( Samples == NB_SAMPLES ) {
Fo170 17:7539e7bdfee9 128 // VDC
Fo170 17:7539e7bdfee9 129 meas_moy = meas_sum;
Fo170 17:7539e7bdfee9 130 meas_moy /= (float)NB_SAMPLES;
Fo170 17:7539e7bdfee9 131 // VAC
Fo170 17:7539e7bdfee9 132 veff = sum_pow2_vac;
Fo170 17:7539e7bdfee9 133 veff /= (float)NB_SAMPLES;
Fo170 17:7539e7bdfee9 134 veff = sqrt(veff);
Fo170 17:7539e7bdfee9 135
Fo170 17:7539e7bdfee9 136 Samples = 0;
Fo170 17:7539e7bdfee9 137 meas_sum = 0.0;
Fo170 17:7539e7bdfee9 138 vdc_min = meas_min, vdc_max = meas_max;
Fo170 17:7539e7bdfee9 139 meas_min = 3300.0 , meas_max = 0.0;
Fo170 17:7539e7bdfee9 140 sum_pow2_vac = 0.0;
Fo170 13:939e0fa0cd39 141 }
Fo170 13:939e0fa0cd39 142 }
Fo170 17:7539e7bdfee9 143
Fo170 11:afb33350db83 144 //------------
Fo170 13:939e0fa0cd39 145 #define __Time_between_refresh_in_Second__ 0.1
Fo170 13:939e0fa0cd39 146
Fo170 7:acad90a34466 147 Ticker second_ticker;
Fo170 7:acad90a34466 148
Fo170 7:acad90a34466 149 void add_one_second()
Fo170 17:7539e7bdfee9 150 {
Fo170 17:7539e7bdfee9 151 Seconds = Seconds + (float)__Time_between_refresh_in_Second__;
Fo170 7:acad90a34466 152 }
Fo170 11:afb33350db83 153 //------------
Fo170 18:7254aeaa41a8 154 //const uint16_t MY_PORT = 80; // for HTTP connection
Fo170 18:7254aeaa41a8 155 //EthernetServer myServer = EthernetServer(MY_PORT);
hudakz 0:68a0003c4cb8 156
Fo170 18:7254aeaa41a8 157 /*
hudakz 0:68a0003c4cb8 158 const string HTTP_OK = "HTTP/1.0 200 OK";
hudakz 0:68a0003c4cb8 159 const string MOVED_PERM = "HTTP/1.0 301 Moved Permanently\r\nLocation: ";
hudakz 0:68a0003c4cb8 160 const string UNAUTHORIZED = "HTTP/1.0 401 Unauthorized";
Fo170 18:7254aeaa41a8 161 */
Fo170 18:7254aeaa41a8 162 //string httpHeader; // HTTP header
Fo170 18:7254aeaa41a8 163 //string httpContent; // HTTP content
hudakz 0:68a0003c4cb8 164
hudakz 0:68a0003c4cb8 165
hudakz 0:68a0003c4cb8 166 // analyse the url given
hudakz 0:68a0003c4cb8 167 // return values: -1 invalid password
hudakz 0:68a0003c4cb8 168 // -2 no command given but password valid
hudakz 0:68a0003c4cb8 169 // -3 just refresh page
hudakz 0:68a0003c4cb8 170 // 0 switch off
hudakz 0:68a0003c4cb8 171 // 1 switch on
hudakz 0:68a0003c4cb8 172 //
hudakz 0:68a0003c4cb8 173 // The string passed to this function will look like this:
hudakz 0:68a0003c4cb8 174 // GET /password HTTP/1.....
hudakz 0:68a0003c4cb8 175 // GET /password/ HTTP/1.....
hudakz 0:68a0003c4cb8 176 // GET /password/?sw=1 HTTP/1.....
hudakz 0:68a0003c4cb8 177 // GET /password/?sw=0 HTTP/1.....
Fo170 18:7254aeaa41a8 178 /*
hudakz 0:68a0003c4cb8 179 int8_t analyse_get_url(string& str)
hudakz 0:68a0003c4cb8 180 {
hudakz 0:68a0003c4cb8 181 if(str.substr(5, PASSWORD.size()) != PASSWORD)
hudakz 0:68a0003c4cb8 182 return(-1);
hudakz 0:68a0003c4cb8 183
hudakz 0:68a0003c4cb8 184 uint8_t pos = 5 + PASSWORD.size();
hudakz 0:68a0003c4cb8 185
Fo170 7:acad90a34466 186 if(str.substr(pos, 1) == " ") return(-2);
hudakz 0:68a0003c4cb8 187
Fo170 7:acad90a34466 188 if(str.substr(pos, 1) != "/") return(-1);
hudakz 0:68a0003c4cb8 189
hudakz 0:68a0003c4cb8 190 pos++;
hudakz 0:68a0003c4cb8 191
hudakz 0:68a0003c4cb8 192 string cmd(str.substr(pos, 5));
hudakz 0:68a0003c4cb8 193
Fo170 7:acad90a34466 194 if(cmd == "?sw=0") return(0);
hudakz 0:68a0003c4cb8 195
Fo170 7:acad90a34466 196 if(cmd == "?sw=1") return(1);
hudakz 0:68a0003c4cb8 197
hudakz 0:68a0003c4cb8 198 return(-3);
hudakz 0:68a0003c4cb8 199 }
Fo170 18:7254aeaa41a8 200 */
Fo170 18:7254aeaa41a8 201 /*
hudakz 0:68a0003c4cb8 202 string& moved_perm(uint8_t flag)
hudakz 0:68a0003c4cb8 203 {
hudakz 0:68a0003c4cb8 204 if(flag == 1)
hudakz 0:68a0003c4cb8 205 httpContent = "/" + PASSWORD + "/";
hudakz 0:68a0003c4cb8 206 else
hudakz 0:68a0003c4cb8 207 httpContent = "";
Fo170 18:7254aeaa41a8 208
Fo170 13:939e0fa0cd39 209 httpContent += str_moved_perm;
Fo170 17:7539e7bdfee9 210
hudakz 0:68a0003c4cb8 211 return (httpContent);
hudakz 0:68a0003c4cb8 212 }
Fo170 18:7254aeaa41a8 213 */
hudakz 0:68a0003c4cb8 214 string& page(uint8_t status)
hudakz 0:68a0003c4cb8 215 {
Fo170 11:afb33350db83 216 char buffer[128];
Fo170 8:305b64d7dd23 217 //char time_stamp[32];
Fo170 17:7539e7bdfee9 218
Fo170 5:a46a2512e17e 219 //-------------
Fo170 18:7254aeaa41a8 220 httpContent = str_DOCTYPE;
Fo170 18:7254aeaa41a8 221 httpContent += str_meta_refresh;
Fo170 18:7254aeaa41a8 222 httpContent += "\r\n<HTML><HEAD>\r\n";
Fo170 13:939e0fa0cd39 223 httpContent += "<title>WEB Server Nucleo F411RE & ENC28J60 - ADC</title>\r\n";
Fo170 18:7254aeaa41a8 224 httpContent += str_favicon;
Fo170 18:7254aeaa41a8 225 httpContent += str_JavaScript;
Fo170 6:2ce163810c2f 226 httpContent += "</HEAD><BODY>\r\n";
Fo170 16:5a3d10a54762 227 httpContent += "<center><h2>WEB Server Nucleo F411RE (ADC)</h2>\r\n";
Fo170 13:939e0fa0cd39 228 httpContent += "<p>Designed for STM32F411RE & ENC28J60 (ADC)\r\n";
Fo170 18:7254aeaa41a8 229 httpContent += str_Compilation_DATE_AND_TIME;
Fo170 18:7254aeaa41a8 230 // httpContent += str_Logo_image ;
Fo170 17:7539e7bdfee9 231
Fo170 8:305b64d7dd23 232 httpContent += "<p></center>\r\n<hr><p>\r\n";
Fo170 17:7539e7bdfee9 233
Fo170 7:acad90a34466 234 /*
Fo170 7:acad90a34466 235 httpContent += "Local Time: ";
Fo170 6:2ce163810c2f 236 time_t seconds = time(NULL)+ 19800; // time(null) gives the GMT time .
Fo170 6:2ce163810c2f 237 // printf("Time as seconds since January 1, 1970 = %d\n", seconds);
Fo170 17:7539e7bdfee9 238 strftime(time_stamp, 32, "%y %m %d, %H:%M:%Ss", localtime(&seconds));
Fo170 17:7539e7bdfee9 239 // this converts the value in seconds obtained above to human readable format and assigns it to the timestamp
Fo170 6:2ce163810c2f 240 sprintf(buffer, "%s", time_stamp);// diplays the human readable time
Fo170 7:acad90a34466 241 */
Fo170 8:305b64d7dd23 242 sprintf(buffer, "%.1f ", Seconds);// diplays the human readable Seconds
Fo170 6:2ce163810c2f 243 httpContent += buffer;
Fo170 7:acad90a34466 244 httpContent += "Seconds\r\n<hr>\r\n";
Fo170 6:2ce163810c2f 245 //----------------
Fo170 17:7539e7bdfee9 246
Fo170 17:7539e7bdfee9 247 httpContent += "AnalogIn(PC_5) :<p>\r\n";
Fo170 17:7539e7bdfee9 248 sprintf(buffer, "%.0f mV Moy ( sum : %.0f - Samples : %u )\r\n", meas_moy, meas_sum, Samples);
Fo170 17:7539e7bdfee9 249 httpContent += buffer;
Fo170 17:7539e7bdfee9 250 httpContent += "<p>\r\n";
Fo170 17:7539e7bdfee9 251 sprintf(buffer, "DC (0 &agrave; 3,3V) : %.0f mV Min, %.0f mV Max , diff : %.0f mV\r\n", vdc_min, vdc_max, vdc_max - vdc_min);
Fo170 17:7539e7bdfee9 252 httpContent += buffer;
Fo170 17:7539e7bdfee9 253 httpContent += "<p>\r\n";
Fo170 17:7539e7bdfee9 254 sprintf(buffer, "AC (-1,65V &agrave; 1,65V) : %.0f mV eff\r\n", veff);
Fo170 17:7539e7bdfee9 255 httpContent += buffer;
Fo170 6:2ce163810c2f 256 httpContent += "</BODY></HTML>";
Fo170 6:2ce163810c2f 257 //-----------
Fo170 7:acad90a34466 258 //wait(1);
Fo170 6:2ce163810c2f 259 return httpContent;
Fo170 6:2ce163810c2f 260 }
Fo170 6:2ce163810c2f 261
Fo170 18:7254aeaa41a8 262 /*
hudakz 0:68a0003c4cb8 263 void http_send(EthernetClient& client, string& header, string& content)
hudakz 0:68a0003c4cb8 264 {
hudakz 0:68a0003c4cb8 265 char content_length[5] = {};
hudakz 0:68a0003c4cb8 266
hudakz 2:76f339a1ba9b 267 header += "\r\nContent-Type: text/html\r\n";
hudakz 0:68a0003c4cb8 268 header += "Content-Length: ";
hudakz 0:68a0003c4cb8 269 sprintf(content_length, "%d", content.length());
hudakz 0:68a0003c4cb8 270 header += string(content_length) + "\r\n";
hudakz 0:68a0003c4cb8 271 header += "Pragma: no-cache\r\n";
hudakz 0:68a0003c4cb8 272 header += "Connection: About to close\r\n";
hudakz 0:68a0003c4cb8 273 header += "\r\n";
hudakz 0:68a0003c4cb8 274 string webpage = header + content;
hudakz 0:68a0003c4cb8 275 client.write((uint8_t*)webpage.c_str(),webpage.length());
hudakz 0:68a0003c4cb8 276 }
Fo170 18:7254aeaa41a8 277 */
hudakz 0:68a0003c4cb8 278 int main()
Fo170 7:acad90a34466 279 {
Fo170 17:7539e7bdfee9 280 meas_moy = 0.0;
Fo170 17:7539e7bdfee9 281 Samples = 0;
Fo170 17:7539e7bdfee9 282 meas_sum = 0.0;
Fo170 17:7539e7bdfee9 283 meas_min = 3300.0 , meas_max = 0.0;
Fo170 17:7539e7bdfee9 284 sum_pow2_vac = 0.0;
Fo170 17:7539e7bdfee9 285
Fo170 17:7539e7bdfee9 286 // RTC
Fo170 17:7539e7bdfee9 287 //set_time(1387188323); // Set RTC time to 16 December 2013 10:05:23 UTC
Fo170 17:7539e7bdfee9 288
Fo170 17:7539e7bdfee9 289 // Date and time are set.
Fo170 17:7539e7bdfee9 290
Fo170 17:7539e7bdfee9 291 // Init the ticker with the address of the function (add_one_second) to be attached and the interval (1000 ms)
Fo170 17:7539e7bdfee9 292 second_ticker.attach(&add_one_second, __Time_between_refresh_in_Second__);
Fo170 17:7539e7bdfee9 293
Fo170 17:7539e7bdfee9 294 //-----------------
Fo170 17:7539e7bdfee9 295 // 50 Hz --> 20ms
Fo170 17:7539e7bdfee9 296 // 100 samples par oscillations = 20 / 100 = 0.2ms = 200µs
Fo170 17:7539e7bdfee9 297 // 100 samples * 50 oscillations = 5000 samples au total par secondes
Fo170 17:7539e7bdfee9 298 // interval: 200 micro seconds chaques samples
Fo170 17:7539e7bdfee9 299 time_measurement_ADC.attach_us(&measurement_ADC, TIME_SAMPLES_us);
Fo170 17:7539e7bdfee9 300
Fo170 18:7254aeaa41a8 301 //-----------------
Fo170 18:7254aeaa41a8 302 HTTP_LOOP();
Fo170 18:7254aeaa41a8 303 /*
hudakz 3:0133517ba02d 304 UIPEthernet.begin(MY_MAC,MY_IP);
hudakz 0:68a0003c4cb8 305 myServer.begin();
Fo170 17:7539e7bdfee9 306 while(1) {
hudakz 0:68a0003c4cb8 307 EthernetClient client = myServer.available();
Fo170 17:7539e7bdfee9 308 if(client) {
hudakz 0:68a0003c4cb8 309 size_t size = client.available();
Fo170 17:7539e7bdfee9 310 if(size > 0) {
hudakz 0:68a0003c4cb8 311 uint8_t* buf = (uint8_t*)malloc(size);
hudakz 0:68a0003c4cb8 312 size = client.read(buf, size);
hudakz 0:68a0003c4cb8 313 string received((char*)buf);
hudakz 0:68a0003c4cb8 314 free(buf);
Fo170 17:7539e7bdfee9 315 if(received.substr(0, 3) != "GET") {
hudakz 0:68a0003c4cb8 316 // head, post or other method
hudakz 0:68a0003c4cb8 317 // for possible status codes see:
hudakz 0:68a0003c4cb8 318 // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
hudakz 0:68a0003c4cb8 319 httpHeader = HTTP_OK;
hudakz 0:68a0003c4cb8 320 httpContent = "<h1>200 OK</h1>";
hudakz 0:68a0003c4cb8 321 http_send(client, httpHeader, httpContent);
hudakz 0:68a0003c4cb8 322 continue;
hudakz 0:68a0003c4cb8 323 }
hudakz 0:68a0003c4cb8 324
Fo170 17:7539e7bdfee9 325 if(received.substr(0, 6) == "GET / ") {
hudakz 0:68a0003c4cb8 326 httpHeader = HTTP_OK;
Fo170 18:7254aeaa41a8 327
Fo170 6:2ce163810c2f 328 http_send(client, httpHeader, page(sw));
hudakz 0:68a0003c4cb8 329 continue;
hudakz 0:68a0003c4cb8 330 }
hudakz 0:68a0003c4cb8 331
hudakz 0:68a0003c4cb8 332 int cmd = analyse_get_url(received);
hudakz 0:68a0003c4cb8 333
Fo170 17:7539e7bdfee9 334 if(cmd == -2) {
hudakz 0:68a0003c4cb8 335 // redirect to the right base url
hudakz 0:68a0003c4cb8 336 httpHeader = MOVED_PERM;
hudakz 0:68a0003c4cb8 337 http_send(client, httpHeader, moved_perm(1));
hudakz 0:68a0003c4cb8 338 continue;
hudakz 0:68a0003c4cb8 339 }
hudakz 0:68a0003c4cb8 340
Fo170 17:7539e7bdfee9 341 if(cmd == -1) {
hudakz 0:68a0003c4cb8 342 httpHeader = UNAUTHORIZED;
Fo170 18:7254aeaa41a8 343
Fo170 13:939e0fa0cd39 344 httpContent = str_Unauthorized;
hudakz 0:68a0003c4cb8 345 http_send(client, httpHeader, httpContent);
hudakz 0:68a0003c4cb8 346 continue;
hudakz 0:68a0003c4cb8 347 }
hudakz 0:68a0003c4cb8 348 }
hudakz 0:68a0003c4cb8 349 }
hudakz 0:68a0003c4cb8 350 }
Fo170 18:7254aeaa41a8 351 */
hudakz 0:68a0003c4cb8 352 }
hudakz 0:68a0003c4cb8 353
hudakz 3:0133517ba02d 354