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:
Wed Aug 05 19:56:31 2015 +0000
Revision:
15:4b3975520691
Parent:
13:939e0fa0cd39
Child:
16:5a3d10a54762
les mesures ADC semble aleatoire et imprecise, entre les minima et les maxima il y as des ecarts entre 50 et 460mV pour une source de 2,5V stable (2 accumulateur Ni-Cd)

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 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 13:939e0fa0cd39 83 float meas, meas_sum, meas_moy, meas_min, meas_max, v_min, v_max;
Fo170 8:305b64d7dd23 84
Fo170 13:939e0fa0cd39 85 Ticker time_measurement_ADC;
Fo170 13:939e0fa0cd39 86
Fo170 13:939e0fa0cd39 87 void measurement_ADC()
Fo170 13:939e0fa0cd39 88 {
Fo170 6:2ce163810c2f 89
Fo170 13:939e0fa0cd39 90 meas = a_in.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
Fo170 13:939e0fa0cd39 91 //wait_us(10);
Fo170 13:939e0fa0cd39 92 meas_sum += meas;
Fo170 13:939e0fa0cd39 93 if(meas_min > meas) meas_min = meas;
Fo170 13:939e0fa0cd39 94 if(meas_max < meas) meas_max = meas;
Fo170 13:939e0fa0cd39 95 Samples++;
Fo170 13:939e0fa0cd39 96
Fo170 13:939e0fa0cd39 97 if( Samples == NB_SAMPLES )
Fo170 13:939e0fa0cd39 98 {
Fo170 13:939e0fa0cd39 99 meas_moy = meas_sum * 3300.0; // Change the value to be in the 0 to 3300 range
Fo170 13:939e0fa0cd39 100 meas_moy /= (float)NB_SAMPLES;
Fo170 13:939e0fa0cd39 101 Samples = 0;
Fo170 13:939e0fa0cd39 102 meas_sum = 0.0;
Fo170 13:939e0fa0cd39 103 v_min = 3300.0 * meas_min, v_max = 3300.0 * meas_max;
Fo170 13:939e0fa0cd39 104 meas_min = 1.0 , meas_max = 0.0;
Fo170 13:939e0fa0cd39 105 }
Fo170 13:939e0fa0cd39 106 }
Fo170 13:939e0fa0cd39 107
Fo170 11:afb33350db83 108 //------------
Fo170 13:939e0fa0cd39 109 #define __Time_between_refresh_in_Second__ 0.1
Fo170 13:939e0fa0cd39 110
Fo170 7:acad90a34466 111 Ticker second_ticker;
Fo170 7:acad90a34466 112
Fo170 7:acad90a34466 113 void add_one_second()
Fo170 11:afb33350db83 114 {
Fo170 13:939e0fa0cd39 115 Seconds = Seconds + (float)__Time_between_refresh_in_Second__;
Fo170 7:acad90a34466 116 }
Fo170 11:afb33350db83 117 //------------
hudakz 0:68a0003c4cb8 118 const uint16_t MY_PORT = 80; // for HTTP connection
hudakz 0:68a0003c4cb8 119 EthernetServer myServer = EthernetServer(MY_PORT);
hudakz 0:68a0003c4cb8 120 // In this example we are turning on/off LED1.
hudakz 4:d34811deedab 121 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 122
hudakz 0:68a0003c4cb8 123 const string PASSWORD = "secret"; // change as you like
hudakz 0:68a0003c4cb8 124 const string HTTP_OK = "HTTP/1.0 200 OK";
hudakz 0:68a0003c4cb8 125 const string MOVED_PERM = "HTTP/1.0 301 Moved Permanently\r\nLocation: ";
hudakz 0:68a0003c4cb8 126 const string UNAUTHORIZED = "HTTP/1.0 401 Unauthorized";
hudakz 0:68a0003c4cb8 127 string httpHeader; // HTTP header
hudakz 0:68a0003c4cb8 128 string httpContent; // HTTP content
hudakz 0:68a0003c4cb8 129
hudakz 0:68a0003c4cb8 130
hudakz 0:68a0003c4cb8 131 // analyse the url given
hudakz 0:68a0003c4cb8 132 // return values: -1 invalid password
hudakz 0:68a0003c4cb8 133 // -2 no command given but password valid
hudakz 0:68a0003c4cb8 134 // -3 just refresh page
hudakz 0:68a0003c4cb8 135 // 0 switch off
hudakz 0:68a0003c4cb8 136 // 1 switch on
hudakz 0:68a0003c4cb8 137 //
hudakz 0:68a0003c4cb8 138 // The string passed to this function will look like this:
hudakz 0:68a0003c4cb8 139 // GET /password HTTP/1.....
hudakz 0:68a0003c4cb8 140 // GET /password/ HTTP/1.....
hudakz 0:68a0003c4cb8 141 // GET /password/?sw=1 HTTP/1.....
hudakz 0:68a0003c4cb8 142 // GET /password/?sw=0 HTTP/1.....
hudakz 0:68a0003c4cb8 143
hudakz 0:68a0003c4cb8 144 int8_t analyse_get_url(string& str)
hudakz 0:68a0003c4cb8 145 {
hudakz 0:68a0003c4cb8 146 if(str.substr(5, PASSWORD.size()) != PASSWORD)
hudakz 0:68a0003c4cb8 147 return(-1);
hudakz 0:68a0003c4cb8 148
hudakz 0:68a0003c4cb8 149 uint8_t pos = 5 + PASSWORD.size();
hudakz 0:68a0003c4cb8 150
Fo170 7:acad90a34466 151 if(str.substr(pos, 1) == " ") return(-2);
hudakz 0:68a0003c4cb8 152
Fo170 7:acad90a34466 153 if(str.substr(pos, 1) != "/") return(-1);
hudakz 0:68a0003c4cb8 154
hudakz 0:68a0003c4cb8 155 pos++;
hudakz 0:68a0003c4cb8 156
hudakz 0:68a0003c4cb8 157 string cmd(str.substr(pos, 5));
hudakz 0:68a0003c4cb8 158
Fo170 7:acad90a34466 159 if(cmd == "?sw=0") return(0);
hudakz 0:68a0003c4cb8 160
Fo170 7:acad90a34466 161 if(cmd == "?sw=1") return(1);
hudakz 0:68a0003c4cb8 162
hudakz 0:68a0003c4cb8 163 return(-3);
hudakz 0:68a0003c4cb8 164 }
hudakz 0:68a0003c4cb8 165
hudakz 0:68a0003c4cb8 166 string& moved_perm(uint8_t flag)
hudakz 0:68a0003c4cb8 167 {
hudakz 0:68a0003c4cb8 168 if(flag == 1)
hudakz 0:68a0003c4cb8 169 httpContent = "/" + PASSWORD + "/";
hudakz 0:68a0003c4cb8 170 else
hudakz 0:68a0003c4cb8 171 httpContent = "";
Fo170 13:939e0fa0cd39 172 /*
Fo170 6:2ce163810c2f 173 httpContent += "<h1>301 Moved Permanently ";
Fo170 9:2f7ad2b13ec8 174 httpContent += __image_301_Moved_Permanently__;
Fo170 9:2f7ad2b13ec8 175 httpContent += "</h1>\r\n";
Fo170 13:939e0fa0cd39 176 */
Fo170 13:939e0fa0cd39 177 httpContent += str_moved_perm;
Fo170 13:939e0fa0cd39 178
hudakz 0:68a0003c4cb8 179 return (httpContent);
hudakz 0:68a0003c4cb8 180 }
hudakz 0:68a0003c4cb8 181
hudakz 0:68a0003c4cb8 182 string& page(uint8_t status)
hudakz 0:68a0003c4cb8 183 {
Fo170 11:afb33350db83 184 char buffer[128];
Fo170 8:305b64d7dd23 185 //char time_stamp[32];
Fo170 13:939e0fa0cd39 186
Fo170 5:a46a2512e17e 187 //-------------
Fo170 6:2ce163810c2f 188 httpContent = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\r\n";
Fo170 9:2f7ad2b13ec8 189 httpContent += "<meta http-equiv=\"refresh\" content=\"";
Fo170 13:939e0fa0cd39 190 httpContent += __Time_between_page_refresh__;
Fo170 9:2f7ad2b13ec8 191 httpContent += ";url=http://";
Fo170 9:2f7ad2b13ec8 192 httpContent += __IP_LOCAL__;
Fo170 9:2f7ad2b13ec8 193 httpContent += "/\">\r\n";
Fo170 6:2ce163810c2f 194 httpContent += "<HTML><HEAD>\r\n";
Fo170 13:939e0fa0cd39 195 httpContent += "<title>WEB Server Nucleo F411RE & ENC28J60 - ADC</title>\r\n";
Fo170 13:939e0fa0cd39 196
Fo170 13:939e0fa0cd39 197
Fo170 13:939e0fa0cd39 198
Fo170 6:2ce163810c2f 199 httpContent += "</HEAD><BODY>\r\n";
Fo170 6:2ce163810c2f 200 httpContent += "<center><h2>WEB Server Nucleo F411RE</h2>\r\n";
Fo170 13:939e0fa0cd39 201 httpContent += "<p>Designed for STM32F411RE & ENC28J60 (ADC)\r\n";
Fo170 10:bbee7dd4bcda 202 httpContent += "<p>Compilation avec mBED &agrave; " __TIME__ " le " __DATE__" \r\n";
Fo170 8:305b64d7dd23 203
Fo170 8:305b64d7dd23 204 httpContent += "<p></center>\r\n<hr><p>\r\n";
Fo170 5:a46a2512e17e 205
Fo170 7:acad90a34466 206 /*
Fo170 7:acad90a34466 207 httpContent += "Local Time: ";
Fo170 6:2ce163810c2f 208 time_t seconds = time(NULL)+ 19800; // time(null) gives the GMT time .
Fo170 6:2ce163810c2f 209 // printf("Time as seconds since January 1, 1970 = %d\n", seconds);
Fo170 7:acad90a34466 210 strftime(time_stamp, 32, "%y %m %d, %H:%M:%Ss", localtime(&seconds));
Fo170 6:2ce163810c2f 211 // this converts the value in seconds obtained above to human readable format and assigns it to the timestamp
Fo170 6:2ce163810c2f 212 sprintf(buffer, "%s", time_stamp);// diplays the human readable time
Fo170 7:acad90a34466 213 */
Fo170 8:305b64d7dd23 214 sprintf(buffer, "%.1f ", Seconds);// diplays the human readable Seconds
Fo170 6:2ce163810c2f 215 httpContent += buffer;
Fo170 7:acad90a34466 216 httpContent += "Seconds\r\n<hr>\r\n";
Fo170 6:2ce163810c2f 217 //----------------
Fo170 13:939e0fa0cd39 218
Fo170 13:939e0fa0cd39 219 httpContent += "AnalogIn(PC_5) : (DC de 0 a 3,3V)<p>\r\n";
Fo170 13:939e0fa0cd39 220 sprintf(buffer, "%.0f mV Moy ( sum : %.0f - Samples : %u )\r\n", meas_moy, meas_sum, Samples);
Fo170 13:939e0fa0cd39 221 httpContent += buffer;
Fo170 13:939e0fa0cd39 222 httpContent += "<p>\r\n";
Fo170 15:4b3975520691 223 sprintf(buffer, "%.0f mV Min, %.0f mV Max , diff : %.0f mV\r\n", v_min, v_max, v_max - v_min);
Fo170 13:939e0fa0cd39 224 httpContent += buffer;
Fo170 6:2ce163810c2f 225 httpContent += "</BODY></HTML>";
Fo170 6:2ce163810c2f 226 //-----------
Fo170 7:acad90a34466 227 //wait(1);
Fo170 6:2ce163810c2f 228 return httpContent;
Fo170 6:2ce163810c2f 229 }
Fo170 6:2ce163810c2f 230
hudakz 0:68a0003c4cb8 231 void http_send(EthernetClient& client, string& header, string& content)
hudakz 0:68a0003c4cb8 232 {
hudakz 0:68a0003c4cb8 233 char content_length[5] = {};
hudakz 0:68a0003c4cb8 234
hudakz 2:76f339a1ba9b 235 header += "\r\nContent-Type: text/html\r\n";
hudakz 0:68a0003c4cb8 236 header += "Content-Length: ";
hudakz 0:68a0003c4cb8 237 sprintf(content_length, "%d", content.length());
hudakz 0:68a0003c4cb8 238 header += string(content_length) + "\r\n";
hudakz 0:68a0003c4cb8 239 header += "Pragma: no-cache\r\n";
hudakz 0:68a0003c4cb8 240 header += "Connection: About to close\r\n";
hudakz 0:68a0003c4cb8 241 header += "\r\n";
hudakz 0:68a0003c4cb8 242 string webpage = header + content;
hudakz 0:68a0003c4cb8 243 client.write((uint8_t*)webpage.c_str(),webpage.length());
hudakz 0:68a0003c4cb8 244 }
hudakz 0:68a0003c4cb8 245
hudakz 0:68a0003c4cb8 246 int main()
Fo170 7:acad90a34466 247 {
Fo170 13:939e0fa0cd39 248 meas_moy = 0.0;
Fo170 13:939e0fa0cd39 249 Samples = 0;
Fo170 13:939e0fa0cd39 250 meas_sum = 0.0;
Fo170 13:939e0fa0cd39 251 meas_min = 1.0 , meas_max = 0.0;
Fo170 5:a46a2512e17e 252 // RTC
Fo170 8:305b64d7dd23 253 //set_time(1387188323); // Set RTC time to 16 December 2013 10:05:23 UTC
Fo170 7:acad90a34466 254
Fo170 5:a46a2512e17e 255 // Date and time are set.
Fo170 7:acad90a34466 256
Fo170 13:939e0fa0cd39 257 // Init the ticker with the address of the function (add_one_second) to be attached and the interval (1000 ms)
Fo170 13:939e0fa0cd39 258 second_ticker.attach(&add_one_second, __Time_between_refresh_in_Second__);
Fo170 13:939e0fa0cd39 259
Fo170 13:939e0fa0cd39 260 //-----------------
Fo170 13:939e0fa0cd39 261 // 50 Hz --> 20ms
Fo170 13:939e0fa0cd39 262 // 100 samples par oscillations = 20 / 100 = 0.2ms = 200µs
Fo170 13:939e0fa0cd39 263 // 100 samples * 50 oscillations = 5000 samples au total par secondes
Fo170 13:939e0fa0cd39 264 // interval: 200 micro seconds chaques samples
Fo170 13:939e0fa0cd39 265 time_measurement_ADC.attach_us(&measurement_ADC, TIME_SAMPLES_us);
Fo170 13:939e0fa0cd39 266
Fo170 7:acad90a34466 267 //-----------------
hudakz 3:0133517ba02d 268 UIPEthernet.begin(MY_MAC,MY_IP);
hudakz 0:68a0003c4cb8 269 myServer.begin();
Fo170 7:acad90a34466 270 while(1)
Fo170 7:acad90a34466 271 {
hudakz 0:68a0003c4cb8 272 EthernetClient client = myServer.available();
Fo170 7:acad90a34466 273 if(client)
Fo170 7:acad90a34466 274 {
hudakz 0:68a0003c4cb8 275 size_t size = client.available();
Fo170 7:acad90a34466 276 if(size > 0)
Fo170 7:acad90a34466 277 {
hudakz 0:68a0003c4cb8 278 uint8_t* buf = (uint8_t*)malloc(size);
hudakz 0:68a0003c4cb8 279 size = client.read(buf, size);
hudakz 0:68a0003c4cb8 280 string received((char*)buf);
hudakz 0:68a0003c4cb8 281 free(buf);
Fo170 7:acad90a34466 282 if(received.substr(0, 3) != "GET")
Fo170 7:acad90a34466 283 {
hudakz 0:68a0003c4cb8 284 // head, post or other method
hudakz 0:68a0003c4cb8 285 // for possible status codes see:
hudakz 0:68a0003c4cb8 286 // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
hudakz 0:68a0003c4cb8 287 httpHeader = HTTP_OK;
hudakz 0:68a0003c4cb8 288 httpContent = "<h1>200 OK</h1>";
hudakz 0:68a0003c4cb8 289 http_send(client, httpHeader, httpContent);
hudakz 0:68a0003c4cb8 290 continue;
hudakz 0:68a0003c4cb8 291 }
hudakz 0:68a0003c4cb8 292
Fo170 7:acad90a34466 293 if(received.substr(0, 6) == "GET / ")
Fo170 7:acad90a34466 294 {
hudakz 0:68a0003c4cb8 295 httpHeader = HTTP_OK;
Fo170 6:2ce163810c2f 296 /*
hudakz 0:68a0003c4cb8 297 httpContent = "<p>Usage: http://host_or_ip/password</p>\r\n";
hudakz 0:68a0003c4cb8 298 http_send(client, httpHeader, httpContent);
Fo170 6:2ce163810c2f 299 */
Fo170 6:2ce163810c2f 300 http_send(client, httpHeader, page(sw));
hudakz 0:68a0003c4cb8 301 continue;
hudakz 0:68a0003c4cb8 302 }
hudakz 0:68a0003c4cb8 303
hudakz 0:68a0003c4cb8 304 int cmd = analyse_get_url(received);
hudakz 0:68a0003c4cb8 305
Fo170 7:acad90a34466 306 if(cmd == -2)
Fo170 7:acad90a34466 307 {
hudakz 0:68a0003c4cb8 308 // redirect to the right base url
hudakz 0:68a0003c4cb8 309 httpHeader = MOVED_PERM;
hudakz 0:68a0003c4cb8 310 http_send(client, httpHeader, moved_perm(1));
hudakz 0:68a0003c4cb8 311 continue;
hudakz 0:68a0003c4cb8 312 }
hudakz 0:68a0003c4cb8 313
Fo170 7:acad90a34466 314 if(cmd == -1)
Fo170 7:acad90a34466 315 {
hudakz 0:68a0003c4cb8 316 httpHeader = UNAUTHORIZED;
Fo170 13:939e0fa0cd39 317 /*
Fo170 9:2f7ad2b13ec8 318 httpContent = "<h1>401 Unauthorized ";
Fo170 9:2f7ad2b13ec8 319 httpContent += __image_401_Unauthorized__;
Fo170 9:2f7ad2b13ec8 320 httpContent += "</h1>\r\n";
Fo170 13:939e0fa0cd39 321 */
Fo170 13:939e0fa0cd39 322 httpContent = str_Unauthorized;
hudakz 0:68a0003c4cb8 323 http_send(client, httpHeader, httpContent);
hudakz 0:68a0003c4cb8 324 continue;
hudakz 0:68a0003c4cb8 325 }
hudakz 0:68a0003c4cb8 326 }
hudakz 0:68a0003c4cb8 327 }
hudakz 0:68a0003c4cb8 328 }
hudakz 0:68a0003c4cb8 329 }
hudakz 0:68a0003c4cb8 330
hudakz 3:0133517ba02d 331