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:
Thu Aug 06 13:55:44 2015 +0000
Revision:
17:7539e7bdfee9
Parent:
16:5a3d10a54762
Child:
18:7254aeaa41a8
adding measures effectively values (center on 1.65V)

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